RunContext

Per-run state passed to hooks and tools: IDs, session state, dependencies, and resolved tools.

The RunContext is an object that can be referenced in pre- and post-hooks, tools, and other parts of the run.

See Agent State for examples of how to use the RunContext in your code.

RunContext Attributes

AttributeTypeDescription
run_idstrRun ID
session_idstrSession ID for the run
user_idOptional[str]User ID associated with the run
workflow_idOptional[str]ID of the workflow this run belongs to, when executed inside a workflow
workflow_nameOptional[str]Name of the workflow this run belongs to, when executed inside a workflow
dependenciesOptional[Dict[str, Any]]Dependencies for the run
knowledge_filtersOptional[Union[Dict[str, Any], List[FilterExpr]]]Knowledge filters for the run
metadataOptional[Dict[str, Any]]Metadata associated with the run
session_stateOptional[Dict[str, Any]]Session state for the run
output_schemaOptional[Union[Type[BaseModel], Dict[str, Any]]]Output schema for the run, as a Pydantic model or JSON schema dict
messagesOptional[List[Message]]Live reference to the current run's message list. Hooks receive a shallow copy; individual Message objects are shared references
toolsOptional[List[Any]]Tools resolved for the run, including results of callable tool factories
knowledgeOptional[Any]Knowledge instance resolved for the run
membersOptional[List[Any]]Team members resolved for the run
client_toolsOptional[List[Any]]Per-run additive tools from the client (e.g. AG-UI frontend tools). Merged after agent.tools during tool resolution