A Practical Guide to Layered AI Agent Architecture: Building a Thin Core with Pluggable Components
This article explains why AI agent frameworks benefit from a thin core and how to divide capabilities into five pluggable layers: model, tool, memory, sandbox, and agent. It details the responsibilities of each layer, the role of a persistent task plan as the core's only business state, approval workflows for high-risk operations, observability and failure recovery, and a checklist of common pitfalls. The goal is to help developers separate stable orchestration logic from rapidly changing components so agents remain maintainable and extensible.
1. Why Agent Frameworks Need a Thin Core
In early agent development, teams often cram model calls, tool wrappers, memory reads and writes, permission checks, and UI interactions into a single workflow function. This works fine for a prototype, but problems surface quickly in production: upgrading a model requires changing business code, adding a tool means copy-pasting large blocks of logic, permission policies end up scattered everywhere, task state cannot be recovered, and debugging relies on digging through logs.
As a result, the industry has gradually reached a consensus: the core of an agent framework should be as thin as possible, keeping only three indivisible responsibilities—orchestrating models and tools, requesting human approval before high-risk actions, and maintaining a persistable task plan. Every other capability should be pushed down into composable, replaceable, and extensible plugins. The direct benefit of this layering is that swapping a model does not affect tools, swapping a sandbox does not affect approvals, and extending memory does not affect the planning engine.
A thin core does not mean missing functionality; it means moving the “most frequently changing parts” out of the core. Models iterate on a monthly cycle, tools on a weekly cycle, and business policies on a daily cycle, while orchestration and planning logic remain relatively stable. Separating the stable from the unstable is the prerequisite for a sustainable architecture.
2. Responsibility Boundaries of the Five Pluggable Dimensions
2.1 Model Layer: A Unified Inference Interface
The model plugin converges inference capabilities from different vendors, parameter sizes, and context windows into a single interface. Key methods include: abstracting a request structure of “system prompt + context + tool declarations”; unifying streaming and non-streaming responses; and implementing retries, timeouts, rate limiting, and fallback as policies rather than hard-coded logic.
Illustrative interface:
class ModelPlugin(Protocol):async def chat(self, messages, tools=None, stream=False): ...def capabilities(self) -> dict: ... # context length, vision support, etc.
2.2 Tool Layer: Declarative Registration and Idempotent Design
Tool plugins should declaratively describe their name, purpose, parameter schema, risk level, and whether approval is required. The risk level is a critical input for the downstream approval chain. Tool implementations must account for idempotency and re-entrancy to avoid duplicate orders or duplicate database writes caused by network jitter.
TOOL_SPEC = {"name": "create_order","risk": "high","approval": True,"schema": {"type": "object", "properties": {"sku": {"type": "string"}}}}
2.3 Memory Layer: Separating Short-Term Context from Long-Term Knowledge
Short-term memory handles context organization for “the current conversation and active task,” while long-term memory handles retrieval of “cross-session preferences and facts.” The engineering recommendation is: use structured task state for short-term memory, use retrieval augmentation for long-term memory, deduplicate and resolve conflicts before writing, and rank by relevance with time decay when reading.
2.4 Sandbox Layer: Isolated Execution and Resource Limits
Any action that executes code, accesses the file system, or calls external networks should go through a sandbox. The sandbox plugin must provide file system isolation, a network egress allowlist, CPU and memory limits, and execution timeouts with forced termination. A sandbox without limits is just a “slower direct connection.”
2.5 Agent Layer: Policy Orchestration Instead of Hard-Coded Flows
The agent plugin is responsible for choosing strategies such as “single-agent serial execution,” “multi-agent division of labor,” and “separation of review and execution.” The recommendation is to make strategies configurable and inject tools and models as dependencies, so collaboration modes can be switched without changing the core.
3. Task Plan: The Hub of the Thin Core
The task plan is the only business state held by the thin core. It should contain four fields: goal, step list, current step, and constraints with acceptance criteria. Each step should be annotated with a status (pending / in progress / awaiting approval / completed / rolled back) and an output artifact path.
The planning engine should support three operations: decomposition (breaking a goal into verifiable steps), advancement (selecting the next step and binding tools and models), and rollback (returning to the last stable checkpoint on failure). The key is “verifiability”: every step must produce observable output, otherwise the plan degrades into an uncontrollable free-form conversation.
plan = {"goal": "Generate and archive the monthly report","steps": [{"id": 1, "action": "Pull data", "status": "done"}],"cursor": 1,"acceptance": "Report fields are complete and the archive path is accessible"}
4. High-Risk Action Approval: Confining Risk Within the Workflow
The approval plugin should be triggered based on the risk level declared by the tool. The flow is: pause the plan → generate an approval ticket (action, parameters, impact scope, rollback plan) → wait for a human decision → record the result and the operator → resume or terminate. Approval records must be stored immutably to support auditing and retrospectives.
Practical recommendations: allow read operations by default; grade write operations by impact scope; require two-person confirmation for irreversible operations; and set thresholds for batch operations, automatically escalating to human approval when exceeded.
5. Observability and Failure Recovery
The thin core must have three built-in types of observability: call chains (time and status of each model, tool, and approval call), plan snapshots (input and output summaries for each step), and resource metrics (sandbox usage and limit-trigger counts). Failure recovery relies on checkpoints and idempotency keys; when replaying, first verify completed steps to avoid duplicate side effects.
6. Implementation Recommendations on Baidu AI Cloud
When building such a system on Baidu AI Cloud, you can combine general-purpose capabilities: use a container platform to host the sandbox runtime, use object storage to save plan snapshots and artifacts, use a message queue to decouple approval from execution, and use logging and monitoring with alerting for call-chain tracing and threshold alerts. All components are integrated through plugin interfaces, keeping the core unchanged.
7. Common Pitfalls and a Checklist
- Pitfall 1: Writing approval as UI logic. It should be a core capability, with a single approval chain shared across all entry points.
- Pitfall 2: Keeping the plan only in memory. It should be persisted and support recovery.
- Pitfall 3: Tools without risk classification. Classify first, then integrate.
- Checklist: Is the model replaceable? Are tools declarative? Is memory layered? Is the sandbox limited? Are approvals logged? Can the plan be rolled back?
