Skip to content

Commit f918c6a

Browse files
authored
docs: #3461 changes for tool_not_found_behavior option (#3462)
1 parent 510b7de commit f918c6a

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

docs/running_agents.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ Use `RunConfig` to override behavior for a single run without changing each agen
155155
##### Tool execution, approval, and tool error behavior
156156

157157
- [`tool_execution`][agents.run.RunConfig.tool_execution]: Configure SDK-side execution behavior for local tool calls, such as limiting how many function tools run at once.
158-
- [`tool_error_formatter`][agents.run.RunConfig.tool_error_formatter]: Customize the model-visible message when a tool call is rejected during approval flows.
158+
- [`tool_not_found_behavior`][agents.run.RunConfig.tool_not_found_behavior]: Configure how the runner handles unresolved function tool calls emitted by the model. The default raises `ModelBehaviorError`; opt in to return a model-visible error output instead.
159+
- [`tool_error_formatter`][agents.run.RunConfig.tool_error_formatter]: Customize model-visible tool error messages, such as approval rejections and opt-in tool-not-found outputs.
159160

160161
Nested handoffs are available as an opt-in beta. Enable the collapsed-transcript behavior by passing `RunConfig(nest_handoff_history=True)` or set `handoff(..., nest_handoff_history=True)` to turn it on for a specific handoff. If you prefer to keep the raw transcript (the default), leave the flag unset or provide a `handoff_input_filter` (or `handoff_history_mapper`) that forwards the conversation exactly as you need. To change the wrapper text used in the generated summary without writing a custom mapper, call [`set_conversation_history_wrappers`][agents.handoffs.set_conversation_history_wrappers] (and [`reset_conversation_history_wrappers`][agents.handoffs.reset_conversation_history_wrappers] to restore the defaults).
161162

@@ -183,13 +184,33 @@ result = await Runner.run(
183184

184185
This is separate from provider-side [`ModelSettings.parallel_tool_calls`][agents.model_settings.ModelSettings.parallel_tool_calls]. `parallel_tool_calls` controls whether the model is allowed to emit multiple tool calls in a single response. `tool_execution.max_function_tool_concurrency` controls how the SDK executes local function tool calls after the model has emitted them.
185186

187+
##### `tool_not_found_behavior`
188+
189+
By default, if the model emits a function tool call that does not match any function tool available to the current agent, the runner raises `ModelBehaviorError`.
190+
191+
Set `tool_not_found_behavior="return_error_to_model"` when you want the run to remain recoverable. In that mode, the SDK appends a `function_call_output` for the unresolved tool call and runs the model again, so the model can choose an available tool or answer without using that tool.
192+
193+
```python
194+
from agents import Agent, RunConfig, Runner
195+
196+
agent = Agent(name="Assistant", tools=[...])
197+
198+
result = await Runner.run(
199+
agent,
200+
"Handle this request with the available tools.",
201+
run_config=RunConfig(tool_not_found_behavior="return_error_to_model"),
202+
)
203+
```
204+
205+
This option currently applies to unresolved function tool calls only. Other invalid tool payloads continue to use their existing error behavior.
206+
186207
##### `tool_error_formatter`
187208

188-
Use `tool_error_formatter` to customize the message that is returned to the model when a tool call is rejected in an approval flow.
209+
Use `tool_error_formatter` to customize the message that is returned to the model when the SDK creates a model-visible tool error output.
189210

190211
The formatter receives [`ToolErrorFormatterArgs`][agents.run_config.ToolErrorFormatterArgs] with:
191212

192-
- `kind`: The error category. Today this is `"approval_rejected"`.
213+
- `kind`: The error category, such as `"approval_rejected"` or `"tool_not_found"`.
193214
- `tool_type`: The tool runtime (`"function"`, `"computer"`, `"shell"`, `"apply_patch"`, or `"custom"`).
194215
- `tool_name`: The tool name.
195216
- `call_id`: The tool call ID.
@@ -208,6 +229,8 @@ def format_rejection(args: ToolErrorFormatterArgs[None]) -> str | None:
208229
f"Tool call '{args.tool_name}' was rejected by a human reviewer. "
209230
"Ask for confirmation or propose a safer alternative."
210231
)
232+
if args.kind == "tool_not_found":
233+
return f"Tool '{args.tool_name}' is not available. Choose one of the listed tools."
211234
return None
212235

213236

0 commit comments

Comments
 (0)