Why Durable Execution?
Traditional agents run in-memory. If your process crashes during:- A long-running LLM call
- An external API request in a tool
- A multi-step conversation with many tool calls
- Checkpoint Every Step: Each LLM call and tool execution is automatically saved
- Automatic Recovery: After a crash, the agent resumes from the last checkpoint
- Exactly-Once Guarantees: Tool executions are never duplicated, even after retries
- Long-Running Workflows: Agents can run for hours or days without risk
Prerequisites
- Temporal Server: You need a running Temporal server. Follow the Temporal installation guide to set one up.
- Redis Server: Temporal agents require Redis for streaming support. Install and run Redis locally or use a hosted Redis service.
Creating a Durable Agent
To make an agent durable with Temporal, create a Temporal runtime withhastekit.NewTemporalRuntime and attach it to the agent with hastekit.WithRuntime:
Deployment Options
There are two ways to deploy durable agents:Option 1: Single Process (Development/Testing)
Run both the Temporal worker and the application code in the same process. This is simpler but less resilient since both components share the same process lifecycle.- The Temporal worker connects to the Temporal server at
0.0.0.0:7233 - Your application server runs on
http://localhost:8070 - Both are in the same process
Option 2: Separate Processes (Production)
For production deployments, run the Temporal worker and application in separate processes. This provides true fault isolation—if your application crashes, the Temporal worker continues running and can recover the workflow.Application Process
Temporal Worker Process
Running the Services
Starting the Temporal Server
If you don’t have a Temporal server running, you can start one locally using Docker:- gRPC endpoint:
localhost:7233(for workers and clients) - Web UI:
http://localhost:8233(for monitoring workflows)
Starting Redis
Redis is required for streaming support in Temporal agents:Example: Complete Durable Agent
See the complete working example in the repository:examples/agents/9_temporal_agent/main.go