- tool
- MCPToolApprovalFunction
- LocalShellExecutor
- ShellExecutor
- Tool
- ToolOutputText
- ToolOutputTextDict
- ToolOutputImage
- ToolOutputImageDict
- ToolOutputFileContent
- ToolOutputFileContentDict
- FunctionToolResult
- FunctionTool
- FileSearchTool
- WebSearchTool
- ComputerTool
- ComputerToolSafetyCheckData
- MCPToolApprovalRequest
- MCPToolApprovalFunctionResult
- HostedMCPTool
- CodeInterpreterTool
- ImageGenerationTool
- LocalShellCommandRequest
- LocalShellTool
- ShellCallOutcome
- ShellCommandOutput
- ShellResult
- ShellActionRequest
- ShellCallData
- ShellCommandRequest
- ShellTool
- ApplyPatchTool
- default_tool_error_function
- function_tool
Tools
MCPToolApprovalFunctionmodule-attribute
MCPToolApprovalFunction=Callable[[MCPToolApprovalRequest],MaybeAwaitable[MCPToolApprovalFunctionResult],]A function that approves or rejects a tool call.
LocalShellExecutormodule-attribute
LocalShellExecutor=Callable[[LocalShellCommandRequest],MaybeAwaitable[str]]A function that executes a command on a shell.
ShellExecutormodule-attribute
ShellExecutor=Callable[[ShellCommandRequest],MaybeAwaitable[Union[str,ShellResult]],]Executes a shell command sequence and returns either text or structured output.
Toolmodule-attribute
Tool=Union[FunctionTool,FileSearchTool,WebSearchTool,ComputerTool,HostedMCPTool,ShellTool,ApplyPatchTool,LocalShellTool,ImageGenerationTool,CodeInterpreterTool,]A tool that can be used in an agent.
ToolOutputText
ToolOutputTextDict
ToolOutputImage
Bases:BaseModel
Represents a tool output that should be sent to the model as an image.
You can provide either animage_url (URL or data URL) or afile_id for previously uploadedcontent. The optionaldetail can control vision detail.
Source code insrc/agents/tool.py
check_at_least_one_required_field
check_at_least_one_required_field()->ToolOutputImageValidate that at least one of image_url or file_id is provided.
Source code insrc/agents/tool.py
ToolOutputImageDict
Bases:TypedDict
TypedDict variant for image tool outputs.
ToolOutputFileContent
Bases:BaseModel
Represents a tool output that should be sent to the model as a file.
Provide one offile_data (base64),file_url, orfile_id. You may alsoprovide an optionalfilename when usingfile_data to hint file name.
Source code insrc/agents/tool.py
check_at_least_one_required_field
check_at_least_one_required_field()->(ToolOutputFileContent)Validate that at least one of file_data, file_url, or file_id is provided.
Source code insrc/agents/tool.py
ToolOutputFileContentDict
Bases:TypedDict
TypedDict variant for file content tool outputs.
FunctionToolResultdataclass
Source code insrc/agents/tool.py
run_iteminstance-attribute
run_item:RunItemThe run item that was produced as a result of the tool call.
FunctionTooldataclass
A tool that wraps a function. In most cases, you should use thefunction_tool helpers tocreate a FunctionTool, as they let you easily wrap a Python function.
Source code insrc/agents/tool.py
nameinstance-attribute
The name of the tool, as shown to the LLM. Generally the name of the function.
params_json_schemainstance-attribute
The JSON schema for the tool's parameters.
on_invoke_toolinstance-attribute
on_invoke_tool:Callable[[ToolContext[Any],str],Awaitable[Any]]A function that invokes the tool with the given context and parameters. The params passedare:1. The tool run context.2. The arguments from the LLM, as a JSON string.
You must return a one of the structured tool output types (e.g. ToolOutputText, ToolOutputImage,ToolOutputFileContent) or a string representation of the tool output, or a list of them,or something we can callstr() on.In case of errors, you can either raise an Exception (which will cause the run to fail) orreturn a string error message (which will be sent back to the LLM).
strict_json_schemaclass-attributeinstance-attribute
Whether the JSON schema is in strict mode. Westrongly recommend setting this to True,as it increases the likelihood of correct JSON input.
is_enabledclass-attributeinstance-attribute
is_enabled:(bool|Callable[[RunContextWrapper[Any],AgentBase],MaybeAwaitable[bool],])=TrueWhether the tool is enabled. Either a bool or a Callable that takes the run context and agentand returns whether the tool is enabled. You can use this to dynamically enable/disable a toolbased on your context/state.
tool_input_guardrailsclass-attributeinstance-attribute
tool_input_guardrails:(list[ToolInputGuardrail[Any]]|None)=NoneOptional list of input guardrails to run before invoking this tool.
tool_output_guardrailsclass-attributeinstance-attribute
tool_output_guardrails:(list[ToolOutputGuardrail[Any]]|None)=NoneOptional list of output guardrails to run after invoking this tool.
FileSearchTooldataclass
A hosted tool that lets the LLM search through a vector store. Currently only supported withOpenAI models, using the Responses API.
Source code insrc/agents/tool.py
max_num_resultsclass-attributeinstance-attribute
The maximum number of results to return.
include_search_resultsclass-attributeinstance-attribute
Whether to include the search results in the output produced by the LLM.
ranking_optionsclass-attributeinstance-attribute
Ranking options for search.
WebSearchTooldataclass
A hosted tool that lets the LLM search the web. Currently only supported with OpenAI models,using the Responses API.
Source code insrc/agents/tool.py
user_locationclass-attributeinstance-attribute
Optional location for the search. Lets you customize results to be relevant to a location.
filtersclass-attributeinstance-attribute
A filter to apply based on file attributes.
ComputerTooldataclass
A hosted tool that lets the LLM control a computer.
Source code insrc/agents/tool.py
computerinstance-attribute
computer:Computer|AsyncComputerThe computer implementation, which describes the environment and dimensions of the computer,as well as implements the computer actions like click, screenshot, etc.
on_safety_checkclass-attributeinstance-attribute
on_safety_check:(Callable[[ComputerToolSafetyCheckData],MaybeAwaitable[bool]]|None)=NoneOptional callback to acknowledge computer tool safety checks.
ComputerToolSafetyCheckDatadataclass
Information about a computer tool safety check.
Source code insrc/agents/tool.py
MCPToolApprovalRequestdataclass
A request to approve a tool call.
Source code insrc/agents/tool.py
MCPToolApprovalFunctionResult
Bases:TypedDict
The result of an MCP tool approval function.
Source code insrc/agents/tool.py
HostedMCPTooldataclass
A tool that allows the LLM to use a remote MCP server. The LLM will automatically list andcall tools, without requiring a round trip back to your code.If you want to run MCP servers locally via stdio, in a VPC or other non-publicly-accessibleenvironment, or you just prefer to run tool calls locally, then you can instead use the serversinagents.mcp and passAgent(mcp_servers=[...]) to the agent.
Source code insrc/agents/tool.py
tool_configinstance-attribute
The MCP tool config, which includes the server URL and other settings.
on_approval_requestclass-attributeinstance-attribute
on_approval_request:MCPToolApprovalFunction|None=NoneAn optional function that will be called if approval is requested for an MCP tool. If notprovided, you will need to manually add approvals/rejections to the input and callRunner.run(...) again.
CodeInterpreterTooldataclass
A tool that allows the LLM to execute code in a sandboxed environment.
Source code insrc/agents/tool.py
ImageGenerationTooldataclass
A tool that allows the LLM to generate images.
Source code insrc/agents/tool.py
LocalShellCommandRequestdataclass
A request to execute a command on a shell.
Source code insrc/agents/tool.py
LocalShellTooldataclass
A tool that allows the LLM to execute commands on a shell.
For more details, see:https://platform.openai.com/docs/guides/tools-local-shell
Source code insrc/agents/tool.py
ShellCallOutcomedataclass
ShellCommandOutputdataclass
Structured output for a single shell command execution.
Source code insrc/agents/tool.py
ShellResultdataclass
ShellActionRequestdataclass
ShellCallDatadataclass
Normalized shell call data provided to shell executors.
ShellCommandRequestdataclass
ShellTooldataclass
Next-generation shell tool. LocalShellTool will be deprecated in favor of this.
ApplyPatchTooldataclass
Hosted apply_patch tool. Lets the model request file mutations via unified diffs.
default_tool_error_function
default_tool_error_function(ctx:RunContextWrapper[Any],error:Exception)->strThe default tool error function, which just returns a generic error message.
function_tool
function_tool(func:ToolFunction[...],*,name_override:str|None=None,description_override:str|None=None,docstring_style:DocstringStyle|None=None,use_docstring_info:bool=True,failure_error_function:ToolErrorFunction|None=None,strict_mode:bool=True,is_enabled:bool|Callable[[RunContextWrapper[Any],AgentBase],MaybeAwaitable[bool],]=True,)->FunctionToolfunction_tool(*,name_override:str|None=None,description_override:str|None=None,docstring_style:DocstringStyle|None=None,use_docstring_info:bool=True,failure_error_function:ToolErrorFunction|None=None,strict_mode:bool=True,is_enabled:bool|Callable[[RunContextWrapper[Any],AgentBase],MaybeAwaitable[bool],]=True,)->Callable[[ToolFunction[...]],FunctionTool]function_tool(func:ToolFunction[...]|None=None,*,name_override:str|None=None,description_override:str|None=None,docstring_style:DocstringStyle|None=None,use_docstring_info:bool=True,failure_error_function:ToolErrorFunction|None=default_tool_error_function,strict_mode:bool=True,is_enabled:bool|Callable[[RunContextWrapper[Any],AgentBase],MaybeAwaitable[bool],]=True,)->(FunctionTool|Callable[[ToolFunction[...]],FunctionTool])Decorator to create a FunctionTool from a function. By default, we will:1. Parse the function signature to create a JSON schema for the tool's parameters.2. Use the function's docstring to populate the tool's description.3. Use the function's docstring to populate argument descriptions.The docstring style is detected automatically, but you can override it.
If the function takes aRunContextWrapper as the first argument, itmust match thecontext type of the agent that uses the tool.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
func | ToolFunction[...] | None | The function to wrap. | None |
name_override | str | None | If provided, use this name for the tool instead of the function's name. | None |
description_override | str | None | If provided, use this description for the tool instead of thefunction's docstring. | None |
docstring_style | DocstringStyle | None | If provided, use this style for the tool's docstring. If not provided,we will attempt to auto-detect the style. | None |
use_docstring_info | bool | If True, use the function's docstring to populate the tool'sdescription and argument descriptions. | True |
failure_error_function | ToolErrorFunction | None | If provided, use this function to generate an error message whenthe tool call fails. The error message is sent to the LLM. If you pass None, then noerror message will be sent and instead an Exception will be raised. | default_tool_error_function |
strict_mode | bool | Whether to enable strict mode for the tool's JSON schema. Westronglyrecommend setting this to True, as it increases the likelihood of correct JSON input.If False, it allows non-strict JSON schemas. For example, if a parameter has a defaultvalue, it will be optional, additional properties are allowed, etc. See here for more:https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#supported-schemas | True |
is_enabled | bool |Callable[[RunContextWrapper[Any],AgentBase],MaybeAwaitable[bool]] | Whether the tool is enabled. Can be a bool or a callable that takes the runcontext and agent and returns whether the tool is enabled. Disabled tools are hiddenfrom the LLM at runtime. | True |
Source code insrc/agents/tool.py
526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674 | |