Long-running agents are in preview. APIs and package versions are subject to change.
Turn on crash recovery
Crash recovery is off by default. Enable it explicitly for the surface you use.Responses protocol
Setresilient_background=True on ResponsesServerOptions:
store=true and background=true. When you enable the opt-in and the container crashes mid-response, the framework reinvokes your handler on restart, replays persisted stream events to reconnecting clients, and preserves conversation state.
Without
resilient_background=True, a background response that crashes is marked failed with error.code="server_error" - the framework does not reinvoke the handler. Foreground (background=false) responses are always marked failed on crash, because their client connection is already gone.Invocations / task primitives
When you build directly on the task primitives, declaring a@task or @multi_turn_task handler automatically enables the startup recovery scan. If you register tasks lazily after host startup, force-enable the scan before startup:
What you get for free
When you turn on recovery, you get the framework half with no handler changes:
A naive recovered handler still produces a correct response - it just reruns the whole turn. Making the recovered attempt resume where it left off is the handler half you take on when you need it.
Detect a recovered entry
On reinvocation, branch on the recovery marker rather than reconstructing the original request.- Responses
- Tasks
Choose a resume strategy
Pick a strategy based on where your progress state lives.
Prefer phase boundaries that checkpoint cleanly: complete one output item per phase, then checkpoint. If a phase crashes before its checkpoint it reruns; after the checkpoint the recovered attempt skips it.