Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Tool Context

ToolContextdataclass

Bases:RunContextWrapper[TContext]

The context of a tool call.

Source code insrc/agents/tool_context.py
@dataclassclassToolContext(RunContextWrapper[TContext]):"""The context of a tool call."""tool_name:str=field(default_factory=_assert_must_pass_tool_name)"""The name of the tool being invoked."""tool_call_id:str=field(default_factory=_assert_must_pass_tool_call_id)"""The ID of the tool call."""tool_arguments:str=field(default_factory=_assert_must_pass_tool_arguments)"""The raw arguments string of the tool call."""tool_call:Optional[ResponseFunctionToolCall]=None"""The tool call object associated with this invocation."""@classmethoddeffrom_agent_context(cls,context:RunContextWrapper[TContext],tool_call_id:str,tool_call:Optional[ResponseFunctionToolCall]=None,)->"ToolContext":"""        Create a ToolContext from a RunContextWrapper.        """# Grab the names of the RunContextWrapper's init=True fieldsbase_values:dict[str,Any]={f.name:getattr(context,f.name)forfinfields(RunContextWrapper)iff.init}tool_name=tool_call.nameiftool_callisnotNoneelse_assert_must_pass_tool_name()tool_args=(tool_call.argumentsiftool_callisnotNoneelse_assert_must_pass_tool_arguments())tool_context=cls(tool_name=tool_name,tool_call_id=tool_call_id,tool_arguments=tool_args,tool_call=tool_call,**base_values,)returntool_context

tool_nameclass-attributeinstance-attribute

tool_name:str=field(default_factory=_assert_must_pass_tool_name)

The name of the tool being invoked.

tool_call_idclass-attributeinstance-attribute

tool_call_id:str=field(default_factory=_assert_must_pass_tool_call_id)

The ID of the tool call.

tool_argumentsclass-attributeinstance-attribute

tool_arguments:str=field(default_factory=_assert_must_pass_tool_arguments)

The raw arguments string of the tool call.

tool_callclass-attributeinstance-attribute

tool_call:Optional[ResponseFunctionToolCall]=None

The tool call object associated with this invocation.

contextinstance-attribute

context:TContext

The context object (or None), passed by you toRunner.run()

usageclass-attributeinstance-attribute

usage:Usage=field(default_factory=Usage)

The usage of the agent run so far. For streamed responses, the usage will be stale until thelast chunk of the stream is processed.

from_agent_contextclassmethod

from_agent_context(context:RunContextWrapper[TContext],tool_call_id:str,tool_call:Optional[ResponseFunctionToolCall]=None,)->ToolContext

Create a ToolContext from a RunContextWrapper.

Source code insrc/agents/tool_context.py
@classmethoddeffrom_agent_context(cls,context:RunContextWrapper[TContext],tool_call_id:str,tool_call:Optional[ResponseFunctionToolCall]=None,)->"ToolContext":"""    Create a ToolContext from a RunContextWrapper.    """# Grab the names of the RunContextWrapper's init=True fieldsbase_values:dict[str,Any]={f.name:getattr(context,f.name)forfinfields(RunContextWrapper)iff.init}tool_name=tool_call.nameiftool_callisnotNoneelse_assert_must_pass_tool_name()tool_args=(tool_call.argumentsiftool_callisnotNoneelse_assert_must_pass_tool_arguments())tool_context=cls(tool_name=tool_name,tool_call_id=tool_call_id,tool_arguments=tool_args,tool_call=tool_call,**base_values,)returntool_context

[8]ページ先頭

©2009-2025 Movatter.jp