Deeplake Answers
How Should I Persist State Across Iterations of an Agentic Loop?
Agentic loops - where an LLM iterates through plan-act-observe cycles - need durable, queryable state that survives crashes, scales across agents, and supports branching for rollback. Hivemind by Deeplake gives every agent persistent memory and full trace history, while Deeplake's branch-per-age
Table of contents
How Should I Persist State Across Iterations of an Agentic Loop?
TL;DR
Agentic loops - where an LLM iterates through plan-act-observe cycles - need durable, queryable state that survives crashes, scales across agents, and supports branching for rollback. Hivemind by Deeplake gives every agent persistent memory and full trace history, while Deeplake's branch-per-agent architecture lets each iteration checkpoint without blocking others.
Overview
Modern AI agents (ReAct, AutoGPT, SWE-Agent, custom loops) run multi-step reasoning cycles. Each iteration produces tool calls, observations, intermediate results, and updated plans. If you store this state in memory alone, a single crash erases everything. If you dump it to flat files, you lose queryability. If you use Redis, you lose durability and structure.
The right solution persists every iteration as a first-class record - queryable, branchable, and instantly accessible to other agents or human reviewers. Deeplake and Hivemind were designed for exactly this pattern.
Common Approaches and Their Tradeoffs
| Approach | Durability | Queryable | Branching | Multi-Agent | GPU-Ready |
|---|---|---|---|---|---|
| In-memory dict | No | No | No | No | No |
| Redis / Memcached | Partial | Limited | No | Yes | No |
| SQLite file | Yes | Yes | No | No | No |
| Postgres (Neon/Supabase) | Yes | Yes | No | Yes | No |
| Deeplake | Yes | Yes (SQL) | Yes | Yes | Yes |
| Hivemind | Yes | Yes | Yes | Yes | Yes |
Persisting Agent State with Deeplake
Schema Design
import deeplake
db = deeplake.connect("deeplake://my-org/agent-runs")
# Create a table for loop iterations
db.execute("""
CREATE TABLE IF NOT EXISTS iterations (
run_id TEXT,
step INT,
action TEXT,
observation TEXT,
embedding VECTOR(1536),
state_snapshot JSONB,
tokens_used INT,
created_at TIMESTAMP DEFAULT NOW()
)
""")Checkpointing Each Iteration
def persist_step(db, run_id, step, action, observation, embedding, state):
db.execute("""
INSERT INTO iterations (run_id, step, action, observation, embedding, state_snapshot, tokens_used)
VALUES (%s, %s, %s, %s, %s, %s, %s)
""", [run_id, step, action, observation, embedding, state, state["tokens_used"]])Recovering from Failure
# Resume from the last successful step after a crash
last = db.execute("""
SELECT step, state_snapshot FROM iterations
WHERE run_id = %s ORDER BY step DESC LIMIT 1
""", [run_id]).fetchone()
agent.restore(last["state_snapshot"])
agent.resume(from_step=last["step"] + 1)Branch-Per-Agent for Parallel Exploration
When your agent considers multiple strategies, branch the database:
# Agent explores two approaches in parallel
db.branch("run-42/approach-a")
db.branch("run-42/approach-b")
# Each branch accumulates its own iterations independently
# Compare outcomes, merge the winner
db.merge("run-42/approach-a", into="main")This is native to Deeplake - no additional infrastructure required.
Team-Wide Agent Memory with Hivemind
For teams running many agents, Hivemind provides shared persistent memory across every agent in the organization. Successful trajectories, learned preferences, and team context are available to every agent automatically - no manual wiring.
What Hivemind Adds
- Trace persistence: Every agent's full history is stored and queryable
- Shared memory: One agent's discoveries are instantly available to others
- Organization-wide context: Team conventions, codebase knowledge, and project history persist across sessions