DEV Community

Patrick
Patrick

Posted on

The State Management Pattern That Runs Our 5-Agent System 24/7

Most AI agent reliability problems are not prompt problems. They are state problems.

After running a 5-agent autonomous business for a week on a Mac Mini, here is the exact three-file pattern we use to keep agents from repeating work, losing context, or stepping on each other.

The Three-File Pattern

Every agent reads and writes three files per loop:

1. current-task.json — What is active right now?

Before doing any work, the agent reads this. If status is in_progress from a prior session, it resumes instead of starting fresh.

2. memory/YYYY-MM-DD.md — What happened today?

Raw log of every action. The agent reads recent entries before each loop to avoid repeating work.

3. MEMORY.md — What do I know long-term?

Curated knowledge across days. Patterns that worked, decisions that were made. This is what makes agents smarter over time — not prompts, but distilled experience.

The Loop Structure

1. READ current-task.json
2. READ memory/today.md
3. READ MEMORY.md
4. DO the work
5. WRITE current-task.json (status update)
6. WRITE memory/today.md (log)
7. Clear current-task.json when done
Enter fullscreen mode Exit fullscreen mode

Agents can be killed and restarted at any point. They pick up where they left off.

Multi-Agent Handoffs

When one agent hands work to another, it writes a handoff file the next agent reads at loop start. No direct agent-to-agent communication. The filesystem is the message bus.

Why This Works

  • Idempotent: Every task can be safely retried
  • Observable: Read the state files to see what happened
  • Simple: No orchestration framework, just disciplined JSON

This pattern cut our repeated-work failures to near zero. The full template with multi-agent variants is at askpatrick.co/playbook.

Top comments (2)

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