Skip to content
Multi-agent collaboration: topology, communication, and termination

Multi-agent collaboration: first prove a single agent is insufficient, then split

I once built a textbook case of over-engineering. I split “read the requirement → search the code → write the implementation → run the tests” into four Agents, each with its own prompt, wired together through a group-chat-style message bus where they shouted at each other.

Once it was running, the test Agent took the implementation Agent’s third draft and tested it, while the implementation Agent changed it back based on another message. The two went back and forth for seven rounds, and nobody could say which version was current. The same requirement, with a single Agent plus four tools, was done in half an hour.

After that, my default attitude toward multi-Agent became one sentence: first prove a single Agent isn’t enough, then split.

Post 14/15 of this series · Previous: Reading, Writing and Forgetting in Agent Memory Systems · Next: After Launch: Observability, Cost and Guardrails

There are only four countable reasons to split

Context isolation is the one I consider most defensible. If a subtask needs to read tens of thousands of tokens of source code or logs, mixing that with the main task’s decision context easily pushes key constraints out of the window. Let the sub-Agent read on its own and return only structured conclusions, and the main Agent’s side stays clean.

Permission isolation solves a different class of problem: an Agent that searches public libraries and an Agent that performs write operations should not share the same set of tool permissions. Confining high-privilege actions to one tightly constrained Agent noticeably shrinks the blast radius of injection attacks (covered in post 15).

Role specialization and parallelism are, at bottom, a cost argument. Subtasks that don’t depend on each other can run concurrently, each with a different model tier and prompt: a strong model for planning, a small model for extraction, plain code for format conversion. The overall cost structure ends up far more sensible than “one strong model does everything.”

The last one is often overlooked: independent evaluation and iteration. When a subtask’s failure rate is clearly high, only after splitting it out can you build a separate eval set, swap models separately, and roll out separately.

Conversely, “the architecture looks cleaner,” “let the models discuss their way to a better answer,” and “easier to extend later” are not reasons. The first often doesn’t hold—the message flow after splitting is usually messier; the second is mostly just several Agents reinforcing the same mistake; the third trades future benefit for present cost, which doesn’t pay off.

Here’s a practical test: if, after writing the communication contract between the multiple Agents clearly, you find it’s really just “the main Agent calling a few tools,” then don’t split. The bulk of multi-Agent cost isn’t in model calls, it’s in state consistency.

flowchart LR
  A[想拆成多个 Agent] --> B{上下文装不下}
  B -- 是 --> OK[拆分成立]
  B -- 否 --> C{权限必须隔离}
  C -- 是 --> OK
  C -- 否 --> D{子任务可并行且档位不同}
  D -- 是 --> OK
  D -- 否 --> E{需要独立评测与灰度}
  E -- 是 --> OK
  E -- 否 --> NO[别拆 主 Agent 调工具就够]

Four topologies

Supervisor (central orchestration) is my default choice. A main Agent handles decomposition, dispatch, and aggregation; sub-Agents are stateless and just take tasks and return results. This is almost isomorphic to the planning layer in post 2—the only difference is that the execution unit changes from a tool to an Agent. It’s the most stable and the easiest to debug. The cost is that the main Agent becomes a bottleneck: as sub-results keep coming back, its own context grows longer and longer.

Hierarchical means a supervisor under a supervisor, suited to tasks with a natural hierarchy—by module, by region, by batch. The more layers, the more information gets compressed at each level, and raw evidence easily gets lost along the way. I limit it to two layers and require every level’s summary to carry traceable artifact_id.

Pipeline / serial means A’s output feeds directly into B as input, in a fixed order with no loops. It has the best controllability and predictable latency, suited to work with clear stages like “extract → validate → generate → review.” The downside is no rollback: if something earlier is wrong, everything after is skewed, so you need an explicit quality gate between every two stages.

Group chat / blackboard means multiple Agents write messages into the same shared space, where anyone can read and anyone can respond. It’s the most flexible and the easiest to lose control of: nondeterministic message order, unclear versions, mutual overwrites, endless discussion. I’ve only used it in exploratory, offline scenarios where human intervention is allowed, never on a user-facing path. If you must use it, make the blackboard an append-only event log rather than an overwritable shared variable.

Topology Consistency Parallelism Debuggability Suited for
Supervisor High Medium High Most production scenarios
Hierarchical Medium High Medium Large-scale divide and conquer
Pipeline High Low High Batch processing with fixed stages
Group chat / blackboard Low High Low Offline exploration, needs human arbitration

Communication contract: messages are not natural language

The root cause of the opening case wasn’t that the model was bad—it was that the messages had no concept of version. Now I define inter-Agent communication as structured records, and pass only artifact handles, not large blocks of text:

JSON13 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
{
"msg_id": "m_0187",
"task_id": "t_8f31",
"from": "impl",
"to": "supervisor",
"in_reply_to": "m_0162",
"artifact": {"id": "art_44", "uri": "store://t_8f31/impl/v3", "schema": "patch_v1"},
"based_on": {"artifact_id": "art_41", "version": 2},
"status": "done",
"checks": [{"name": "tests_pass", "value": true}],
"confidence": 0.86,
"budget_used": {"tokens": 9200, "seconds": 34}
}

A few fields were added specifically to prevent pitfalls.

based_on declares which version this artifact is based on. When the test Agent is testing art_41/v2 and the implementation Agent has already produced art_44/v3, the supervisor can immediately determine the result is stale, without expecting the model to “explain clearly” in conversation.

