AI Agent Architecture: A Practical Guide to Slim Kernels and Plan-Driven Design

    This guide explains why AI agent frameworks tend to accumulate complexity, and how to counter it with a slim kernel and plan-driven execution. It defines the kernel's three core responsibilities, five categories of pluggable capabilities that share a common plugin contract, and a structured task plan with an explicit approval state for high-risk actions. It also covers memory and sandbox governance, the observability metrics and regression baselines needed to make plugin replacement routine, a four-step adoption path, and common pitfalls to avoid.

    AI Agent Architecture: A Practical Guide to Slim Kernels and Plan-Driven Design

    1. Background: Why Agent Frameworks Keep Getting Thicker

    In the early stages of an agent application, teams usually keep all the logic in one big loop: assemble the prompt, parse the model output, call tools, write results back, and start the next round. As requirements grow, capabilities such as retry policies, permission checks, log tracing, context trimming, and human approval get pushed into the same module, until it becomes a “thick kernel” that is hard to test and hard to replace.

    A thick kernel causes three typical problems. First, coupling is too high: switching model vendors or inference methods requires changes to the scheduling backbone. Second, behavior becomes unpredictable: approval, retries, and tool calls are tangled together, so failures are hard to reproduce. Third, extension costs are high: adding a memory strategy or an execution environment usually means invading the core code.

    Because of this, the industry has gradually converged on a direction: keep the framework kernel thin, turn the volatile parts into composable, replaceable, extensible plugins, and constrain agent behavior with one explicit task plan. This article follows that line of thinking and presents a set of engineering practices that are independent of any specific product.

    2. Core Design Principles: A Slim Kernel and Five Pluggable Capability Classes

    The slim kernel’s responsibilities should be strictly limited to three things: scheduling models and tools, requesting human approval before high-risk operations, and maintaining a task plan. Every other capability should be pushed down to the plugin layer.

    Pluggable capabilities are usually divided into five classes:

    • Model capabilities: handle inference and generation, and hide differences between inference interfaces in parameters, context length, and streaming output.
    • Tool capabilities: wrap operations on external systems as invocation units with structured descriptions, declaring the input schema, side-effect level, and timeout policy.
    • Memory capabilities: manage short-term conversation context and long-term knowledge accumulation, and provide write, retrieval, compression, and expiration policies.
    • Sandbox capabilities: provide isolated environments for high-risk actions such as code execution and file operations, restricting network access, the file system, and resource quotas.
    • Agent capabilities: combine a set of prompt strategies, a tool allowlist, and plan templates into a reusable role.

    These five classes share one plugin contract: a unified initialization entry point, a unified invocation signature, and unified error classification and observability instrumentation. As long as the contract stays stable, swapping an implementation does not affect the backbone logic.

    A sketch of the contract definitions could look like this:

    1. class Plugin(Protocol):
    2. name: str
    3. def init(self, cfg: dict) -> None: ...
    4. def health(self) -> bool: ...
    5. def close(self) -> None: ...
    6. class ModelPlugin(Plugin):
    7. def complete(self, messages: list[dict], **opts) -> str: ...
    8. class ToolPlugin(Plugin):
    9. schema: dict # structured parameter description
    10. risk_level: str # low / medium / high
    11. def run(self, args: dict) -> dict: ...

    3. The Task Plan: The Key Handle for Agent Controllability

    The plan is the only state the slim kernel holds over the long term. It is not a piece of free text, but a set of nodes with states and dependencies. The recommended minimal state machine includes: pending, running, waiting for approval, done, failed, and cancelled.

    The value of the plan shows up in three ways. First, recoverability: after a process restart, execution can resume from the plan and memory instead of replaying the entire conversation from the beginning. Second, auditability: each node’s input, output, duration, and approval record can be persisted for later review. Third, constraint: the model can only choose actions from the “currently runnable node set,” which avoids unauthorized calls caused by free-form wandering.

    Plan nodes should include the following fields:

    1. {
    2. "id": "n3",
    3. "goal": "generate and validate the config file",
    4. "tool": "file_write",
    5. "risk": "high",
    6. "depends_on": ["n2"],
    7. "state": "waiting_approval",
    8. "attempts": 0
    9. }

    The scheduling loop can stay minimal:

    1. while plan.has_runnable():
    2. node = plan.next_runnable()
    3. if node.risk == "high" and not approvals.granted(node.id):
    4. plan.mark(node, "waiting_approval")
    5. continue
    6. result = sandbox.guard(tools[node.tool]).run(node.args)
    7. memory.append(node.id, result)
    8. plan.mark(node, "done" if result.ok else "failed")

    Note that the backbone code contains no specific model or tool names, which is exactly the hallmark of a slim kernel.

    4. Approval Gates: Turning High-Risk Operations into an Explicit State

    Approval should not be an if check scattered inside tools; it should be an explicit state in the plan. This has two direct benefits: approval requests can be queued and handled in batches, and when approval times out, the plan automatically suspends instead of retrying blindly.

    In practice, it helps to grade by side effect: read-only queries are low risk and can run directly; writing configuration or modifying data is medium risk and uses sampled auditing; deleting data, performing irreversible external operations, and anything involving cost or permission changes is high risk and must be confirmed each time. Approval credentials should be bound to the node ID, be single-use, and have a validity period, so they cannot be reused by later nodes.

    5. Memory and Sandbox: Isolating Risk and Governing Context

    The memory plugin needs to distinguish three kinds of content: short-range context for the current task, cross-session user preferences, and retrievable domain knowledge. The governance focus is compression and expiration: layered summarization for long conversations, reranking and truncation for retrieval results, and masking of sensitive fields before anything is persisted.

    The sandbox plugin takes on execution isolation. Common practices include containerized execution, a read-only root file system, a least-privilege account, a network egress allowlist, CPU and memory quotas, and forced termination on execution timeout. All sandbox output should be treated as untrusted text, and length and format constraints must be applied before it is fed back into the model, to prevent contaminating later reasoning.

    6. Observability and Evaluation: Making Plugin Replacement Routine

    The benefits of a plugin architecture only hold when they are measurable. It is recommended to collect four metrics consistently: scheduling latency, tool success rate, approval wait time, and plan completion rate. Logs and traces should use a unified identifier across the three stages of “plan node — model call — tool execution,” combined with logging services and monitoring/alerting to locate anomalies.

    For evaluation, maintain a fixed task set and a regression baseline, and run it after each model or tool implementation swap, comparing completion rate, average number of steps, and number of human interventions. If metrics degrade beyond a threshold, roll back the plugin version rather than changing the backbone.

    7. Adoption Path and Common Pitfalls

    A four-step rollout is recommended: first extract the plugin contract and a unified error classification; then separate approval and retries from the backbone into plan states; next integrate the sandbox and memory plugins; finally fill in metrics and regression evaluation.

    There are three common pitfalls. First, writing the plan as a long piece of natural language, which makes states undecidable; structured nodes are the fix. Second, over-designing the plugin contract with deeply nested parameters, which raises implementation cost; keep signatures small and stable. Third, making approval granularity too coarse and applying one rule to an entire workflow, which actually reduces efficiency; refine it by grading side effects.

    8. Conclusion

    The direction of agent framework evolution is not to keep adding features, but to externalize the volatile parts and converge the control plane. When models, tools, memory, sandboxes, and agent roles all exist as plugins, and the kernel keeps only the three responsibilities of scheduling, approval, and planning, the team gains sustainable replaceability and clear failure boundaries. With support from general-purpose capabilities such as containers, object storage, logging, and monitoring on cloud platforms like Baidu AI Cloud, this architecture can be implemented relatively smoothly as an operable, auditable production system.