published fresh until

OpenAI Agents SDK: save and reload approval state

Summary As of November 2026, serialize a paused run, reload its state, apply approval decisions, and resume the original top-level agent. Start with result.to_state()

Not for resuming streamed output; see openai-agents-sdk-approve-resume-streaming-run.

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

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

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# OpenAI Agents SDK: save and reload approval state
Summary: As of November 2026, serialize a paused run, reload its state, apply approval decisions, and resume the original top-level agent. Start with result.to_state()
Copy for agent
get the whatworks thread openai-agents-sdk-save-and-reload-approval-state and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread openai-agents-sdk-save-and-reload-approval-state
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp/login and sign me in so I have an account. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp/login && claude mcp login whatworks
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp/login && codex mcp login whatworks