AI Agent Layered Architecture: A Practical Guide to a Thin-Kernel Harness
This article explains why a thin-kernel harness matters more than the model itself in AI agent engineering, and how to structure a runtime around it. It covers the five-layer model (model, tools, memory, sandbox, and agent orchestration), the engineering implementation of the kernel's three core responsibilities (model and tool scheduling, high-risk action approval, and explicit task plan maintenance), guidance for selecting capability packages and plugins, observability and cost governance, and a four-stage rollout roadmap with common pitfalls and their mitigations.
1. Background: Why Agent Frameworks Need a “Thin Kernel”
Agent engineering over the past two years has repeatedly confirmed one conclusion: what really determines a project’s success is often not the model itself, but the surrounding “runtime.” The same model, paired with different tool sets, memory strategies, and execution isolation schemes, can produce results that differ by several times in quality. As a result, the industry has gradually converged on a common architectural paradigm:
Agent ≈ Model + Harness (runtime skeleton)
The Harness takes on three minimal responsibilities: scheduling the model and tools, requesting human approval before high-risk actions, and maintaining an evolving task plan. All other capabilities are pushed down into plugins. This “extremely thin kernel, externalized capabilities” structure brings three direct benefits: first, low replacement cost, since swapping models does not change business code; second, clear governance boundaries, with permissions and auditing centralized in the kernel; third, controllable upgrades, since plugins can be rolled out gradually and independently.
Note that this article does not target any specific vendor’s product. Instead, it abstracts the common design of such frameworks into a general engineering method, and productized packaging forms in the examples are uniformly referred to as “a cloud vendor’s agent capability package.”
2. Layered Model: Responsibility Boundaries of Five Pluggable Components
A mature agent runtime typically divides capabilities into five layers, each exposed through a unified interface and composable, replaceable, and extensible.
- Model layer: responsible for reasoning and decision-making. Engineering-wise, it should abstract a unified message protocol, streaming output, tool-call format, and timeout/retry strategy so that the business side is unaware of specific model differences.
- Tool layer: responsible for interacting with the external world, including retrieval, data queries, code execution, message notifications, and more. The quality of tool descriptions (name, purpose, parameter schema) directly determines the model’s accuracy in selecting tools.
- Memory layer: distinguishes short-term context from long-term memory. Short-term relies on context window management, while long-term usually lands on a combination of vector retrieval and structured storage.
- Sandbox layer: provides an isolated execution environment for untrusted code and file operations, restricting network egress, filesystem scope, and resource quotas.
- Agent layer: orchestrates the above components by role, such as planner, executor, and reviewer, forming a closed loop through message passing.
The value of layering lies in “replaceability that can be tested.” Each layer should have contract tests so that replacing an implementation does not break upper-layer behavior.
3. Engineering Implementation of the Kernel’s Three Things
3.1 Model and Tool Scheduling
The core of the scheduler is a constrained loop: read the task plan → choose the next action → call the model or a tool directly → validate the result → write back state. Key design points include idempotency keys for tool calls, failure classification (retryable / needs human / terminate), and context trimming strategy to avoid long tasks blowing up the window.
while not plan.done():step = plan.next()result = runtime.invoke(step) # model or toolif result.needs_approval:result = await approve(result) # intercept high-risk actionsplan.commit(step, result)
3.2 High-Risk Operation Approval
Approval is not a simple “confirmation popup” but should include four elements: action summary, scope of impact, rollback plan, and timeout policy. Actions such as writing files, deleting data, sending external requests, and generating billable calls should enter the approval queue by default; read-only queries can be allowed through. All approval records must be auditable.
3.3 Task Plan Maintenance
The plan should be an explicit data structure rather than hidden in conversation history, containing at least the goal, steps, dependencies, status, and artifact paths. Making it explicit supports resume-from-breakpoint, failure re-planning, and human takeover.
4. Capability Packages and Plugin Selection: Avoiding Trial and Error Among Massive Components
A cloud vendor’s agent capability package takes the approach of bundling the model quota and runtime components needed to “get work done, remember things, grow, and produce deliverables,” with quota deducted uniformly for more controllable budgeting. For developers, the practical meaning is lower selection cost: which type of retrieval to use, which data source to trust, how to connect memory, and how to iterate on results have all been pre-validated once.
Selection recommendations follow three principles: prefer components with clear input/output contracts; prefer observable components (with logs, metrics, tracing); prefer components that can degrade gracefully on failure.
5. Observability and Cost Governance
An agent is a long-chain system, and three layers of observability must be established: call-chain tracing (which step is slow, which step is wrong), quality metrics (task success rate, human takeover rate, approval rejection rate), and cost metrics (model consumption and tool-call counts per task). On Baidu AI Cloud, this system can be built by combining general capabilities such as log service, monitoring and alerting, object storage, and message queues, enabling budget threshold alerts and automatic degradation.
6. Rollout Roadmap and Common Pitfalls
It is recommended to proceed in four stages: first do read-only Q&A and retrieval to validate tool description quality; then introduce sandbox execution to validate isolation and rollback; then connect long-term memory to validate recall relevance; finally open write operations and external side effects, keeping approval and auditing throughout.
Common pitfalls include: too many tools leading to lower selection accuracy, no context trimming leading to out-of-control costs, no deduplication on memory writes leading to recall pollution, and fully open sandbox network leading to data leakage risk. The corresponding practices are tool grouping, context budgeting, write validation, and least-privilege network policies.
Overall, “thin kernel + pluginization” moves agents from one-off demos to sustainable operational systems engineering, while unified capability packages and quota management solve the two long-term pain points of selection and budgeting upfront.