schema forces artifacts to be structured and verifiable. The done_when from post 2 now becomes the acceptance criterion across Agents: artifacts that don’t match the schema are rejected outright—don’t make downstream Agents guess what a piece of free text means.

checks compresses judgment into a boolean. Having one Agent evaluate another Agent’s output in natural language as “good quality” is the starting point of most mutually reinforcing errors.

in_reply_to and msg_id build the causal chain and are also the basis for cross-Agent tracing (post 15).

Messages or shared state? My choice: short instructions and results go through messages, long-lived facts go through shared state—but shared state must carry a version and a writer. The expected_version optimistic locking from post 13 applies here just the same. Never allow two Agents to directly overwrite the same field; all writes go through a validating state.apply(patch, expected_version), and conflicts are merged explicitly.

One more discipline: sub-Agents don’t look directly at the main Agent’s full conversation history. The context given to them contains only the task description, necessary constraints, and the artifacts they themselves need. Context isolation is the whole point of splitting—stuffing in the full history is as good as not splitting at all.

Termination conditions: where multi-Agent most easily loses control

A single agent with a step limit is basically sufficient. Multi-agent systems introduce three additional classes of non-convergence: mutual waiting (deadlock), back-and-forth negation (oscillation), and continuous generation of new tasks (task inflation). Therefore, termination conditions must be defined at the system level and cannot be left to any individual agent to judge.

PYTHON18 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def supervise(task, budget):
state = SharedState(task, version=0)
for round_no in range(budget.max_rounds):
pending = plan_next(state) # 返回可并发的子任务
if not pending:
return finish(state)
results = run_parallel(pending, timeout=budget.round_timeout)
for r in results:
if not r.valid or r.based_on.version != state.version:
state.mark_stale(r) # 过期结果不写回
continue
state.apply(r.patch, expected_version=state.version)
state.version += 1
if state.unchanged(lookback=2): # 连续两轮无有效状态变化
return halt(state, reason="plateau")
if budget.exhausted() or state.conflict_unresolved():
return halt(state, reason="budget_or_conflict", need_human=True)
return halt(state, reason="round_limit", need_human=True)

All four criteria are indispensable:

  • Round limit (I usually set 3–6 rounds) and a global budget, the latter covering total tokens, total wall-clock time, and total cost;
  • Plateau detection: stop when the shared state shows no substantive change for N consecutive rounds — this is the most effective measure against oscillation;
  • Convergence criterion: express “done” as a boolean check over required_fields, rather than letting some agent declare itself finished;
  • Conflict escalation: when two agents reach mutually exclusive conclusions and arbitration cannot decide either, stop and hand it to a human — don’t let them keep discussing. Model debates lacking external evidence often just reinforce each other’s initial bias.

The need_human=True exit must actually exist. I’ve seen plenty of systems that “theoretically hand off to a human,” but after halt they simply return the text that most resembles a conclusion — effectively automating away the fallback.

Cost: four agents cost more than 4x

Multi-agent cost is not linear. Roughly, total cost equals the sum over agents of rounds × per-round context tokens, plus coordination overhead, plus duplicated work.

One commonly underestimated item is that every sub-agent carries its own copy of system instructions, tool definitions, and constraint descriptions — four agents means four fixed overheads. Add to that the supervisor re-reading sub-results every round, and the same material may be encoded three or four times.

The control measures are the same as in article 3: trim tool sets by role; assign different model tiers to different agents — strong models for planning, small models or even pure code for extraction and format validation; pass handles rather than full text between agents; cache results for high-frequency subtasks.

For observability, cross-agent traces must be linkable via task_id + msg_id into a causal graph that can at least answer: which agent, in which round, based on which version, did what, produced what, and who consumed it. Without this graph, debugging multi-agent systems basically means reading chat logs — and chat logs are the least trustworthy source, since they don’t record which version was in effect.

Benefits, costs, and my current default

On the benefits side: isolating long materials keeps the main decision context cleaner; permissions can be narrowed by role; independent subtasks can run in parallel and use different model tiers; subtasks can be evaluated and rolled out separately; failures are confined to one branch instead of requiring a full rerun.

On the cost side: state consistency becomes a first-class problem — versions, staleness, and concurrent writes all become your responsibility; coordination overhead and duplicate encoding can double costs; failure modes multiply, especially oscillation and task inflation; debugging difficulty spikes; end-to-end latency is determined by the slowest branch, with an obvious long tail.

So when not to split: few steps, context fits, subtasks are tightly coupled and need frequent back-and-forth adjustment, strict latency budget, and the team lacks a stable trace and evaluation system. My experience: without cross-agent tracing, don’t go multi-agent — you won’t even be able to reproduce problems.

One intermediate form deserves separate mention: not multiple agents, but a single agent switching between multiple sets of “role configuration + tool set + independent context window,” explicitly scheduled by code. It captures most of the benefits of context isolation and permission isolation without the consistency burden of shared state and message protocols. Most of the requirements I once wanted to split into multi-agent ended up settling in this form.

With this installment, the series has covered single agents, RAG pipelines, fusion architectures, and memory and collaboration. What remains is what happens after they go into production: how to know it’s quietly getting worse, how to keep cost and latency within budget, and what to do when retrieved external content itself carries malicious instructions. Back to the stuck point at the beginning: in your current collaboration workflow, can you tell at a glance which version of an artifact a given conclusion was based on?

About this Post

This post is written by Lu's Blog, licensed under CC BY-NC 4.0.

#Agent #Architecture #Multi-Agent

Comments