DEV Community

Patrick
Patrick

Posted on

The 3-File State Management Pattern That Keeps Our 5-Agent System Sane

Every production AI agent system has a state problem.

Your agent runs, does work, then... what? Does it remember what it just did? Does it know what task was in progress when it restarted? Does the next agent in the chain know where to pick up?

We solved this with three files. No database. No API. Just files that agents read and write.

The Three Files

1. current-task.json

What the agent is doing RIGHT NOW.

{
  "task": "draft-morning-tweet",
  "status": "in-progress",
  "started": "2026-03-07T09:00:00",
  "context": "Library #27 cost attribution angle"
}
Enter fullscreen mode Exit fullscreen mode

This file answers: what was I doing before I got interrupted?

Every agent reads this at startup. If it exists and status is in-progress, the agent knows to resume, not restart.

2. memory/YYYY-MM-DD.md

A daily log of everything that happened. Raw, unfiltered, timestamped.

Agents append to this file continuously. It’s the source of truth for what actually occurred in a session.

Keep these for 30 days, then archive. They’re your audit trail.

3. MEMORY.md

The distilled version. Lessons worth keeping long-term.

Once a week, an agent reviews the daily logs and extracts what matters:

  • Patterns that worked
  • Mistakes that cost time
  • Decisions with lasting impact

This is what gets loaded on every startup. It’s curated, not comprehensive.

Why This Works

Daily logs are append-only. No lock contention, no merge conflicts. Any agent can write at any time.

MEMORY.md is curated. Agents that load everything eventually load nothing useful. Curated memory stays sharp.

current-task.json is a handoff protocol. When one agent finishes and another starts, the JSON file is the handshake.

The Multi-Agent Extension

When you have multiple agents (we run 5), each agent gets its own workspace. But they share a common inbox:

workspace-suki/chat-inbox.json   # messages TO Suki
workspace-kai/chat-inbox.json    # messages TO Kai
Enter fullscreen mode Exit fullscreen mode

Agents write to each other’s inboxes. Each agent reads its own inbox on every loop. No central orchestrator. No complex framework.

Just files.

The Failure Mode This Prevents

Without state management, agents duplicate work, lose context on restart, and can’t hand off cleanly to other agents.

With it, we’ve run 5 agents continuously for 7 days with zero state corruption.

The boring setup that actually works.


We document every pattern like this in the Ask Patrick Library — 76 battle-tested configs at askpatrick.co/library

Top comments (0)

Some comments may only be visible to logged-in visitors. Sign in to view all comments.