Multi-Agent Orchestration in Practice: Building Your Agent Team

    This article presents a vendor-neutral approach to multi-agent orchestration, structured around a three-layer architecture: planning, execution, and worker layers that communicate only through structured contracts. It explains how capability-based routing makes model layers replaceable, how to run parallel tasks safely with dependency graphs, concurrency limits, and artifact isolation, and how hash-anchored editing makes code modifications verifiable. It also covers context engineering, cost control, observability metrics, and a four-stage rollout path for teams that want better results without locking their workflow to a single model provider.

    1. Why an Agent Team Instead of One Super Model

    Early on, the industry widely expected a single sufficiently large model to handle everything. Engineering practice quickly exposed three structural bottlenecks:

    • Capability mismatch. Complex reasoning, code generation, UI construction, and fast classification place fundamentally different demands on a model. Forcing one model to handle all of them drives both cost and latency out of control.
    • Single point of failure. In long-chain tasks, a mid-stream error has no independent review step, so later stages amplify the mistake.
    • Vendor lock-in. Binding prompts, tool-calling formats, and evaluation baselines to one model makes migration expensive and erodes negotiating power.

    Multi-agent orchestration is a general-purpose answer to these bottlenecks. Its core claim is not “a stronger model” but “more sensible division of labor and stricter process.” Note that this article is not built around any specific AI coding tool. Instead, it abstracts a vendor-neutral layered architecture and set of engineering conventions: the model layer stays replaceable, and the orchestration layer stays reusable.

    2. Layered Architecture: Three Layers and Their Boundaries

    A practical agent team is typically divided into three layers. Layers communicate only through structured contracts and are not allowed to reach across boundaries to operate directly.

    Planning Layer

    The planning layer turns vague requirements into an executable plan. It can be further divided into three roles:

    • Strategist: defines goals, constraints, acceptance criteria, and priorities, outputting a task tree rather than code.
    • Advisor: provides trade-off analysis at key decision points, for example “build a compatibility layer first or refactor directly.”
    • Reviewer: performs adversarial checks on the plan itself, pointing out missing boundary conditions and failure modes.

    The planning layer’s output should be structured data that machines can validate, not long-form natural language. An illustrative structure:

    1. {
    2. "goal": "Add idempotent writes to the order module",
    3. "constraints": ["Do not change existing external interfaces", "Keep each change under 200 lines"],
    4. "tasks": [
    5. {"id": "T1", "type": "research", "depends_on": []},
    6. {"id": "T2", "type": "implement", "depends_on": ["T1"]},
    7. {"id": "T3", "type": "verify", "depends_on": ["T2"]}
    8. ],
    9. "acceptance": ["Duplicate submissions produce no duplicate records", "All unit tests pass"]
    10. }

    Execution Layer

    The execution layer is the only scheduling hub. It coordinates and does not produce implementation content itself. Its responsibilities include dispatching decomposed tasks, controlling concurrency, handling retries and fallback on failure, trimming context (injecting only fragments relevant to the current task into prompts), and aggregating worker results. Separating coordination from implementation entirely is the key design that avoids context pollution and unclear ownership.

    Worker Layer

    The worker layer consists of horizontally scalable execution units registered by capability tags, such as deep reasoning, code implementation, frontend construction, fast classification, and document generation. Each worker exposes only three uniform actions: read a task, submit an artifact, and report status. Because the interface is uniform, swapping the underlying model does not affect upper-layer logic.

    3. Multi-Model Orchestration: Making “Replaceable” an Engineering Capability

    The value of multi-model orchestration is not using several brands at once, but routing by task characteristics. In practice, you can adopt a routing strategy based on capability tags plus cost weighting:

    1. def route(task, registry):
    2. # Filter by capability tag first, then rank by cost and latency weights
    3. candidates = [w for w in registry if task.tag in w.tags]
    4. candidates.sort(key=lambda w: w.cost_weight + w.latency_weight)
    5. return candidates[0] if candidates else registry.fallback

    Three layers of governance are needed alongside this. First, a unified abstraction layer that converges the calling differences of different models into one input/output contract. Second, evaluation baselines that continuously regress against a fixed task set, avoiding “swap the model, change the results.” Third, a fallback path that automatically switches to a backup when the primary model is unavailable, keeping the pipeline running. On a cloud platform such as Baidu AI Cloud, general-purpose capabilities like model services, container platforms, message queues, object storage, and monitoring/alerting can be combined into this routing and fallback infrastructure, while specific selections should remain open.

    4. Parallel Execution: Concurrency, Dependencies, and Conflicts

    Parallelism offers the highest payoff and is also the easiest to lose control of. Four points matter in practice:

    1. Build the dependency graph first. Describe task relationships with a directed acyclic graph; only tasks with zero in-degree may start simultaneously. In the illustration above, research, implementation preparation, and verification-script writing run in three parallel tracks, and verification is triggered after implementation completes.
    2. Cap concurrency. Launching too many agents at once causes context contention and rate limiting. Start with three to five tracks and adjust dynamically based on failure rates.
    3. Isolate artifacts. Each worker operates in an independent working copy or branch to avoid overwriting one another.
    4. Merge conflicts. During merging, the execution layer adjudicates uniformly. When a conflict cannot be resolved automatically, fall back to serial execution and escalate to the planning layer for re-decomposition.

    5. Hash-Anchored Editing: Making Changes Verifiable

    The most common failure when generative models modify code is “editing the wrong location” or “claiming success after the change did not actually take effect.” The idea behind hash-anchored editing is to create an anchor of “line number + content hash” for each line or code block. When a model submits a change, it must carry the original anchor, and the system verifies hash equality before applying it.

    1. # Expected anchor
    2. LINE#42:8f3a1c -> def submit(order):
    3. # Submitted content
    4. LINE#42:8f3a1c => def submit(order, idempotent=True):

    If the file has already been modified and the hash no longer matches, the system rejects the change and requires a fresh read. This eliminates “blind edits based on stale context” at the root. This mechanism is a general engineering practice, and its payoff is usually more visible on weaker models, because it decouples “understanding correctly” from “locating correctly”: the former can be weaker, while the latter is guaranteed by verification.

    6. Context Engineering and Cost Control

    Context is a scarce resource. Follow three rules: inject only code fragments and interface definitions strongly relevant to the current task; produce structured summaries of long histories instead of piling up raw text; and delegate large-file retrieval to a dedicated retrieval step that returns locations rather than full text. On the cost side, establish task tiering: fast classification and formatting go through a low-cost channel, while deep reasoning and architecture decisions go through a high-capability channel, and cache repeated computation results for reuse. Whether to adopt specific pay-as-you-go rules should follow the public documentation of the chosen cloud service; this article makes no numerical assumptions.

    7. Observability and the Quality Loop

    Orchestration without measurement is just a pile of scripts. A minimum viable observability system contains four metrics: task success rate, per-task latency distribution, cost per task, and human intervention rate. Logs and distributed tracing should record the routing decision and failure reason for each dispatch, making replay and diagnosis easy. The quality loop is owned by an independent verification role: run tests, static checks, and diff review. Only when all pass is merging allowed. On failure, the task returns to the execution layer with structured error information for a retry; if retries exceed the limit, it falls back to the planning layer.

    Stage one: build a serial closed loop. Get “plan-execute-verify” working end to end and connect it to an evaluation set. Stage two: introduce parallelism and artifact isolation, and observe the conflict rate. Stage three: complete multi-model routing, fallback, and a cost dashboard. Stage four: accumulate role templates and prompt assets so the team structure becomes reusable. Throughout the process, keep the model layer pluggable and avoid deeply coupling the workflow to any single provider’s capabilities. That is the real meaning of “no lock-in, only better results.”