Multi-Agent Relay Collaboration: Architecture and Engineering Practices

    This article explains how to move from single-session AI coding tools to a multi-agent relay model, where specialized agents hand off work explicitly. It covers the core architecture of four roles and three collaboration channels, memory isolation with a shared capability library, state persistence and restart recovery, verifiable handoff protocols, observability and cost control, cloud hosting options, and a practical rollout sequence with common pitfalls.

    1. Background: From One-Shot Q&A to Persistent Relay

    Early AI coding tools mostly followed a “one session, one delivery” model: the user states a requirement, the model returns a result, and the context disappears when the session ends. This works well for single-file edits and snippet generation, but once a task spans multiple stages—requirement clarification, solution design, implementation, testing, and documentation—the context window and role boundaries of a single session quickly become bottlenecks.

    The industry has gradually converged on a different approach: split an “all-capable agent” into multiple persistent agents with narrow responsibilities, and complete the work through explicit handoffs. This idea is structurally close to service decomposition and pipeline orchestration in software engineering, and it pays off in three ways:

    • Controlled context: each agent keeps only the memory relevant to its own role, so unrelated information does not dilute its attention.
    • Auditable responsibility: every handoff point is a checkpoint, making it easier to locate which stage a problem came from.
    • Reusable capabilities: a shared capability library means new agents do not have to reimplement the same tool integrations.

    2. Core Architecture: Four Roles and Three Collaboration Channels

    A practical multi-agent relay system typically consists of four roles and three collaboration channels.

    The four roles:

    1. Orchestrator: understands the overall goal, decomposes tasks, assigns work, and accepts results. It does not do the heavy lifting itself.
    2. Worker: divided by responsibility, such as design-oriented, implementation-oriented, verification-oriented, and documentation-oriented, each with its own model configuration and memory space.
    3. Shared Room: a broadcast-style area for information sync, used to publish stage conclusions, risks, and blockers.
    4. Handoff: defines who passes what state to whom under which conditions, and is the key to whether the relay runs reliably.

    The three collaboration channels:

    • Instruction channel: the orchestrator sends structured tasks down to workers.
    • Broadcast channel: the shared room carries cross-role state sync, avoiding a point-to-point message explosion.
    • Handoff channel: an explicit @ mention triggers the transfer of responsibility, and the receiver must acknowledge.

    A sketch of the task description structure (pseudocode that only expresses field semantics):

    1. Task {
    2. id: string
    3. goal: string
    4. owner: agent_id // agent currently responsible
    5. inputs: [artifact_ref] // referenced artifacts, content is not copied
    6. acceptance: [check] // acceptance conditions that can be validated automatically
    7. next: agent_id | null // handoff target; null means terminal
    8. deadline: timestamp
    9. }

    The key design point here is “reference, not copy”: on handoff, pass an artifact reference (such as a path identifier in object storage) instead of stuffing large blocks of content into the message body. This significantly reduces context bloat and transfer cost.

    3. Memory and Capabilities: Isolation by Default, Sharing by Exception

    The part of a multi-agent system most likely to spiral out of control is memory. If all agents share one context, it looks convenient in the short term but inevitably leads to information pollution and blurred responsibility over time. A safer default strategy is:

    • Memory isolation: each agent maintains its own short-term session memory and long-term preference memory, with no crossing of boundaries.
    • Externalized artifacts: intermediate results are written to external storage, and agent memory keeps only indexes and summaries.
    • Shared capabilities: capabilities unrelated to any specific role—model access, tool adapters, skill wrappers—are consolidated into a shared capability library and referenced on demand.

    A shared capability library usually contains three kinds of content: descriptions of external system integrations, reusable skill wrappers, and a unified error and retry convention. Its value is that it strips integration cost away from each individual agent, so adding a new worker only requires declaring the list of capabilities it needs.

    4. State Persistence and Restart Recovery

    The robustness of relay collaboration depends on whether work can continue from the break point after an interruption. Engineering practice usually works on four levels:

    1. Externalized task state: tasks and handoff records are written to persistent storage, so a process restart does not affect the factual state.
    2. Idempotent handoff: repeated delivery of the same handoff event produces no duplicate side effects, relying on unique identifiers and a deduplication table.
    3. Checkpointing: a checkpoint is taken after each acceptance condition passes, and recovery resumes from the most recent checkpoint.
    4. Timeout and compensation: each stage gets a timeout; on timeout, fall back to the previous checkpoint or hand over to a standby agent.

    A simplified recovery decision logic:

    1. on_restart():
    2. tasks = load_persisted_tasks()
    3. for t in tasks where t.state != DONE:
    4. if t.acceptance.all_passed(): mark_done(t)
    5. elif t.retried >= MAX_RETRY: escalate(t) // escalate to the orchestrator or a human
    6. else: resume_from_last_checkpoint(t)

    The point worth stressing: recovery capability is not “remembering what was discussed last time” but “restoring to a verifiable consistent state.” The former depends on model memory and is unreliable; the latter depends on external facts and is auditable.

    5. Designing the Collaboration Protocol: Making Handoffs Verifiable

    The handoff is the “interface contract” of a multi-agent system. A mature handoff protocol should define at least:

    • Trigger conditions: which events allow a handoff to be initiated (acceptance passed, blocker timeout, capability mismatch).
    • Payload format: structured fields plus artifact references; free text must not carry key parameters.
    • Acknowledgment: the receiver must confirm explicitly; without confirmation, the handoff is treated as not having happened.
    • Conflict handling: priority and arbitration rules when the same task is claimed by multiple parties.
    • Termination conditions: a clear completion criterion and a failure escalation path.

    The practical recommendation is to write acceptance conditions as automatically executable checks (unit tests, static checks, format validation), so that “whether a handoff is allowed” is decided by machines rather than self-reported by the model. This is one of the most effective ways to reduce collaboration hallucinations.

    6. Observability and Cost Control

    A multi-agent system typically makes several times as many calls as a single agent, and without observability both cost and failures spiral out of control. Collect at least three categories of metrics:

    • Collaboration metrics: number of handoffs, average stage duration, rework rate, blocked time.
    • Quality metrics: first-pass acceptance rate, human intervention rate, where defects flow back to.
    • Cost metrics: call volume and resource consumption distribution per agent.

    For cost control, a “tiered model” strategy works well: use stronger model configurations for the orchestrator and complex reasoning stages, and lightweight configurations for formatting, extraction, and validation stages; at the same time, compress context length through externalized artifacts and summary indexes.

    7. Engineering Foundation: Built on General Cloud Capabilities

    To run such a system in production, you can combine general cloud capability categories: a container platform to host persistent agent processes and provide elastic scaling; object storage to hold task artifacts and checkpoints; a message queue to decouple handoff events and support redelivery and dead-letter handling; logging and monitoring with alerting for full-chain tracing and anomaly notification; and key management to centrally hold model access credentials. Baidu AI Cloud offers corresponding product forms in these general categories, which can each carry a separate responsibility boundary and avoid single-point coupling.

    8. Rollout Steps and Common Pitfalls

    Recommended rollout order:

    1. Define responsibilities and acceptance criteria first, before writing any agent logic.
    2. Get a single handoff loop working end to end, validating acknowledgment and idempotency.
    3. Introduce the shared capability library to eliminate duplicate integrations.
    4. Add persistence and restart recovery, and run fault-injection drills.
    5. Wire up observability and cost governance last.

    Common pitfalls include: handoff conditions that depend on the model’s subjective judgment; artifacts copied repeatedly inside message bodies; missing termination conditions that let tasks drift; and treating “memory” as the source of truth. The mitigation comes down to one sentence—make state verifiable, make handoffs acknowledged, and make failures recoverable.