A Four-Layer Architecture for Pluggable AI Coding Agents

    This article breaks down the four-layer architecture of pluggable AI coding agents, or code harnesses, where context assembly, model access, tool registration, and permission policies are all replaceable units. It explains each layer—context management, tool orchestration with permission boundaries, the verification loop, and extension governance with observability—along with practical engineering guidance for building controllable, auditable coding agents on cloud platforms such as Baidu AI Cloud.

    When a new class of AI coding tools arrives with the philosophy that “plugins are everything,” many developers’ first reaction is to dismiss it as a reskinned version of an established product. That judgment hides the change that actually matters: every component of the toolchain—context assembly, model access, tool registration, permission policies, and verification workflows—becomes a replaceable unit. Replaceability means customizability, but it also means stability is no longer guaranteed by the vendor and must be designed by the user. Setting aside specific product features, this article discusses the general architecture and engineering practices of these pluggable coding agents (code harnesses), so you can build controllable, auditable coding agents on cloud platforms such as Baidu AI Cloud.

    From a Closed Pipeline to Pluggable Assembly

    Traditional AI coding tools typically use a closed design: the model, context window, toolset, and execution policies are fixed by the vendor, and users can only tune parameters or swap prompts. The advantage of such tools is stability; the drawback is a clear ceiling—you cannot inject domain-specific workflows, nor combine different models into a more suitable agent.

    A pluggable architecture abstracts these components into interfaces and assembles them through registration. The payoff is extreme flexibility; the cost is increased complexity: a single misconfigured component can make an agent “start rewriting things incorrectly as it runs.” The prerequisite for mastering such tools is not memorizing new terminology, but two capabilities: first, domain knowledge, so you know which business scenario to customize for; second, an overall understanding of the agent workflow, so you know how tool calls, result checks, and abnormal termination form a closed loop.

    Layer 1: Context Management

    Context management determines what the agent “sees.” Key design points include:

    • Admission policy: which files enter the prompt should be decided jointly by directory conventions, the dependency graph, and the scope of changes, rather than stuffing everything in.
    • Compression and summarization: when conversation history exceeds a threshold, summarize it in segments, keeping decisions and constraints while discarding redundant trial and error.
    • Re-read mechanism: when a summary and the source code may be inconsistent, force a re-read of key files to avoid modifying based on stale information.

    Illustrative logic:

    1. def build_context(task, repo):
    2. files = select_by_dependency(task.entry, repo, max_files=20)
    3. history = summarize_if_over(task.history, token_budget=8000)
    4. if history.stale vs repo.head():
    5. files += reread(task.touched_files)
    6. return assemble(files, history, task.constraints)

    Without this layer, the most common problem with an agent is not that it “cannot write code,” but that it “confidently edits the wrong files within the wrong context.”

    Layer 2: Tool Orchestration and Permission Boundaries

    More tools is not better; clearer boundaries are. Reading files, modifying files, executing commands, calling external capabilities, and requesting user authorization should be classified by risk:

    • Read-only: allowed by default, with audit logs recorded.
    • Write: restricted to a path allowlist and an upper limit on the scale of changes.
    • Execution: run in an isolated sandbox with network and resource limits.
    • Authorization: high-risk operations require explicit confirmation, with confirmation granularity down to the specific action.

    An agent that is handed permissions carelessly is more dangerous than one that cannot use tools. Engineering practice recommends managing permissions as code, so that permission changes can be reviewed and rolled back.

    Layer 3: The Verification Loop

    A genuinely useful coding agent does not “finish once the code is written”; it forms a loop: run tests, static checks, and type checks, feed the errors back to the model, and then decide whether to continue fixing or stop and ask. The key design is the termination condition: set a maximum number of iterations, a repetition threshold for the same type of error, and rollback points to avoid infinite loops that consume resources.

    1. while not passed and rounds < max_rounds:
    2. result = run(tests, lint, typecheck)
    3. if result.repeated_error > threshold:
    4. ask_human(result)
    5. break
    6. patch = model.fix(result)
    7. apply(patch)

    Layer 4: Extension Governance and Observability

    When plugins become first-class citizens, governance must keep pace: define versions and compatibility policies for plugins, retain a traceable call chain for each run, connect logs, metrics, and alerts to common cloud logging services and monitoring and alerting capabilities, and accumulate failure samples as regression test cases. If multiple models are combined, model selection should be treated as a configurable policy, with budget guardrails set for cost and latency.

    Implementation Recommendations

    Start with a narrow scenario, such as “fixing failing unit tests in a specified directory,” and fill in the four layers step by step: first context admission, then permission classification, then the verification loop, and finally governance and observability. Running and auditing this pluggable system on general capabilities provided by Baidu AI Cloud, such as container platforms, object storage, logging, and monitoring, can make it both flexible and controllable. The value of flexibility lies not in “being able to change anything,” but in clearly knowing the impact of each change and being able to stop, roll back, and review at any time.