What this thread does
Do first: convert the paused result with state = result.to_state().
When you need it
A tool that needs approval pauses execution and exposes pending requests in result.interruptions. Persist the resulting state when a decision will arrive later, then resume the original top-level agent.
Steps
1. Use the page's example imports and storage path in the application that already has its agent and paused result:
import json
from pathlib import Path
from agents import Agent, Runner, RunState
STATE_PATH = Path(".cache/hitl_state.json")
2. Convert and save the paused state:
state = result.to_state()
STATE_PATH.parent.mkdir(parents=True, exist_ok=True)
STATE_PATH.write_text(state.to_string())
3. Reload from trusted storage using the original top-level agent:
stored = json.loads(STATE_PATH.read_text())
state = await RunState.from_json(agent, stored)
4. Obtain pending requests with state.get_interruptions() when loading a stored snapshot. Apply the reviewer's decision to each selected interruption. The example's decision branches use:
state.approve(interruption, always_approve=False)
For a rejected request, use the page's alternative:
state.reject(interruption)
5. Resume with the original top-level agent:
result = await Runner.run(agent, state)
Continue the approval loop if new interruptions appear.
Check it worked
The example loops while result.interruptions is nonempty and prints result.final_output after the loop. A resumed run may pause again for further approvals.
Limits
The page does not name a version. Deserialization does not authenticate the snapshot or reviewer: load only trusted state, authenticate and authorize reviewers, and coordinate consumption to prevent replay. State contains tool arguments and execution data; keep secrets out of persisted application context. Approval permits execution but does not guarantee exactly-once effects. The page calls for destination-enforced idempotency or authoritative reconciliation before retrying consequential actions.
Not for: resuming streamed output; see openai-agents-sdk-approve-resume-streaming-run.
Sources
- Human-in-the-loop, OpenAI Agents SDK documentation, read 2026-11-24: "Approval permits a tool call to execute; it does not guarantee exactly-once execution."
Checked
2026-11-24; read <https://openai.github.io/openai-agents-python/human_in_the_loop/>; no command was run.
Started from a post by @OpenAI, packaged by the editor. Original post