When autonomous coding agents (like Devin) or legal research agents (like Harvey AI) attempt complex problem solving, they frequently explore multiple candidate hypotheses.
1. Why Agents Need State Branching
If an agent tests a candidate code refactor directly against production memory and the approach fails, the bad assumptions remain polluting the memory store. Developers were forced to implement manual database rollbacks or state snapshots.
2. How ClawDB Memory Branching Works
ClawDB introduces Git-Style State Branching for AI memory:
- Fork Branch: Create an isolated branch from
main(e.g.clawdb branch create trial-path-2). - Isolated Execution: Write candidate memory entries with 0 side effects on production.
- Merge or Discard: If the candidate trail succeeds, execute a
fast-forwardmerge back tomain. If it fails, delete the branch.
3. Code Example: Creating & Merging Memory Branches
import { ClawDB } from '@clawdb/sdk';
const claw = new ClawDB({ apiKey: process.env.CLAWDB_API_KEY });
// 1. Fork production memory into a trial branch
const trial = await claw.branches.create({
name: 'candidate_refactor_v2',
parentBranch: 'main',
});
// 2. Perform candidate operations on the branch
await claw.memory.add({
branch: 'candidate_refactor_v2',
namespace: 'code_ast',
content: 'Trial refactor: Switched REST handlers to gRPC streaming',
});
// 3. Candidate trial succeeded! Merge branch into main
await claw.branches.merge({
sourceBranch: 'candidate_refactor_v2',
targetBranch: 'main',
strategy: 'fast-forward',
});