Skip to main content
Durable agent execution ensures that your agents can survive process crashes, restarts, or failures without losing progress. Using Temporal, each step of the agent’s execution (LLM calls, tool executions) is checkpointed, allowing the agent to resume from exactly where it left off after a failure.

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
…all progress is lost, and the entire execution must restart from scratch. With durable execution:
  • 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

  1. Temporal Server: You need a running Temporal server. Follow the Temporal installation guide to set one up.
  2. 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 with hastekit.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.
With this setup:
  • 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
Note: If this process crashes, both components restart together. True durability requires separation (Option 2).

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

Important: Both processes must register the agent with the exact same name and configuration. This ensures the Temporal worker can execute the agent with the correct setup.

Running the Services

Starting the Temporal Server

If you don’t have a Temporal server running, you can start one locally using Docker:
The Temporal server will be available at:
  • 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

Learn More