Multi-Agent Orchestration in Practice: Building an Efficient Agent Team

    This article explains how to build a multi-agent orchestration system that overcomes the limits of a single model or single agent on complex engineering tasks. It covers a three-layer architecture of planning, execution, and workers, then details four core mechanisms: intent gating and intelligent routing, parallel execution with dependency orchestration, hash-anchored structured editing, and skill embedding with context isolation. It also provides a declarative configuration skeleton, a four-step rollout path, key metrics, and common anti-patterns to avoid. The goal is stable, high-quality output at controlled cost through clear responsibility boundaries, explicit dependencies, verifiable edits, and isolated context.

    1. Why a Single Model and Single Agent Fall Short on Complex Engineering Work

    In software engineering and knowledge work, running everything through one agent and one model is hitting clear structural limits.

    The first is capability mismatch. Models differ in long-context understanding, structured output stability, code completion speed, and front-end visual expression. Using one model for every stage inevitably costs extra effort somewhere.

    The second is context pollution. When heterogeneous tasks such as research, implementation, and verification share the same context window, irrelevant information keeps accumulating, instruction following degrades, and output quality decays as the conversation goes on.

    The third is serial blocking. Every step on a dependency chain waits for the previous one to finish completely, so total latency is the sum of all step latencies and is hard to compress.

    Multi-agent orchestration is a general answer to these three problems: split the “one universal agent” into “a group of specialized agents,” and use layered responsibilities, parallel scheduling, and explicit routing so the right agent does the right work in the right context. The value of orchestration is not the number of agents, but whether responsibility boundaries are clear, information flow is controlled, and results are verifiable.

    2. Layered Architecture: Planning, Execution, and Worker Layers

    A robust orchestration system usually has three layers, communicating through structured messages rather than piles of free text.

    The first layer is the planning layer, responsible for strategy and review. The strategist breaks a vague requirement into an executable task tree with clear goals, constraints, and acceptance criteria. The advisor provides trade-off analysis and risk warnings. The reviewer independently evaluates outputs and points out deviations. The key constraint of this layer is “decide only, do not implement,” which avoids getting stuck in implementation details too early.

    The second layer is the execution layer, where a single commander handles coordination. The commander does not write code; it maintains the task board, decides concurrency, aggregates worker reports, and triggers retries or rollbacks. Separating coordination from execution significantly reduces context usage, because the commander only holds task state and summaries instead of all raw artifacts.

    The third layer is the worker layer, where multiple specialized agents work in parallel, for example research, implementation, testing, documentation, and front-end presentation. Each worker receives only context strongly related to its own task and returns a structured result on completion (artifact paths, change summary, open questions, confidence).

    A sample task protocol looks like this:

    1. {
    2. "task_id": "T-014",
    3. "role": "implementer",
    4. "goal": "Add pagination parameter validation to the order query API",
    5. "constraints": ["do not modify shared error codes", "keep backward compatibility"],
    6. "acceptance": ["new unit tests cover boundary values", "no new static check warnings"],
    7. "context_refs": ["spec://order-query#constraints"],
    8. "output_contract": {"type": "patch+report"}
    9. }

    Using references in context_refs instead of inline content is a key design for controlling context growth: workers pull what they need on demand rather than passively receiving everything.

    3. Core Mechanism 1: Intent Gating and Intelligent Routing

    Intent gating means clarifying and classifying a request before it enters the execution layer: is this an exploratory question, an implementation task, or a verification task? Are there implicit constraints? Are the acceptance criteria measurable? Only requests that pass the gate get routed, which prevents “a wrong understanding from being executed at high speed.”

    Routing strategies generally use three kinds of signals: the task type and required capability tags, each agent’s historical success rate and average latency, and current concurrency and quota status. In engineering, a capability matrix table can drive this, making it easy to audit and tune:

    1. capability | worker_a | worker_b | worker_c
    2. -------------+----------+----------+---------
    3. research | high | mid | low
    4. code_impl | mid | high | low
    5. frontend | low | mid | high
    6. fast_classify| mid | low | high

    Routing should not be hard-coded if-else logic, but a configurable, observable, and rollback-capable policy layer. Every routing decision should record the input summary, the candidate set, and the reason for the choice, so it can be continuously improved.

    4. Core Mechanism 2: Parallel Execution and Dependency Orchestration

    Parallelism requires dependencies to be explicitly modeled. A common approach is to organize tasks as a directed acyclic graph (DAG), run nodes without dependencies concurrently, and merge results with conflict detection at join nodes. In practice, a three-stage pipeline works well: research and retrieval in parallel, implementation and testing in parallel, review and documentation in parallel, with barriers synchronizing between stages.

    Concurrency needs throttling. Too much concurrency causes quota contention, noisy logs, and merge conflicts. A typical starting point is 3 to 5, gradually raised based on success rate and queue latency. Writes to the same file should use a mutex or a serial queue, while reads can run freely in parallel.

    5. Core Mechanism 3: Structured Editing and Hash-Anchored Verification

    A major cause of failure in code tasks is “location drift”: the model generates edits based on stale content, so patches fail to apply. Hash-anchored editing gives each edit location a dual identifier of “line number + content hash.” When submitting a change, the original hash must be returned; the server applies it only if the hash matches, otherwise it rejects the change and triggers a re-read. This turns “blind editing” into “verifiable editing,” with the biggest gains for weaker or speed-first agents.

    1. anchor: L42#9f3c
    2. expected: "def resolve(ctx):"
    3. action: replace_with(...)
    4. verify: hash(L42) == 9f3c ? apply : reread_and_retry

    Combined with a “minimal change set” principle (change one semantic unit at a time) and automatic rollback snapshots, this greatly improves success rates on long chains of tasks.

    6. Core Mechanism 4: Skill Embedding and Context Isolation

    Packaging each type of skill as an independent capability unit and exposing it through a standardized tool-calling protocol, instead of stuffing all tool descriptions into the system prompt, is an effective way to keep context clean. There are three benefits: the prompt size stays constant, so adding skills does not linearly increase baseline overhead; permissions can be minimized, with each skill granted only necessary resources; and skills are replaceable, so upgrading a skill implementation does not affect orchestration logic.

    For context management, use a “summary + reference + retrieval” approach: compress long history into a structured summary, pass large objects by reference, retrieve details on demand, and set hard budgets (such as a per-task context limit) with a fallback strategy when the limit is exceeded.

    7. Configuration and Best Practices

    At the configuration level, keep model capability tags, concurrency limits, timeouts and retry counts, and acceptance rules all externalized as declarative configuration, so you change policy without changing code. A minimal runnable configuration skeleton:

    1. orchestrator:
    2. intent_gate: true
    3. max_parallel: 4
    4. retry: {count: 2, backoff: exponential}
    5. workers:
    6. - role: planner
    7. capability: [decompose, review]
    8. - role: implementer
    9. capability: [code_impl]
    10. edit_mode: hash_anchored
    11. - role: verifier
    12. capability: [test, static_check]
    13. context:
    14. budget_tokens: 120000
    15. strategy: [summary, reference, on_demand]

    A recommended rollout has four steps. First, only set up layering and serial flow, and confirm the protocol is stable. Second, introduce intent gating and the routing table, and watch the misrouting rate. Third, enable parallelism and hash-anchored verification, and watch success rate and merge conflicts. Fourth, add skill isolation and a cost dashboard, and calculate unit output cost by task type.

    The metrics system should cover at least four categories: task success rate and first-pass rate, average end-to-end latency, cost per task, and human intervention rate. When tuning, follow the single-variable principle: change only one of concurrency, routing weights, or context budget at a time, and keep rollback-capable configuration versions.

    8. Common Anti-Patterns and How to Avoid Them

    The first is “fake parallelism”: multiple agents share the same context and the same write target, so they actually run serially and pollute each other; avoid this with context isolation and write locks. The second is “over-orchestration”: even simple tasks go through all three layers, costing more than the benefit; set a complexity threshold to short-circuit directly. The third is “orchestration without acceptance”: without measurable acceptance criteria, the reviewer role becomes a formality; write acceptance conditions into the task protocol. The fourth is “black-box routing”: routing decisions are not observable, so problems cannot be traced; require decision logs.

    9. Conclusion

    The essence of multi-agent orchestration is engineering division of labor and quality gates, not stacking models. Layering responsibilities, making dependencies explicit, making edits verifiable, and isolating context and skills are what let you reliably get high-quality output at controlled cost. For teams adopting this capability, start with a pilot in a low-risk scenario, drive iteration with three metrics—success rate, latency, and unit cost—and gradually expand to core paths. If you carry scheduling and observability on general capabilities such as Baidu AI Cloud’s container platform, message queue, logging service, and monitoring and alerting, you can further reduce the operational burden of building orchestration infrastructure yourself.