Run context
RunContextWrapperdataclass
Bases:Generic[TContext]
This wraps the context object that you passed toRunner.run(). It also containsinformation about the usage of the agent run so far.
NOTE: Contexts are not passed to the LLM. They're a way to pass dependencies and data to codeyou implement, like tool functions, callbacks, hooks, etc.
Source code insrc/agents/run_context.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 | |
usageclass-attributeinstance-attribute
The usage of the agent run so far. For streamed responses, the usage will be stale until thelast chunk of the stream is processed.
tool_inputclass-attributeinstance-attribute
Structured input for the current agent tool run, when available.
is_tool_approved
Return True/False/None for the given tool call.
Source code insrc/agents/run_context.py
approve_tool
approve_tool(approval_item:ToolApprovalItem,always_approve:bool=False,)->NoneApprove a tool call, optionally for all future calls.
reject_tool
reject_tool(approval_item:ToolApprovalItem,always_reject:bool=False,)->NoneReject a tool call, optionally for all future calls.
get_approval_status
get_approval_status(tool_name:str,call_id:str,*,existing_pending:ToolApprovalItem|None=None,)->bool|NoneReturn approval status, retrying with pending item's tool name if necessary.
Source code insrc/agents/run_context.py
AgentHookContextdataclass
Bases:RunContextWrapper[TContext]
Context passed to agent hooks (on_start, on_end).
Source code insrc/agents/run_context.py
usageclass-attributeinstance-attribute
The usage of the agent run so far. For streamed responses, the usage will be stale until thelast chunk of the stream is processed.
tool_inputclass-attributeinstance-attribute
Structured input for the current agent tool run, when available.
is_tool_approved
Return True/False/None for the given tool call.
Source code insrc/agents/run_context.py
approve_tool
approve_tool(approval_item:ToolApprovalItem,always_approve:bool=False,)->NoneApprove a tool call, optionally for all future calls.
reject_tool
reject_tool(approval_item:ToolApprovalItem,always_reject:bool=False,)->NoneReject a tool call, optionally for all future calls.
get_approval_status
get_approval_status(tool_name:str,call_id:str,*,existing_pending:ToolApprovalItem|None=None,)->bool|NoneReturn approval status, retrying with pending item's tool name if necessary.