AgentSpan and LangGraph: durable Python agent tutorial

Build crash recovery and human approval workflows with AgentSpan, then wrap an existing LangGraph graph while preserving its internal logic.

Player not loading? Watch on YouTube

This Python tutorial explains how AgentSpan stores workflow state on a server so an AI agent can resume after a worker process stops or wait for human approval. The speaker describes the platform as open source and self-hostable, and discloses that AgentSpan sponsors the video.

Setup uses uv, with pip offered as an alternative. The examples call OpenAI's GPT-4o and require a provider API key in the server environment. The walkthrough therefore covers a locally running workflow server, rather than offline model inference. The speaker uses the doctor command to check provider configuration and monitors executions at localhost:6767.

The first example processes mock data chunks and aggregates their results. A file holds the execution ID, allowing the script to reattach to the same execution after a keyboard interrupt. Resuming requires the same agent and tools to be available. The script removes the ID file when work finishes.

A mock refund workflow then adds a tool that requires approval. The speaker interrupts the process while approval is pending, restarts it, and responds through the terminal. The final example adapts an existing LangGraph workflow. A runtime wrapper exposes monitoring, but recovery also needs deployment, serving, and execution ID handling. The graph's internal logic stays intact.