You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/agents.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -33,9 +33,11 @@ The most common properties of an agent are:
33
33
|`model_settings`| no | Model tuning parameters such as `temperature`, `top_p`, and `tool_choice`. |
34
34
|`tools`| no | Tools the agent can call. See [Tools](tools.md). |
35
35
|`mcp_servers`| no | MCP-backed tools for the agent. See the [MCP guide](mcp.md). |
36
+
|`mcp_config`| no | Fine-tune how MCP tools are prepared, such as strict schema conversion and MCP failure formatting. See the [MCP guide](mcp.md#agent-level-mcp-configuration). |
36
37
|`input_guardrails`| no | Guardrails that run on the first user input for this agent chain. See [Guardrails](guardrails.md). |
37
38
|`output_guardrails`| no | Guardrails that run on the final output for this agent. See [Guardrails](guardrails.md). |
38
39
|`output_type`| no | Structured output type instead of plain text. See [Output types](#output-types). |
40
+
|`hooks`| no | Agent-scoped lifecycle callbacks. See [Lifecycle events (hooks)](#lifecycle-events-hooks). |
39
41
|`tool_use_behavior`| no | Control whether tool results loop back to the model or end the run. See [Tool use behavior](#tool-use-behavior). |
40
42
|`reset_tool_choice`| no | Reset `tool_choice` after a tool call (default: `True`) to avoid tool-use loops. See [Forcing tool use](#forcing-tool-use). |
Copy file name to clipboardExpand all lines: docs/human_in_the_loop.md
+31Lines changed: 31 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,6 +51,36 @@ Sticky decisions created with `always_approve=True` or `always_reject=True` are
51
51
52
52
You do not need to resolve every pending approval in the same pass. `interruptions` can contain a mix of regular function tools, hosted MCP approvals, and nested `Agent.as_tool()` approvals. If you rerun after approving or rejecting only some items, those resolved calls can continue while unresolved ones remain in `interruptions` and pause the run again.
53
53
54
+
## Custom rejection messages
55
+
56
+
By default, a rejected tool call returns the SDK's standard rejection text back into the run. You can customize that message in two layers:
57
+
58
+
- Run-wide fallback: set [`RunConfig.tool_error_formatter`][agents.run.RunConfig.tool_error_formatter] to control the default model-visible message for approval rejections across the whole run.
59
+
- Per-call override: pass `rejection_message=...` to `state.reject(...)` when you want one specific rejected tool call to surface a different message.
60
+
61
+
If both are provided, the per-call `rejection_message` takes precedence over the run-wide formatter.
62
+
63
+
```python
64
+
from agents import RunConfig, ToolErrorFormatterArgs
rejection_message="Publish action was canceled because the reviewer denied approval.",
79
+
)
80
+
```
81
+
82
+
See [`examples/agent_patterns/human_in_the_loop_custom_rejection.py`](https://github.com/openai/openai-agents-python/tree/main/examples/agent_patterns/human_in_the_loop_custom_rejection.py) for a complete example that shows both layers together.
83
+
54
84
## Automatic approval decisions
55
85
56
86
Manual `interruptions` are the most general pattern, but they are not the only one:
@@ -140,6 +170,7 @@ To stream output while waiting for approvals, call `Runner.run_streamed`, consum
140
170
## Repository patterns and examples
141
171
142
172
-**Streaming approvals**: `examples/agent_patterns/human_in_the_loop_stream.py` shows how to drain `stream_events()` and then approve pending tool calls before resuming with `Runner.run_streamed(agent, state)`.
173
+
-**Custom rejection text**: `examples/agent_patterns/human_in_the_loop_custom_rejection.py` shows how to combine run-level `tool_error_formatter` with per-call `rejection_message` overrides when approvals are rejected.
143
174
-**Agent as tool approvals**: `Agent.as_tool(..., needs_approval=...)` applies the same interruption flow when delegated agent tasks need review. Nested interruptions still surface on the outer run, so resume the original top-level agent rather than the nested one.
144
175
-**Local shell and apply_patch tools**: `ShellTool` and `ApplyPatchTool` also support `needs_approval`. Use `state.approve(interruption, always_approve=True)` or `state.reject(..., always_reject=True)` to cache the decision for future calls. For automatic decisions, provide `on_approval` (see `examples/tools/shell.py`); for manual decisions, handle interruptions (see `examples/tools/shell_human_in_the_loop.py`). Hosted shell environments do not support `needs_approval` or `on_approval`; see the [tools guide](tools.md).
145
176
-**Local MCP servers**: Use `require_approval` on `MCPServerStdio` / `MCPServerSse` / `MCPServerStreamableHttp` to gate MCP tool calls (see `examples/mcp/get_all_mcp_tools_example/main.py` and `examples/mcp/tool_filter_example/main.py`).
Copy file name to clipboardExpand all lines: docs/models/index.md
+4Lines changed: 4 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -265,6 +265,7 @@ When you are using the OpenAI Responses API, several request fields already have
265
265
| --- | --- |
266
266
|`parallel_tool_calls`| Allow or forbid multiple tool calls in the same turn. |
267
267
|`truncation`| Set `"auto"` to let the Responses API drop the oldest conversation items instead of failing when context would overflow. |
268
+
|`store`| Control whether the generated response is stored server-side for later retrieval. This matters for follow-up workflows that rely on response IDs, and for session compaction flows that may need to fall back to local input when `store=False`. |
268
269
|`prompt_cache_retention`| Keep cached prompt prefixes around longer, for example with `"24h"`. |
269
270
|`response_include`| Request richer response payloads such as `web_search_call.action.sources`, `file_search_call.results`, or `reasoning.encrypted_content`. |
270
271
|`top_logprobs`| Request top-token logprobs for output text. The SDK also adds `message.output_text.logprobs` automatically. |
When you set `store=False`, the Responses API does not keep that response available for later server-side retrieval. This is useful for stateless or zero-data-retention style flows, but it also means features that would otherwise reuse response IDs need to rely on locally managed state instead. For example, [`OpenAIResponsesCompactionSession`][agents.memory.openai_responses_compaction_session.OpenAIResponsesCompactionSession] switches its default `"auto"` compaction path to input-based compaction when the last response was not stored. See the [Sessions guide](../sessions/index.md#openai-responses-compaction-sessions).
292
+
289
293
#### Runner-managed retries
290
294
291
295
Retries are runtime-only and opt in. The SDK does not retry general model requests unless you set `ModelSettings(retry=...)` and your retry policy chooses to retry.
Copy file name to clipboardExpand all lines: docs/sessions/index.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -277,6 +277,8 @@ By default, compaction runs after each turn once the candidate threshold is reac
277
277
278
278
`compaction_mode="previous_response_id"` works best when you are already chaining turns with Responses API response IDs. `compaction_mode="input"` rebuilds the compaction request from the current session items instead, which is useful when the response chain is unavailable or you want the session contents to be the source of truth. The default `"auto"` chooses the safest available option.
279
279
280
+
If your agent runs with `ModelSettings(store=False)`, the Responses API does not retain the last response for later lookup. In that stateless setup, the default `"auto"` mode falls back to input-based compaction instead of relying on `previous_response_id`. See [`examples/memory/compaction_session_stateless_example.py`](https://github.com/openai/openai-agents-python/tree/main/examples/memory/compaction_session_stateless_example.py) for a complete example.
281
+
280
282
#### auto-compaction can block streaming
281
283
282
284
Compaction clears and rewrites the session history, so the SDK waits for compaction to finish before considering the run complete. In streaming mode, this means `run.stream_events()` can stay open for a few seconds after the last output token if compaction is heavy.
0 commit comments