Skip to main content

Overview

StateGraph provides comprehensive reliability features:
  • 🔄 Retry Policies - Automatic retry with exponential backoff
  • 💾 Cache Policies - Avoid re-executing expensive operations
  • 🛡️ Durability Modes - Control when state is persisted
  • 🔁 Failure Recovery - Resume from the last successful checkpoint

Retry Policies

Retry policies handle transient failures automatically.

Basic Retry

Retry Configuration

Selective Retry

Only retry specific exception types:
Retry on multiple exception types:

Custom Retry Logic

Use a function to determine whether to retry:

Cache Policies

Cache policies avoid re-executing expensive operations.

Basic Caching

Cache keys are automatically generated from the node’s input state. Same input = cache hit.

Cache Configuration

SQLite Cache for Persistence

Use SQLite cache to persist cached results across restarts:
Important: Always use check_same_thread=False when creating SQLite connections for StateGraph. This is required because the graph uses asyncio internally.

Combined Retry and Cache

Use both for maximum reliability and performance:
Order of Operations: Retry happens first, then successful results are cached.

Failure Recovery

Resume execution from the last successful checkpoint:

Best Practices

1. Retry Transient Failures Only

Don’t retry permanent failures:

2. Set Appropriate TTLs

Match cache TTL to data volatility:

3. Choose Right Durability

Match durability mode to workflow criticality:

4. Make Operations Idempotent

Ensure retried operations don’t cause side effects:

Next Steps