Skip to content

Commit 5d48424

Browse files
authored
Update docs (#2307)
1 parent 97e811b commit 5d48424

15 files changed

Lines changed: 174 additions & 8 deletions

docs/guardrails.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,57 @@ Output guardrails run in 3 steps:
4141

4242
Output guardrails always run after the agent completes, so they don't support the `run_in_parallel` parameter.
4343

44+
## Tool guardrails
45+
46+
Tool guardrails wrap **function tools** and let you validate or block tool calls before and after execution. They are configured on the tool itself and run every time that tool is invoked.
47+
48+
- Input tool guardrails run before the tool executes and can skip the call, replace the output with a message, or raise a tripwire.
49+
- Output tool guardrails run after the tool executes and can replace the output or raise a tripwire.
50+
- Tool guardrails apply only to function tools created with [`function_tool`][agents.function_tool]; hosted tools (`WebSearchTool`, `FileSearchTool`, `HostedMCPTool`, `CodeInterpreterTool`, `ImageGenerationTool`) and local runtime tools (`ComputerTool`, `ShellTool`, `ApplyPatchTool`, `LocalShellTool`) do not use this guardrail pipeline.
51+
52+
```python
53+
import json
54+
from agents import (
55+
Agent,
56+
Runner,
57+
ToolGuardrailFunctionOutput,
58+
function_tool,
59+
tool_input_guardrail,
60+
tool_output_guardrail,
61+
)
62+
63+
@tool_input_guardrail
64+
def block_secrets(data):
65+
args = json.loads(data.context.tool_arguments or "{}")
66+
if "sk-" in json.dumps(args):
67+
return ToolGuardrailFunctionOutput.reject_content(
68+
"Remove secrets before calling this tool."
69+
)
70+
return ToolGuardrailFunctionOutput.allow()
71+
72+
73+
@tool_output_guardrail
74+
def redact_output(data):
75+
text = str(data.output or "")
76+
if "sk-" in text:
77+
return ToolGuardrailFunctionOutput.reject_content("Output contained sensitive data.")
78+
return ToolGuardrailFunctionOutput.allow()
79+
80+
81+
@function_tool(
82+
tool_input_guardrails=[block_secrets],
83+
tool_output_guardrails=[redact_output],
84+
)
85+
def classify_text(text: str) -> str:
86+
"""Classify text for internal routing."""
87+
return f"length:{len(text)}"
88+
89+
90+
agent = Agent(name="Classifier", tools=[classify_text])
91+
result = Runner.run_sync(agent, "hello world")
92+
print(result.final_output)
93+
```
94+
4495
## Tripwires
4596

4697
If the input or output fails the guardrail, the Guardrail can signal this with a tripwire. As soon as we see a guardrail that has triggered the tripwires, we immediately raise a `{Input,Output}GuardrailTripwireTriggered` exception and halt the Agent execution.
@@ -161,4 +212,4 @@ async def main():
161212
1. This is the actual agent's output type.
162213
2. This is the guardrail's output type.
163214
3. This is the guardrail function that receives the agent's output, and returns the result.
164-
4. This is the actual agent that defines the workflow.
215+
4. This is the actual agent that defines the workflow.

docs/handoffs.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Handoffs are represented as tools to the LLM. So if there's a handoff to an agen
88

99
All agents have a [`handoffs`][agents.agent.Agent.handoffs] param, which can either take an `Agent` directly, or a `Handoff` object that customizes the Handoff.
1010

11+
If you pass plain `Agent` instances, their [`handoff_description`][agents.agent.Agent.handoff_description] (when set) is appended to the default tool description. Use it to hint when the model should pick that handoff without writing a full `handoff()` object.
12+
1113
You can create a handoff using the [`handoff()`][agents.handoffs.handoff] function provided by the Agents SDK. This function allows you to specify the agent to hand off to, along with optional overrides and input filters.
1214

1315
### Basic Usage

docs/mcp.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,10 @@ The constructor accepts additional options:
181181

182182
## 3. HTTP with SSE MCP servers
183183

184+
!!! warning
185+
186+
The MCP project has deprecated the Server-Sent Events transport. Prefer Streamable HTTP or stdio for new integrations and keep SSE only for legacy servers.
187+
184188
If the MCP server implements the HTTP with SSE transport, instantiate
185189
[`MCPServerSse`][agents.mcp.server.MCPServerSse]. Apart from the transport, the API is identical to the Streamable HTTP server.
186190

docs/models/litellm.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,13 @@ agent = Agent(
8888
```
8989

9090
With `include_usage=True`, LiteLLM requests report token and request counts through `result.context_wrapper.usage` just like the built-in OpenAI models.
91+
92+
## Troubleshooting
93+
94+
If you see Pydantic serializer warnings from LiteLLM responses, enable a small compatibility patch by setting:
95+
96+
```bash
97+
export OPENAI_AGENTS_ENABLE_LITELLM_SERIALIZER_PATCH=true
98+
```
99+
100+
This opt-in flag suppresses known LiteLLM serializer warnings while preserving normal behavior. Turn it off (unset or `false`) if you do not need it.

docs/ref/apply_diff.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Apply Diff`
2+
3+
::: agents.apply_diff

docs/ref/editor.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Editor`
2+
3+
::: agents.editor
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Async Sqlite Session`
2+
3+
::: agents.extensions.memory.async_sqlite_session

docs/ref/handoffs/history.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `History`
2+
3+
::: agents.handoffs.history
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Openai Responses Compaction Session`
2+
3+
::: agents.memory.openai_responses_compaction_session

docs/ref/tracing/config.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# `Config`
2+
3+
::: agents.tracing.config

0 commit comments

Comments
 (0)