CONTENTS
CHAPTER 8

Multi-agent systems and long-running agents

6 MIN READ

Once a single agent works, two pressures appear. Some tasks are too big for one context window, so you're tempted to split them across several agents. And some tasks take hours, so your agent has to survive crashes, deploys and waiting for humans. This chapter covers both, starting with the most public disagreement in the field.

The debate: should you build multi-agent systems?

In June 2025, within a day of each other, two respected teams published opposite-sounding advice.

Cognition, "Don't Build Multi-Agents" (Walden Yan). Cognition builds Devin, a coding agent. Their argument rests on two principles:

  1. "Share context, and share full agent traces, not just individual messages."
  2. "Actions carry implicit decisions, and conflicting decisions carry bad results."

Their example: split "build a Flappy Bird clone" between two sub-agents, one for the background and pipes, one for the bird. The first builds a background that looks like Super Mario Bros. The second builds a bird that doesn't look or move like Flappy Bird's. Each made reasonable choices in isolation; together they're incoherent, and a final agent is left to reconcile pieces that don't fit. Their recommendation: by default, use a single-threaded agent with a continuous context, and for very long tasks, compress history (which they admit is hard to do well).

Anthropic, "How we built our multi-agent research system" (Hadfield, Zhang and colleagues). Their Research feature uses an orchestrator-worker design: a lead agent plans, saves its plan to memory, and spawns sub-agents that search in parallel, each with its own context, then synthesizes their findings. On their internal research evaluation, a system with Claude Opus 4 as lead and Claude Sonnet 4 sub-agents outperformed single-agent Opus 4 by 90.2%. On the BrowseComp benchmark, three factors explained 95% of performance variance, and token usage alone explained 80%. Multi-agent systems win, in part, because they spend more tokens: agents used about 4× the tokens of chat, and the multi-agent system about 15×.

They're less opposed than they look. Anthropic's own post says multi-agent fits poorly in domains where agents need to share context or have many dependencies on each other, and names coding as one. Cognition notes that Claude Code's sub-agents work because they don't run in parallel with the main agent and usually just answer a well-defined question, which keeps exploration out of the main context.

Put together, the rule is:

Key insight: Split work across agents when the sub-tasks are independent reads (searching, investigating, summarizing different sources) that each return a compact answer. Keep work in one agent when the sub-tasks are interdependent writes (building parts of one artifact) where each choice constrains the others.

Research is breadth-first and read-heavy: perfect for parallel workers. Building software is a chain of interdependent decisions: keep it in one thread, and use sub-agents only to answer questions.

Designing an orchestrator-worker system

If your task fits, Anthropic's lessons are a practical checklist:

  • Brief sub-agents like colleagues. Each needs an objective, an output format, guidance on which tools and sources to use, and clear boundaries. Vague briefs ("research the semiconductor shortage") produced duplicated work and gaps.
  • Scale effort to the task. Put rules in the lead agent's prompt: a simple fact-finding question needs one agent and a few tool calls; a complex comparison needs several agents.
  • Start wide, then narrow. Short, broad queries first, then focus.
  • Parallelize. Running sub-agents and their tool calls in parallel cut research time by up to 90% for complex queries.
  • Return compact results. Workers send back condensed findings, not their whole transcript.
  • Account for cost. At roughly 15× the tokens of a chat, multi-agent systems only make sense for tasks valuable enough to pay for it.

Long-running agents need durable execution

A request-response API call lasts seconds. An agent may run for an hour, wait a day for a human approval, and make two hundred tool calls along the way. During that time your servers will deploy, crash, and scale. If the agent's state lives only in a process's memory, it dies with the process.

Anthropic's multi-agent post puts it bluntly: agents are stateful and errors compound, so you need to resume from where the error occurred rather than restart. They also describe rainbow deployments, gradually shifting traffic to new versions while old versions keep running, so a deploy doesn't break agents that are mid-task.

The solution is old: durable execution, the same idea behind workflow engines in distributed systems. Persist the agent's state after every step, so any worker can pick it up and continue. Several approaches exist:

  • Workflow engines like Temporal record an event history and replay it to rebuild state after a crash; model calls and tool calls run as retryable activities.
  • Agent frameworks with checkpointers, such as LangGraph's persistence layer, save state per thread and support resume, human-in-the-loop pauses and "time travel" to earlier states.
  • Your own table. Store the context and business state per run in a database after each step. With the stateless-reducer design from Chapter 7, this is a few dozen lines.

Concept deep dive: idempotency, or why "retry" is dangerous

Durable execution means retrying. Retrying means some steps will run twice. For reads that's fine. For writes it can be a disaster: a crash right after the refund API succeeded, but before you saved that fact, leads to a second refund on resume.

This is a classic distributed systems problem, and the classic solution is idempotency: designing operations so that doing them twice has the same effect as doing them once.

The standard technique is an idempotency key. Before executing a write, derive a unique key from the run and step (for example run_42:step_17:refund). Send it with the request. The receiving service records keys it has processed; if it sees the same key again, it returns the original result instead of acting again. Many payment APIs support exactly this.

def execute_write(run_id, step, call):
    key = f"{run_id}:{step}:{call.name}"
    if (done := results_store.get(key)) is not None:
        return done
    result = call.tool.execute(call.args, idempotency_key=key)
    results_store.put(key, result)
    return result

Two rules follow for agent design:

  1. Separate reads from writes in your tool design. Reads can retry freely. Writes need idempotency keys, confirmation, or both.
  2. Record intent before acting. Log "about to refund order 1234" before the call and "refunded" after. On resume, an intent without a result tells you to check the world before retrying.

None of this is specific to AI, which is the point. Agents are distributed systems with a non-deterministic component, and everything you know about distributed systems applies.

Harnesses for very long tasks

As agents took on multi-hour work (coding projects especially), builders found a context window can't hold the whole job no matter how well you compact it. The emerging answer is a harness: structure outside the model that carries the task across many context windows.

Anthropic's "Effective harnesses for long-running agents" (2025) describes one for coding. A first session sets up the environment: an init script, a progress file, a structured feature list and an initial commit. Each later session reads the progress file and git history, picks one feature, implements and tests it, commits, and updates the progress file. The model's memory is the repository.

The pattern generalizes:

  • Externalize the plan and progress into files or a database.
  • Work in small, verifiable increments, each ending in a checkpoint (a commit, a saved record).
  • Start each session by reading state, not by relying on a summary of a summary.

By 2026, practitioners increasingly called this work harness engineering. Mitchell Hashimoto describes a habit worth adopting: whenever an agent makes a mistake, engineer the harness (a tool, a check, an instruction in the project's agent file) so it can't make that mistake again. That's Chapter 1's point about verification, turned into a daily practice.

Key takeaways

  • Multi-agent systems help with independent, read-heavy, parallel work (research). They hurt with interdependent writes (building one artifact).
  • Multi-agent systems spend many more tokens (about 15× chat in Anthropic's measurement). Reserve them for high-value tasks.
  • Long-running agents need durable execution: persist state after every step and resume rather than restart.
  • Retries make writes dangerous. Use idempotency keys and record intent before acting.
  • For very long tasks, build a harness: externalized plans and progress, small verified increments.

Exercises

  1. Classify these as better for one agent or many, and explain: competitive analysis of ten companies; refactoring a module; triaging 500 support tickets; writing a novel chapter.
  2. Design the state schema for a durable support agent that can wait up to three days for a manager's approval.
  3. List the write tools in an agent you know of. For each, how would you make it idempotent?