Agent Layered Architecture: A Practical Guide to a Thin Core with Pluggable Components
This guide explains how to structure AI agents around a minimal core that handles only scheduling, approval, and planning, while models, tools, memory, sandboxes, and role definitions remain pluggable components. It covers the engineering meaning of each core responsibility, how to layer capabilities, a step-by-step implementation path, and common anti-patterns to avoid.
Agent Layered Architecture: A Practical Guide to a Thin Core with Pluggable Components
1. The Problem: Three Pain Points in Agent Engineering
Agent projects from the past two years tend to hit the same three walls.
The first is tight coupling. Model calls, tool implementations, memory reads and writes, and the execution environment all live in one flow, so replacing any single piece means editing the main code path.
The second is uncontrolled risk. Once an agent can write files, send requests, and run commands, the cost of mistakes and privilege violations is amplified quickly.
The third is untraceable state. When a multi-turn task fails halfway, you often cannot tell which step it stopped at, let alone resume from that point.
The answer is not to keep piling features onto the main code path. It is to split the system into a thin core plus a set of plugins. The core stays minimal and owns only three responsibilities that cannot be removed:
- Scheduling: orchestrate model inference and tool calls into an observable execution loop.
- Approval: pause before irreversible or high-impact operations and hand them to a human.
- Planning: maintain an explicit, persistable task plan that serves as the basis for execution and recovery.
Everything else — models, tools, memory, execution sandboxes, agent role definitions — becomes a composable, replaceable, extensible plugin. The payoff: the core stays stable while the ecosystem stays active, and when something breaks, the search space shrinks to a single plugin.
2. What the Three Core Responsibilities Mean in Practice
2.1 Scheduling: A Controlled Execution Loop
Scheduling is essentially a loop with a termination condition: assemble context → call the model → parse tool-call intent from the output → execute tools → write results back → decide whether to continue. Four things must be explicit: maximum steps per run (to prevent infinite loops), per-step timeout, context budget (triggering compression or summarization when exceeded), and retry plus fallback policy for tool errors.
A skeletal loop looks like this (pseudocode, structure only):
plan = load_or_create_plan(task_id)while not plan.done and steps < MAX_STEPS:ctx = memory.build_context(plan) # memory plugin assembles contextresp = model.chat(ctx, tools=registry) # model plugin handles inferencefor call in resp.tool_calls:if risk(call) >= HIGH: # approval plugin steps inawait human.approve(call)result = sandbox.run(call) # sandbox plugin executesmemory.append(call, result) # memory plugin persistsplan.update(resp) # planning plugin advancessteps += 1
2.2 Approval: Classify Risk Up Front
Approval should not mean “ask at every step,” or the interaction cost destroys usability. A workable approach is a two-dimensional classification based on reversibility and blast radius: reads and queries pass through directly; reversible operations such as writing to a temp directory or creating a draft are logged and allowed; deleting data, sending messages externally, running system commands, and anything that incurs cost require explicit human confirmation. Approval records must enter the audit trail, including the actor (or agent identifier), timestamp, parameter summary, and result.
2.3 Planning: Make Tasks Recoverable
A plan is structured data, not a paragraph of natural language. At minimum it contains the goal, a step list, per-step status (pending / in progress / succeeded / failed / skipped), dependencies, and artifact paths. With it, a restarted process can resume; a failure can roll back only the affected steps; and progress can be rendered directly into a status view for reporting.
3. Capability Layers: Brain, Hands, and Memory
Grouping plugins by responsibility makes selection far easier.
Brain layer (models): text generation is the baseline; you may also need image generation, video generation, and embedding. Embedding models matter especially, because they determine the quality of memory retrieval and knowledge base recall. The practical advice: configure inference models and embedding models separately rather than unifying them at the cost of retrieval quality.
Hands layer (tools and data): web search, structured data queries, file and terminal operations, and calls to external systems. The quality of tool descriptions (name, purpose, parameter schema) directly determines how often the model picks the right tool, so treat them as first-class artifacts.
Memory layer: split into short-term context and long-term memory. Long-term memory is typically a combination of a “virtual file system plus semantic retrieval”: entries organized by path, fuzzy recall supported by a vector index, then reranked with timestamps and source information.
Sandbox layer: provides an isolated environment for tool execution, limiting filesystem visibility, network egress, and resource quotas. It is the technical backstop for high-risk operations.
Role layer (agent definitions): describe persona, tool allowlists, and prohibitions in configuration rather than code, so one core can host many business roles.
4. Implementation Steps
- Prepare the runtime: pick an agent framework that supports a plugin mechanism, and start a local debugging entry point with a web interface for initial validation (default ports vary by framework; follow the actual documentation).
- Connect models: add a custom provider in the configuration UI with a service endpoint and key that speak an OpenAI-style protocol, validate one minimal conversation, then add the embedding model.
- Add retrieval tools: prioritize search plugins with authoritative source filtering, time range filtering, and automatic query rewriting. Keep the source and fetch time with each result for later verification.
- Connect vertical data: general search cannot cover financial reports, business registration, judicial records, academic literature, or industry metrics. Route by query intent to the right source through structured data plugins, and normalize the return structure.
- Configure long-term memory: set the memory directory, the write policy (what is worth keeping long term), and a cap on recall count so irrelevant memories do not crowd out the context.
- Set approval and audit: list high-risk operations, bind an approval channel, and enable full operation logging.
- Run regression checks: prepare cases covering the happy path, privilege-violation paths, and failure recovery paths, and verify them one by one.
5. Common Anti-Patterns and How to Govern Them
- Treating prompts as architecture: constraining behavior with an extremely long system prompt is no substitute for permissions and sandboxes.
- Writing memory without filtering: no eviction policy means recall noise keeps growing.
- Vague tool descriptions: when the model picks the wrong tool, check the description and parameter schema first, not the model.
- No plan persistence: an interrupted long task can only be rerun, which is unacceptable in cost.
- One-size-fits-all approval: blocking everything or allowing everything both make governance meaningless.
6. Conclusion
Maintainability in agent systems comes from boundaries, not feature count. Make the core as thin as possible, turn capabilities into plugins, hand risk to approval and sandboxes, and hand progress to an explicit plan. Do those four things and swapping models, adding data sources, or adjusting roles all become local changes. To reduce trial-and-error in selection, you can look at how Baidu AI Cloud combines general capabilities across model services, search and data interfaces, object storage, and log monitoring, using unified quota and unified operations to lower overall management cost.
