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/human_in_the_loop.md
+15-1Lines changed: 15 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -123,7 +123,21 @@ To stream output while waiting for approvals, call `Runner.run_streamed`, consum
123
123
124
124
## Long-running approvals
125
125
126
-
`RunState` is designed to be durable. Use `state.to_json()` or `state.to_string()` to store pending work in a database or queue and recreate it later with `RunState.from_json(...)` or `RunState.from_string(...)`. Pass `context_override` if you do not want to persist sensitive context data in the serialized payload.
126
+
`RunState` is designed to be durable. Use `state.to_json()` or `state.to_string()` to store pending work in a database or queue and recreate it later with `RunState.from_json(...)` or `RunState.from_string(...)`.
127
+
128
+
Useful serialization options:
129
+
130
+
-`context_serializer`: Customize how non-mapping context objects are serialized.
131
+
-`strict_context=True`: Fail serialization or deserialization unless the context is already a
132
+
mapping or you provide the appropriate serializer/deserializer.
133
+
-`context_override`: Replace the serialized context when loading state. This is useful when you
134
+
do not want to restore the original context object, but it does not remove that context from an
135
+
already serialized payload.
136
+
-`include_tracing_api_key=True`: Include the tracing API key in the serialized trace payload
137
+
when you need resumed work to keep exporting traces with the same credentials.
138
+
139
+
`RunState` also preserves trace metadata and server-managed conversation settings, so a resumed run
140
+
can continue the same trace and the same `conversation_id` / `previous_response_id` chain.
Copy file name to clipboardExpand all lines: docs/results.md
+8-2Lines changed: 8 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,11 @@ The [`input`][agents.result.RunResultBase.input] property contains the original
55
55
56
56
### Interruptions and resuming runs
57
57
58
-
If a run pauses for tool approval, pending approvals are exposed in [`interruptions`][agents.result.RunResultBase.interruptions]. Convert the result into a [`RunState`][agents.run_state.RunState] with `to_state()`, approve or reject the interruption(s), and resume with `Runner.run(...)` or `Runner.run_streamed(...)`.
58
+
If a run pauses for tool approval, pending approvals are exposed in
59
+
[`RunResult.interruptions`][agents.result.RunResult.interruptions] or
60
+
[`RunResultStreaming.interruptions`][agents.result.RunResultStreaming.interruptions]. Convert the
61
+
result into a [`RunState`][agents.run_state.RunState] with `to_state()`, approve or reject the
62
+
interruption(s), and resume with `Runner.run(...)` or `Runner.run_streamed(...)`.
59
63
60
64
```python
61
65
from agents import Agent, Runner
@@ -70,7 +74,9 @@ if result.interruptions:
70
74
result =await Runner.run(agent, state)
71
75
```
72
76
73
-
Both [`RunResult`][agents.result.RunResult] and [`RunResultStreaming`][agents.result.RunResultStreaming] support `to_state()`.
77
+
Both [`RunResult`][agents.result.RunResult] and
78
+
[`RunResultStreaming`][agents.result.RunResultStreaming] support `to_state()`. For durable
79
+
approval workflows, see the [human-in-the-loop guide](human_in_the_loop.md).
Copy file name to clipboardExpand all lines: docs/running_agents.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,7 +25,11 @@ Read more in the [results guide](results.md).
25
25
26
26
### The agent loop
27
27
28
-
When you use the run method in `Runner`, you pass in a starting agent and input. The input can either be a string (which is considered a user message), or a list of input items, which are the items in the OpenAI Responses API.
28
+
When you use the run method in `Runner`, you pass in a starting agent and input. The input can be:
29
+
30
+
- a string (treated as a user message),
31
+
- a list of input items in the OpenAI Responses API format, or
32
+
- a [`RunState`][agents.run_state.RunState] when resuming an interrupted run.
29
33
30
34
The runner then runs a loop:
31
35
@@ -123,7 +127,7 @@ Use `RunConfig` to override behavior for a single run without changing each agen
123
127
-[`model_provider`][agents.run.RunConfig.model_provider]: A model provider for looking up model names, which defaults to OpenAI.
124
128
-[`model_settings`][agents.run.RunConfig.model_settings]: Overrides agent-specific settings. For example, you can set a global `temperature` or `top_p`.
125
129
-[`session_settings`][agents.run.RunConfig.session_settings]: Overrides session-level defaults (for example, `SessionSettings(limit=...)`) when retrieving history during a run.
126
-
-[`session_input_callback`][agents.run.RunConfig.session_input_callback]: Customize how new user input is merged with session history before each turn when using Sessions.
130
+
-[`session_input_callback`][agents.run.RunConfig.session_input_callback]: Customize how new user input is merged with session history before each turn when using Sessions. The callback can be sync or async.
127
131
128
132
##### Guardrails, handoffs, and model input shaping
129
133
@@ -345,6 +349,10 @@ async def main():
345
349
print(f"Assistant: {result.final_output}")
346
350
```
347
351
352
+
If a run pauses for approval and you resume from a [`RunState`][agents.run_state.RunState], the
353
+
SDK keeps the saved `conversation_id` / `previous_response_id` / `auto_previous_response_id`
354
+
settings so the resumed turn continues in the same server-managed conversation.
355
+
348
356
!!! note
349
357
350
358
The SDK automatically retries `conversation_locked` errors with backoff. In server-managed
@@ -378,7 +386,7 @@ result = Runner.run_sync(
378
386
)
379
387
```
380
388
381
-
Set the hook per run via `run_config`or as a default on your `Runner`to redact sensitive data, trim long histories, or inject additional system guidance.
389
+
Set the hook per run via `run_config` to redact sensitive data, trim long histories, or inject additional system guidance.
Copy file name to clipboardExpand all lines: docs/streaming.md
+16Lines changed: 16 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -35,6 +35,22 @@ if __name__ == "__main__":
35
35
36
36
[`RunItemStreamEvent`][agents.stream_events.RunItemStreamEvent]s are higher level events. They inform you when an item has been fully generated. This allows you to push progress updates at the level of "message generated", "tool ran", etc, instead of each token. Similarly, [`AgentUpdatedStreamEvent`][agents.stream_events.AgentUpdatedStreamEvent] gives you updates when the current agent changes (e.g. as the result of a handoff).
37
37
38
+
### Run item event names
39
+
40
+
`RunItemStreamEvent.name` uses a fixed set of semantic event names:
41
+
42
+
-`message_output_created`
43
+
-`handoff_requested`
44
+
-`handoff_occured`
45
+
-`tool_called`
46
+
-`tool_output`
47
+
-`reasoning_item_created`
48
+
-`mcp_approval_requested`
49
+
-`mcp_approval_response`
50
+
-`mcp_list_tools`
51
+
52
+
`handoff_occured` is intentionally misspelled for backward compatibility.
53
+
38
54
For example, this will ignore raw events and stream updates to the user.
0 commit comments