Skip to content

Commit 306d426

Browse files
authored
docs: changes for #3487 feature addition (#3488)
1 parent f918c6a commit 306d426

4 files changed

Lines changed: 12 additions & 4 deletions

File tree

docs/guardrails.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Tool guardrails wrap **function tools** and let you validate or block tool calls
5757

5858
- Input tool guardrails run before the tool executes and can skip the call, replace the output with a message, or raise a tripwire.
5959
- Output tool guardrails run after the tool executes and can replace the output or raise a tripwire.
60+
- If a function tool requires approval, input tool guardrails normally run after approval and immediately before execution. Set [`RunConfig.tool_execution`][agents.run.RunConfig.tool_execution] to [`ToolExecutionConfig(pre_approval_tool_input_guardrails=True)`][agents.run.ToolExecutionConfig] when you want those input checks to run before the pending approval interruption is emitted. Calls that pass this pre-approval check are still checked again after approval before the tool executes.
6061
- Tool guardrails apply only to function tools created with [`function_tool`][agents.tool.function_tool]. Handoffs run through the SDK's handoff pipeline rather than the normal function-tool pipeline, so tool guardrails do not apply to the handoff call itself. Hosted tools (`WebSearchTool`, `FileSearchTool`, `HostedMCPTool`, `CodeInterpreterTool`, `ImageGenerationTool`) and built-in execution tools (`ComputerTool`, `ShellTool`, `ApplyPatchTool`, `LocalShellTool`) also do not use this guardrail pipeline, and [`Agent.as_tool()`][agents.agent.Agent.as_tool] does not currently expose tool-guardrail options directly.
6162

6263
See the code snippet below for details.

docs/realtime/guide.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ agent = RealtimeAgent(
206206

207207
Function tools can require human approval before execution. When that happens, the session emits `tool_approval_required` and pauses the tool run until you call `approve_tool_call()` or `reject_tool_call()`.
208208

209+
If the tool also has input guardrails, those guardrails run immediately before execution after approval. To run them before the approval event is emitted, create the runner with `RealtimeRunner(..., config={"tool_execution": {"pre_approval_tool_input_guardrails": True}})`. Calls that pass this pre-approval check are still checked again after approval before execution.
210+
209211
```python
210212
async for event in session:
211213
if event.type == "tool_approval_required":
@@ -242,7 +244,7 @@ Bare `RealtimeAgent` handoffs are auto-wrapped, and `realtime_handoff(...)` lets
242244

243245
### Guardrails
244246

245-
Only output guardrails are supported for realtime agents. They run on debounced transcript accumulation rather than on every partial token, and they emit `guardrail_tripped` instead of raising an exception.
247+
Realtime agents support output guardrails on agent responses and input guardrails on function-tool calls. Output guardrails run on debounced transcript accumulation rather than on every partial token, and they emit `guardrail_tripped` instead of raising an exception.
246248

247249
```python
248250
from agents.guardrail import GuardrailFunctionOutput, OutputGuardrail

docs/realtime/quickstart.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Once the basic session works, the settings most people reach for next are:
114114
- `audio.input.turn_detection` for automatic turn detection
115115
- `audio.output.voice`
116116
- `tool_choice`, `prompt`, `tracing`
117-
- `async_tool_calls`, `guardrails_settings.debounce_text_length`, `tool_error_formatter`
117+
- `async_tool_calls`, `tool_execution.pre_approval_tool_input_guardrails`, `guardrails_settings.debounce_text_length`, `tool_error_formatter`
118118

119119
The older flat aliases such as `input_audio_format`, `output_audio_format`, `input_audio_transcription`, and `turn_detection` still work, but nested `audio` settings are preferred for new code.
120120

docs/running_agents.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Nested handoffs are available as an opt-in beta. Enable the collapsed-transcript
164164

165165
##### `tool_execution`
166166

167-
Use `tool_execution` when you want the SDK to limit local function-tool concurrency for a run.
167+
Use `tool_execution` when you want to configure SDK-side behavior for local function tools, such as limiting local function-tool concurrency for a run.
168168

169169
```python
170170
from agents import Agent, RunConfig, Runner, ToolExecutionConfig
@@ -175,7 +175,10 @@ result = await Runner.run(
175175
agent,
176176
"Run the required tool calls.",
177177
run_config=RunConfig(
178-
tool_execution=ToolExecutionConfig(max_function_tool_concurrency=2),
178+
tool_execution=ToolExecutionConfig(
179+
max_function_tool_concurrency=2,
180+
pre_approval_tool_input_guardrails=True,
181+
),
179182
),
180183
)
181184
```
@@ -184,6 +187,8 @@ result = await Runner.run(
184187

185188
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.
186189

190+
`pre_approval_tool_input_guardrails=False` preserves the default approval flow: if a function tool needs approval, the run pauses first and the tool input guardrails run only after approval, immediately before execution. Set it to `True` when you want function-tool input guardrails to run before the pending approval interruption is emitted. Calls that pass this pre-approval check still run the same input guardrails again after approval, so time-sensitive checks are revalidated before execution.
191+
187192
##### `tool_not_found_behavior`
188193

189194
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`.

0 commit comments

Comments
 (0)