| name | ai-python-durable-execution |
| description | Use when adding durable execution to AI SDK for Python, building durable agent loops, or serializing messages across workflow steps. |
| metadata | {"sdk-version":"0.2.1"} |
ai-python-durable-execution
Use durable execution when an agent run must survive restarts, worker moves, or
long waits.
The SDK does not provide durability by itself. Build a custom Agent.loop, and
put side effects inside durable steps:
- model calls
- tool I/O
- approval or resume boundaries
Keep the workflow replayable. Durable steps should take JSON inputs and return
JSON outputs.
Serialize messages like this:
data = message.model_dump(mode="json")
message = ai.messages.Message.model_validate(data)
Model Step
A durable model step should drain ai.stream(...) inside the step and return one
complete assistant Message.
@workflow.step
async def llm_step(
model_data: dict[str, object],
messages_data: list[dict[str, object]],
tools_data: [[, ]],
) -> [, ]:
model = ai.Model.model_validate(model_data)
messages = [
ai.messages.Message.model_validate(message)
message messages_data
]
tools = [ai.Tool.model_validate(tool) tool tools_data]
ai.stream(model, messages, tools=tools) stream:
_event stream:
stream.message :
RuntimeError()
stream.message.model_dump(mode=)