Architecture Design and Practice for Multi-Agent Coding Tools

    This article explains how to move AI coding tools beyond single-turn chat toward an orchestrated system. It covers a unified scheduling layer that abstracts heterogeneous capabilities behind one interface, an adapter layer that normalizes raw output into structured events, a supervisor and sub-agent collaboration model, workspace isolation with version-controlled worktrees, skill templates and external tool integration, observability and data tracking, and recommended runtime environments. Readers will also find a suggested architecture evolution order to avoid costly refactoring later.

    1. Background: From Single-Point Chat to Engineering-Grade Collaboration

    Early AI coding tools were mostly built around single-turn conversation or single-file completion. Developers had to manually copy context, switch between windows, and repeatedly explain the project structure. Once tasks grew to cross-module refactoring, batch bug fixing, or continuous integration maintenance, the limits of a single-session model became obvious quickly: a finite context window, long tasks that break midway, multiple tasks interfering with each other, and execution processes that cannot be observed.

    The engineering answer is to treat AI coding as an orchestrated system rather than a chat window. The core goals come down to four points: multiple capability sources can be integrated through one interface, multiple execution agents can collaborate, the execution process is observable and traceable, and workspaces do not contaminate each other. The following sections build on these four goals layer by layer.

    2. Unified Scheduling Layer: Abstracting Heterogeneous Capabilities Behind One Interface

    The first step in integrating multiple capabilities is defining a stable abstraction boundary. The scheduling layer (which can be understood as the role of a BridgeManager class) is responsible for registering, discovering, starting and stopping, and routing different capability providers. It exposes unified semantics upward and hides differences downward. Key design points include:

    • Registration and discovery: capability providers register as adapters, carrying metadata such as name, available commands or paths, default model, parameter templates, and environment variables.
    • Routing strategy: select the execution agent based on task type, cost constraints, context length, whether network access is required, and other dimensions.
    • Lifecycle management: probe availability before startup, enforce timeout and cancellation control while running, and reclaim child processes and temporary resources afterward.
    • Configuration persistence: provider configurations are stored in a database, supporting enable/disable, command overrides, and parameter adjustments, so environment differences are not hard-coded into business logic.

    It is worth stressing that built-in adapter configurations are only default templates and do not mean the runtime already has the corresponding executables and login state. If the local machine lacks a given command or has not completed authentication, the interface can still open normally, but the corresponding capability cannot actually execute tasks. A capability self-check at startup is therefore a necessary step.

    A sample adapter registration structure:

    1. ProviderDescriptor {
    2. id, displayName, kind("cli" | "sdk" | "http"),
    3. executablePath, argsTemplate, env,
    4. defaultModel, capabilities(["chat","edit","exec","vision"]),
    5. healthCheck()
    6. }

    3. Adapter Layer: Turning Uncontrolled Output into Structured Events

    Different execution agents produce very different output forms: some emit plain text streams, some emit marked incremental blocks, and some emit structured messages. If the upper layer consumes raw output directly, the UI and business logic become tightly coupled. The adapter layer’s job is to normalize any output into a unified event model, for example:

    • Lifecycle events: session creation, heartbeat, completion, and errors.
    • Content events: text deltas, reasoning summaries, and code block boundaries.
    • Tool events: command execution, file reads and writes, retrieval calls, and their result states.
    • Metric events: input and output size, elapsed time, and retry counts.

    A unified event stream brings two direct benefits: the UI can render the “activity stream” and the “message stream” with the same logic, and auditing and statistics can reuse the same data offline. In practice, it is advisable to define a version number and schema validation for events so that adapter upgrades do not break downstream parsing.

    4. Multi-Agent Collaboration: The Supervisor and Sub-Agent Model

    Complex tasks are best decomposed. The Supervisor handles goal breakdown, task assignment, result merging, and conflict resolution, while each Sub Agent takes on the smallest task unit it can complete independently. Key implementation points:

    1. Task decomposition granularity must be verifiable, and every subtask should have clear inputs, outputs, and acceptance criteria.
    2. Session relationships need to be persisted, forming a tree or graph of task lineage so it is easy to trace “who changed what under which context.”
    3. The merge stage must include conflict detection, especially when the same file is modified by multiple subtasks.
    4. Failures need a convergence strategy: retry limits, fallback paths, and human intervention points.

    Persisted relationship data usually includes hierarchies such as tasks, workflows, missions (long-term goals), and teams (role orchestration), so a large cross-session refactoring can be advanced in segments without losing context.

    5. Workspace Isolation: A Prerequisite for Parallel Development

    The biggest risk in parallel execution is mutual overwriting caused by a shared workspace. Independent worktrees based on version control (the worktree approach) can give each subtask its own directory and branch for file-level isolation; after a task finishes, changes are merged or discarded based on review results. The following practices improve the outcome:

    • Bind each task to its own branch naming convention and lifecycle marker.
    • Automatically aggregate change sets into a reviewable diff list.
    • Run a unified static check and test baseline before merging to reduce cases that “look done but actually break the build.”

    6. Extension Mechanisms: Skill Templates and External Tool Integration

    The Skill system turns reusable prompt templates, variable placeholders, and output constraints into assets, so similar tasks do not require repeating the background. The design should support variable injection, compatibility adaptation per capability provider, and two scopes at the project level and the user level.

    External tool integration is typically done through a standardized Model Context Protocol (MCP)-style mechanism, mounting capabilities such as retrieval, browser debugging, and process control as services. Note that external services should all go through a unified permission and audit channel to avoid scripts accessing sensitive paths arbitrarily.

    7. Observability and Data Tracking

    A trustworthy automated development environment must be explainable. At minimum, record session state transitions, sub-agent lifecycles, file change details, command execution records, and resource usage statistics. On the visualization side, provide an activity timeline and a history search panel, which significantly reduces troubleshooting cost. Logs and metrics can be stored in a local database with export capability reserved, making it easier to connect to an enterprise’s unified logging service and monitoring and alerting system.

    8. Runtime Environment and Implementation Advice

    The recommended baseline environment is a recent desktop operating system, a supported long-term maintenance runtime (such as Node.js 20 or 22), a package manager, and version control tools. If distribution is via an installer, the required external commands must still be installed and authenticated locally, otherwise the related capabilities are unavailable.

    From an architecture evolution perspective, it is recommended to proceed in the order of “first unify the event model, then build adapters, and finally add orchestration and isolation.” Skipping event standardization and going straight to multi-agent orchestration often leads to high refactoring costs later. In this kind of engineering practice, Baidu AI Cloud typically provides general infrastructure categories such as container platforms, object storage, logging services, and monitoring and alerting, which can serve as a general foundation for hosting such a toolchain.