Skip to main content

Checkpoints & Rollbacks

StateBase gives your AI agents a superpower that humans don’t have: the ability to undo mistakes. This is the core of StateBase’s reliability guarantee.

The Problem: Non-Deterministic Failures

AI agents fail in unpredictable ways:
With StateBase: You can roll back to Turn 5 and try again with a different prompt or model.

How It Works: Automatic State Versioning

Every time you update a session’s state, StateBase creates an immutable snapshot:
Each version is stored in the database with:
  • Version number (auto-incrementing)
  • State snapshot (full JSON)
  • Timestamp (when it was created)
  • Reasoning (why this change was made)
  • Trace ID (which operation triggered it)

Rollback: Undo to a Previous Version

If your agent makes a mistake, you can revert to any previous state version:

What Happens During Rollback?

  1. StateBase retrieves the state snapshot from version 3
  2. Creates a new version (e.g., version 6) with the restored state
  3. Returns the restored state to your agent
  4. Preserves history: Versions 4 and 5 are still in the database for audit
Key Insight: Rollbacks are non-destructive. You can always see what went wrong by inspecting the corrupted versions.

Checkpoint Strategies

Not every state change needs to be checkpointed. Here are common strategies:

Strategy 1: Checkpoint After Tool Calls

Why: Tool calls are expensive and may fail. Checkpointing lets you retry without re-calling the API.

Strategy 2: Checkpoint After User Confirmation

Why: User confirmations are critical decision points. You want to be able to roll back to “just before confirmation” if something goes wrong.

Strategy 3: Checkpoint Before Risky Operations

Why: Destructive operations should always have a checkpoint immediately before.

Automatic Checkpointing

StateBase automatically creates checkpoints in these scenarios:

Controlling Turn-Based Checkpointing

By default, add_turn() does not create a checkpoint unless you explicitly update state:
Why: Most turns don’t change state (e.g., small talk). Checkpointing every turn would be wasteful.

Recovery Patterns

Pattern 1: Retry with Different Prompt

Pattern 2: Fallback to Human

Pattern 3: A/B Testing Recovery


Forking: Branching Conversations

Sometimes you don’t want to replace the current state—you want to explore an alternative timeline. That’s where forking comes in.

What is Forking?

Forking creates a new session that starts from a specific version of an existing session:

When to Fork vs Rollback

Example: Debugging in Production


Cost vs Safety Trade-offs

Checkpointing has a cost (storage + API calls). Here’s how to balance safety and efficiency:

High-Frequency Checkpointing (Paranoid Mode)

Use when: Handling financial transactions, medical data, or compliance-critical workflows.
Use when: Most production agents (customer support, personal assistants, etc.)

Low-Frequency Checkpointing (Optimized)

Use when: High-volume, low-risk agents (chatbots, FAQ assistants)

Monitoring Rollback Frequency

If you’re rolling back frequently, it’s a sign your agent needs improvement:
Healthy rollback rate: < 2%
Warning threshold: 5%
Critical threshold: 10%

Best Practices

✅ Do This

  • Checkpoint before risky operations (deletions, payments, API calls)
  • Include reasoning in every checkpoint (helps with debugging)
  • Use forking for debugging (don’t modify production sessions)
  • Monitor rollback frequency (it’s a health metric)

❌ Avoid This

  • Don’t checkpoint every turn (wasteful unless state actually changes)
  • Don’t roll back without understanding why (you’ll repeat the same mistake)
  • Don’t delete checkpoint history (it’s your audit trail)

Next Steps


Key Takeaway: Checkpoints are your time machine. Use them strategically to make your agents resilient to LLM non-determinism.