Long-running agents are in preview. APIs and package versions are subject to change.
Prerequisites
- An Azure subscription with Microsoft Foundry access.
- Python 3.13.
- The Azure Developer CLI (
azd) with the Foundry agents extension:azd extension install azure.ai.agents.
Get the sample
In an empty directory, initialize the resilient streaming agent from itsazure.yaml manifest:
azure.yaml, creates an azd environment, and connects it to the Foundry project you select.
The sample opts in to resilience when it creates the host:
resilient_background defaults to False. Without it, a background response that crashes is marked failed instead of being recovered. See Recover long-running work after a crash.Run it locally
The resilient state store uses files when you run it locally, so your machine uses the same recovery code path.azd ai agent run installs the Python dependencies, injects the active azd environment, and starts the agent on http://localhost:8088.
Test crash recovery locally
Use Linux, WSL2, or a container for this exercise so the operating system releases the file lock when the process exits. In the terminal that runs the agent, setSIMULATE_CRASH_AFTER_STAGE so the sample crashes after it checkpoints the first stage, and then start it:
store: true and background: true), so send the full request body from a file. In a second terminal, create the request file:
context.is_recovery == True. The handler restores context.persisted_response, skips the checkpointed analyze stage, and completes the generate and refine stages.
Deploy to Foundry
Provision the project and deploy the agent. When prompted for a location, choose a region that supports hosted agents.azd up prints the Responses endpoint and a playground link.
Invoke the deployed agent
Create a stored background response on the deployed agent. Reuse the samerequest.json body:
starting_after cursor, see Stream with reconnect.