Documentation
¶
Overview ¶
Example: durable_llm_graph — where LLM calls happen, and how the StateGraph runtime makes them durable.
What you'll learn:
- LLM calls happen INSIDE graph nodes (the runtime itself is LLM-agnostic).
- The runner checkpoints state after every node that completes.
- When a later node fails (a crash, a transient provider/network error, a process restart), Resume continues from the last checkpoint — so a completed, EXPENSIVE LLM node is never re-executed.
The graph is a 3-step content pipeline:
draft (LLM) ──▶ review (LLM) ──▶ finalize
We deliberately make `review` fail on its first attempt to simulate a crash after `draft` has already done its expensive LLM work. On Resume, `draft` is skipped (its output was checkpointed) and execution picks up at `review`.
This example uses a deterministic stub Provider so it runs offline and in CI with no API keys. Swap it for a real provider (OpenAI/Anthropic/Gemini/Ollama) and the graph code does not change — that is the whole point of the model.Provider interface. See examples/graph_with_llm for a real-provider version.
Run:
go run ./examples/durable_llm_graph/