Tool Context
ToolContextdataclass
Bases:RunContextWrapper[TContext]
The context of a tool call.
Source code insrc/agents/tool_context.py
tool_nameclass-attributeinstance-attribute
The name of the tool being invoked.
tool_argumentsclass-attributeinstance-attribute
tool_arguments:str=(_assert_must_pass_tool_arguments()iftool_argumentsis_MISSINGelsecast(str,tool_arguments))The raw arguments string of the tool call.
tool_call_idclass-attributeinstance-attribute
tool_call_id:str=(_assert_must_pass_tool_call_id()iftool_call_idis_MISSINGelsecast(str,tool_call_id))The ID of the tool call.
tool_callclass-attributeinstance-attribute
The tool call object associated with this invocation.
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.
__init__
__init__(context:TContext,usage:Usage|object=_MISSING,tool_name:str|object=_MISSING,tool_call_id:str|object=_MISSING,tool_arguments:str|object=_MISSING,tool_call:ResponseFunctionToolCall|None=None,*,turn_input:list[TResponseInputItem]|None=None,_approvals:dict[str,_ApprovalRecord]|None=None,tool_input:Any|None=None,)->NonePreserve the v0.7 positional constructor while accepting new context fields.
Source code insrc/agents/tool_context.py
from_agent_contextclassmethod
from_agent_context(context:RunContextWrapper[TContext],tool_call_id:str,tool_call:ResponseFunctionToolCall|None=None,)->ToolContextCreate a ToolContext from a RunContextWrapper.
Source code insrc/agents/tool_context.py
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.