Agent Architecture: A Practical Guide to Layered Design with a Thin Core and Rich Plugins

    This article explains why layered decoupling is essential for building reliable AI agents, using the principle Agent = Model + Harness. It defines a reference architecture across model, orchestration, tool, memory, execution, and governance layers, then walks through a minimal working skeleton, model abstraction, tool side-effect declarations, tiered memory, sandboxing and approval, layered evaluation, a four-step rollout path, and common anti-patterns to avoid.

    1. Why Agent Engineering Needs a Thin Core and Rich Plugins

    Most agent projects over the past two years have gone through the same phase: start by stuffing requirements into one large prompt, attach every interface you can think of as a tool, and eventually discover that behavior is unstable, costs are uncontrollable, and actions cannot be audited. The root cause is not model capability but architecture. When orchestration logic, tool implementations, memory strategy, and the execution environment are all coupled inside a single process, any change in one place triggers a global regression.

    The industry is converging on layered decoupling, which can be summarized by a simple equation:

    1. Agent = Model + Harness

    The Model handles reasoning and generation, while the Harness (the “carrying and constraining layer”) grounds the model’s capabilities in real tasks. An ideal Harness core should be extremely thin, keeping only three irreducible responsibilities:

    1. Orchestration: decide which model and which tool to call at each step, and write the result back into the context;
    2. Approval: pause before irreversible or high-risk operations and wait for human confirmation;
    3. Planning: maintain an explicit, readable, and persistable task plan instead of scattering planning across the conversation history.

    Everything else—model integration, retrieval, memory, execution sandbox, role orchestration—should be built as plugins. This brings three direct benefits: low replacement cost (swap models without changing business code), contained failure domains (a sandbox crash does not affect orchestration), and auditability (every approval and plan change is recorded).

    2. Reference Layered Architecture and Responsibility Boundaries

    A practical layered structure typically looks like this:

    Layer Responsibility Key Design Points
    Model layer Reasoning, generation, multimodal, embedding Unified abstraction interface that hides vendor differences
    Orchestration layer Step sequencing, context assembly, retries and rate limiting Extremely thin core with no business semantics
    Tool layer Retrieval, computation, business API calls Parameterized schemas, declared side-effect levels
    Memory layer Short-term context, long-term knowledge, vector recall Separate reads and writes, with expiration and eviction
    Execution layer Running code/commands in an isolated environment Resource limits, network policies, snapshot rollback
    Governance layer Approval, audit, budget, observability Mandatory human confirmation for high-risk actions

    Boundary discipline must be emphasized: the orchestration layer should not know the business meaning of any tool, the tool layer should not write directly to the memory store, and the execution layer should not hold credentials beyond what the task requires. Once boundaries blur, pluginization degrades into a formality.

    3. Getting Started and a Minimal Viable Skeleton

    A minimal viable version needs no complex dependencies—just a host process and a plugin manifest. The following is illustrative code (structure only, not a specific product interface):

    1. # Pseudocode: the three actions of an extremely thin core
    2. plan = planner.load_or_create(task_id) # 1. Maintain the plan
    3. step = plan.next()
    4. result = runtime.dispatch(step, model=model, tools=tools) # 2. Orchestrate model and tools
    5. if result.requires_approval:
    6. human.ask(result.preview) # 3. Approve before high-risk actions
    7. plan.commit(step, result)

    When implementing, make the “plan” a first-class citizen first: each step should have a unique ID, an input summary, an output summary, and a status (pending / running / pending approval / completed / rolled back). Once the plan is visualized, debugging costs drop significantly, because most cases of “an agent going off track” are actually a mismatch between the plan and real progress.

    4. Model Layer: Abstracting the “Brain” into a Replaceable Slot

    Production environments rarely use only one model. A reasonable goal is to give the model layer four capabilities, exposed through a unified interface:

    • Text generation: primary reasoning and tool selection;
    • Image and video generation: assets and demo outputs;
    • Embedding: semantic representations for retrieval and memory;
    • Fallback and degradation: automatic switching when the primary model is rate-limited or times out.

    For integration, use a “custom provider + unified key management” pattern: declare the base URL, key reference, model alias, and timeout policy in configuration, and let business code depend only on aliases. For needs like these, Baidu AI Cloud typically relies on a unified model service and access credential system, combined with general-purpose capabilities such as object storage, message queues, logging, and monitoring/alerting, to handle key hosting, asynchronous tasks, and full-chain observability.

    1. models:
    2. primary: { alias: reasoner, timeout_ms: 8000, retries: 2 }
    3. fallback: { alias: reasoner-lite }
    4. embedding: { alias: embedder, batch: 32 }

    5. Tools and Memory: Hands, Feet, and the Hippocampus

    The first principle of tool design is “declarable side effects.” Each tool is tagged read_only or mutating at registration, and the orchestration layer uses this to decide whether to force approval, rather than relying on the prompt’s self-discipline.

    1. {
    2. "name": "query_order",
    3. "side_effect": "read_only",
    4. "schema": {"order_id": "string"},
    5. "timeout_ms": 3000
    6. }

    Memory should be split into three tiers: session short-term memory (current task context, reclaimed when the plan ends), task mid-term memory (structured intermediate artifacts, persisted for recovery), and long-term knowledge (document chunks and vector indexes, supporting permission filtering and expiration eviction). The key to retrieval quality is not “recall more” but “recall more accurately”: setting a reasonable chunk size, mixing keyword and semantic retrieval, and reranking results with threshold truncation are usually more cost-effective than switching to a larger model.

    6. Sandbox and Approval: Caging the Risk

    The execution layer handles high-risk actions such as running code, processing files, and batch changes, and must have: resource limits (CPU, memory, duration), a network allowlist, read-only mounts by default, and operation snapshots with one-click rollback. The approval step should present a “readable change preview” rather than raw instructions—for example, showing the scope of affected resources and the estimated scale, so a person can decide whether to allow or reject within three seconds. All approvals and execution results are written to an audit log, forming a traceable closed loop.

    7. Evaluation, Budget, and the Rollout Path

    After pluginization, evaluation must also be layered: the model layer looks at task success rate and hallucination rate, the tool layer at parameter correctness and timeout rate, the memory layer at recall hit rate, and the execution layer at rollback rate. For budget governance, do quota aggregation and limit alerting centrally in the governance layer to avoid a single task running out of control and amplifying costs.

    The recommended rollout concludes in four steps: first, get planning and orchestration working with read-only tools; then introduce sandbox execution for low-risk actions; next, add long-term memory and retrieval reranking; finally, enable multi-model fallback and budget alerts. Keep a switch at every step so it can be rolled out gradually and rolled back.

    8. Common Anti-Patterns

    • Writing approval logic into the prompt instead of the core;
    • Letting the number of tools balloon without side-effect annotations, making them uncontrollable;
    • Using conversation history as the plan, which distorts once the task gets long;
    • Memory that is only written and never evicted, so retrieval noise keeps amplifying;
    • Hardcoding a single model, so the whole chain blocks when it is rate-limited.

    By sticking to “thin core, rich plugins, strong governance,” an agent system can evolve from a demo into a sustainable production system.