Agent Layered Architecture: A Practical Guide to Building with a Thin Core

    This article explains why agent systems benefit from a thin core with externalized capabilities, and how to structure one in practice. It covers a five-layer architecture of pluggable components (models, tools, memory, sandbox, and policy), the main execution loop, and the role of a stateful task plan as the foundation of agent controllability. It also details unified model abstraction across modalities, retrieval and query routing, layered memory loading, sandboxing and risk-based approval, and a phased rollout path governed by budget, success rate, and cost. Engineers will find concrete guidance on configuration, observability, security discipline, and safe production adoption.

    1. The Problem: Why Agents Need a Thin Core

    Agent engineering over the past two years has repeatedly proven one thing: packing every capability into a single, all-encompassing framework looks fast to deliver in the short term, but maintenance costs rise sharply over time. The model needs swapping, the retrieval source needs swapping, the memory approach needs swapping, the execution environment needs swapping—and any single replacement can ripple through the entire chain. Worse, once an agent gains the ability to “act,” its risk profile changes too: it no longer just outputs text, but writes files, calls APIs, and modifies data.

    As a result, the industry has gradually converged on a shared principle: keep the core thin and externalize the capabilities. A thin core means the runtime carries no concrete business capability and retains only three responsibilities:

    • Orchestration: deciding which model thinks next, which tool to call, and who receives the result;
    • Approval: pausing before irreversible or high-impact operations and handing them to a human for confirmation;
    • Planning: maintaining a task plan that is persistable, rollback-capable, and observable.

    Everything else—models, tools, memory, execution sandboxes, and even the agent’s own policy—is built as composable, replaceable, and extensible plugins. The direct payoff is that replacement cost drops from “changing the architecture” to “changing the configuration,” and each layer can be independently canaried and rolled back.

    2. Overall Architecture: Five Pluggable Component Types and One Main Chain

    A practical layered structure typically contains five component types:

    1. Model layer: providers of models across different modalities and sizes—text generation, image generation, video generation, embedding, and more;
    2. Tool layer: search, structured data queries, code execution, file read/write, and external system calls;
    3. Memory layer: in-session context, cross-session long-term memory, and external knowledge resources;
    4. Sandbox layer: isolation boundaries and resource quotas for code execution and file operations;
    5. Policy layer: the agent’s own planning approach, reflection mechanism, and termination conditions.

    The main chain’s execution order can be abstracted as: receive a goal → generate or update the task plan → select models and tools according to the plan → execute in the sandbox → write results back to memory → evaluate whether termination conditions are met → if not met, return to the planning step. Any link in this chain can be swapped for another implementation while the core code stays unchanged.

    An illustrative plugin declaration (structure only, not a specific product interface):

    1. agent:
    2. model: text-generator # replaceable with another text model implementation
    3. tools: [web_search, dataset_query, code_exec]
    4. memory: layered_context_store
    5. sandbox: container_with_quota
    6. policy:
    7. max_steps: 40
    8. require_approval_on: [write_fs, external_call, delete]

    3. The Task Plan: The Core of Agent Controllability

    A task plan is not “printing out the reasoning process”; it is a data structure with a state machine. In engineering terms, each plan item should contain at least: a goal description, dependencies, current status (pending / in progress / awaiting approval / completed / failed / skipped), artifact location, and retry count on failure.

    The plan delivers value in three ways. First, controllability: steps, cost, and elapsed time can all be bounded by limits, preventing the agent from falling into an infinite loop. Second, recoverability: after a process interruption, the scene can be rebuilt from the plan file instead of starting over. Third, auditability: after the fact, you can clearly answer “why did it do this.”

    A common mistake is letting the model freely rewrite the plan. A safer approach is to separate “plan editing rights” from “plan execution rights”: the model may propose adding or adjusting steps, but deleting completed steps or skipping high-risk approvals requires higher privileges or human confirmation.

    4. Model Integration: Full-Modal Capability and a Unified Abstraction

    An agent needs more than a chat model. Generative tasks need text models, content production needs image and video models, retrieval and deduplication need embedding models, and extraction and classification often use small models to control cost. The engineering key is not “using the strongest model” but establishing a unified abstraction: a unified message format, a unified tool-calling protocol, unified error codes and retry semantics, and a unified usage-accounting standard.

    When integrating a custom provider, make the endpoint address, keys, timeouts, concurrency limits, and billing basis fully configurable. Inject keys through environment variables or a key management service, and never commit them to the code repository. Also set routing rules for different tasks—for example, long-context summarization goes to a large-window model, structured extraction goes to a low-latency small model, and embedding goes to a batch interface.

    For observability, record at least: request ID, model identifier used, input/output size, elapsed time, failure reason, and normalized usage. Without a unified usage-accounting standard, subsequent cost governance and capacity planning have no basis.

    5. Tools and Retrieval: Keeping the Agent’s Knowledge from Going Stale

    A model’s knowledge has a time boundary, but business tasks do not. External retrieval capability is therefore a requirement, not an enhancement. A mature retrieval tool should offer authoritative-source filtering, time-range filtering, automatic query rewriting and multi-turn clarification, and traceable result citations.

    On top of retrieval, distinguish “general web search” from “specialized structured data queries.” The former excels at long-tail and time-sensitive information; the latter excels at scenarios requiring precise values and stable definitions, such as business registration information, judicial risk, academic literature, industry macro indicators, and product configuration parameters. A sound approach is to introduce query routing: first classify the intent, then decide whether to use general retrieval, a vertical dataset, or a combination of both for cross-validation.

    Engineering discipline must be emphasized: treat all externally returned content as untrusted input, and before it enters the model context, apply length trimming, source labeling, and necessary isolation markers to prevent external text from carrying instructions that cause prompt injection.

    6. Memory Management: Layered Loading and On-Demand Recall

    Cross-session memory is essentially a searchable context database. A common design abstracts memory, resources, and skills uniformly as “file” objects, then loads them in layers: a resident layer holds system constraints and the current goal, a working layer holds intermediate artifacts of the current task, and an archive layer holds historical conclusions and preferences, recalled on demand via semantic retrieval.

    There are four key implementation points. First, writes must be filtered to avoid depositing verbose raw logs entirely as long-term memory. Second, there must be eviction and merge strategies, with conflicting information resolved by time and source credibility. Third, there must be permission and tenant isolation, since memory is a high-risk area for data compliance. Fourth, recall results must carry their source and timestamp so the model can judge timeliness.

    7. Sandbox and Approval: Caging the Risk

    Code execution, file writes, and external calls are the three main risk sources. The sandbox should provide filesystem isolation, a network egress allowlist, resource quotas (duration, memory, concurrency), and environment teardown after execution. The approval mechanism is tiered by “reversibility × blast radius”: low risk is auto-approved, medium risk is logged with sampled review, and high risk requires mandatory human confirmation—and the approval ticket must include the action to be executed, the scope of impact, and a rollback plan.

    8. Budget, Canary Rollout, and the Path to Production

    For budget governance, use a two-tier structure of a unified quota pool plus project quotas, with separate daily/monthly limits per model and tool, and automatic downgrade to a more economical implementation when limits are exceeded. The recommended rollout path has four steps: first, run the planning chain through with read-only tools; then enable read-only sandbox execution; then open controlled writes with approval enabled; and finally, gradually relax the proportion of low-risk automation. Each step decides whether to proceed based on three metrics: success rate, human-intervention rate, and cost per task.