Agent Plan-Driven Minimal Framework: A Practical Guide to Maintainable AI Agent Systems
This article explains why AI agent systems become hard to maintain as they move from prototypes to production, and presents a practical plan-driven architecture built on a thin kernel and thick plugins. It covers the core design principles, a five-layer architecture with plugin contracts, using a verifiable plan as the single source of truth, approval gates for high-risk operations, execution sandboxing and memory governance, observability and evaluation, common anti-patterns, and a four-stage rollout approach with general-purpose cloud capabilities. Engineers will learn how to keep the kernel minimal, externalize constraints through policies and contracts, and achieve controllability and auditability without sacrificing flexibility.
1. Background: Why Agent Systems Get Harder to Maintain
Agent engineering over the past two years has followed a familiar trajectory. In the prototype stage, a few dozen lines of code are enough to close the loop between a model and tools. Once the system enters real business use, however, complexity grows quickly. The problem is not the model’s capability but the lack of clear engineering boundaries: model invocation logic, tool adapters, context assembly, permission checks, retry strategies, and logging are all mixed into one large loop. The result is a “monolith loop” where any change can trigger cascading failures.
Uncontrollability makes things worse. Tool calls have side effects. Operations such as writing files, sending messages, changing configurations, and deleting data become dangerous once the model autonomously decides their execution order, because errors are amplified quickly. Most implementations lack pre-execution confirmation and rollback points, so after a failure teams can only reconstruct what happened from logs with great difficulty. At the same time, business stakeholders strongly demand replaceability: switching model vendors, changing the vector retrieval approach, or moving local execution into an isolated environment often means rewriting a large part of the system.
The industry has gradually converged on a shared conclusion: agent systems need a structure of a “thin kernel plus thick plugins.” The kernel does only the minimal but most critical work, and all other capabilities are pluggable. This article uses the plan as the organizing center and provides a complete, actionable practical guide.
2. Core Design Principles: Subtract from the Kernel, Add Capabilities as Plugins
The value of a thin kernel is that it decouples decision-making from execution. The kernel is not suited to domain logic and should not take it on. It is responsible for only three things:
- Scheduling models and tools: deciding “who to call next” and returning structured results to the context.
- Requesting human approval before high-risk operations: turning irreversible actions into gated actions that require explicit authorization.
- Maintaining a task plan: keeping goals, steps, status, and artifacts visible to both humans and models.
Around these three responsibilities, models, tools, memory, execution sandboxes, and agent strategies should all be composable, replaceable, and extensible plugins. A simple test determines whether a design is sound: when replacing any one class of plugin, the kernel code should not need to change, and only new configuration and an adapter layer are required.
This structure brings three direct benefits. First is controllability: permissions and approvals are centralized in the kernel and cannot be bypassed by the implementation details of a plugin. Second is evolvability: model upgrades, new tools, and memory strategy changes become local changes. Third is auditability: the plan and approval records naturally form a complete evidence chain.
3. Layered Architecture and Plugin Contracts
It is recommended to divide the system into five layers: an access layer, a kernel scheduling layer, a plugin capability layer, an execution isolation layer, and an observability layer.
The access layer handles sessions and identity and outputs a unified task request. The kernel scheduling layer holds the plan state machine and approval policy. The plugin capability layer consists of five types of plugins. The execution isolation layer provides a restricted runtime environment for tools. The observability layer collects plan changes, tool calls, and approval events.
The plugin contract is the key to the whole architecture. Each type of plugin exposes only a minimal, stable interface, and inputs and outputs use structured data to avoid free text flowing between layers:
ModelPlugin: infer(context, schema) -> structured_resultToolPlugin: describe() -> {name, risk_level, cost_hint}invoke(args, sandbox_handle) -> resultMemoryPlugin: recall(query, budget) -> snippetswrite(item, policy) -> ackSandboxPlugin: create(policy) -> handleexec(handle, action) -> outputAgentPlugin: propose(plan_state) -> next_steps
Here, risk_level and cost_hint are self-declared by the tool plugin, and the kernel uses them to decide whether approval is required and whether a budget constraint applies. This “capability self-description” means the kernel does not need to understand the semantics of any specific tool, which fundamentally avoids coupling.
4. The Plan: The Single Source of Truth for the Agent
A plan is not a piece of natural-language description but a verifiable state machine. The minimal usable structure includes a goal, a set of steps, dependencies, the current state, artifacts, and a budget:
{"goal": "Generate a quarterly data summary and archive it","steps": [{"id": "s1", "action": "collect", "depends_on": [], "state": "done"},{"id": "s2", "action": "analyze", "depends_on": ["s1"], "state": "running"},{"id": "s3", "action": "publish", "depends_on": ["s2"], "state": "pending", "risk": "high"}],"budget": {"tokens": 120000, "tool_calls": 40}}
Plan-driven design offers three benefits. First, in each round the model faces only the “currently executable steps,” which significantly compresses both context length and the decision space and improves output stability. Second, failures can be retried locally: you only need to roll a step’s state back to pending instead of restarting the whole flow. Third, the plan itself is a progress view for humans, so business stakeholders can judge task progress without understanding the internal implementation.
Three hard rules are recommended in engineering: state transitions may only be performed by the kernel; the model may only “propose” step changes and cannot directly rewrite state; and any high-risk step must be in pending and have obtained authorization before it can enter running.
5. Approval for High-Risk Operations: Put Irreversible Actions Behind a Gate
The key to designing an approval mechanism is not a “pop-up” but a decidable policy. It is recommended to classify tools by risk: read-only tools are low risk and can run directly; tools that write internal state are medium risk and must be logged and capped; tools that affect external systems or are irreversible are high risk and require human confirmation.
def gate(step, tool_meta, approval):if tool_meta.risk_level == "high":return approval.is_granted(step.id, scope=tool_meta.name)if step.cumulative_cost > step.budget.tool_calls:return approval.is_granted(step.id, reason="budget_exceeded")return True
An approval request should carry enough context: the goal, the current step, the action about to be executed, the expected scope of impact, the rollback plan, and a timeout. The recommended timeout policy is to deny by default rather than allow by default, avoiding “automatically opening permissions when unattended.” All approval decisions are written to a tamper-proof audit stream bound to the plan version number, making it easy to trace afterward “at which step, by whom, and what was authorized.”
6. Execution Isolation and Memory Governance
Tool execution must run in a restricted environment. A common practice is to create an independent sandbox instance for each task, configured with least privilege, read-only mounts for data directories, restricted network egress, and CPU and runtime limits, then destroy it when the task ends. File writes first land in a temporary area, and only after validation does the kernel commit them to persistent storage, keeping “dirty data” out of production directories.
The memory plugin also needs a budget and policy. It is recommended to distinguish three types of memory: short-term session context, task-level intermediate artifacts, and long-term knowledge across sessions. Before writing to long-term memory, perform deduplication and conflict detection; when reading, truncate by relevance and quota to avoid the context being flooded by irrelevant content. All memory entries retain their source and write time and support batch invalidation by policy.
7. Observability, Evaluation, and Common Anti-Patterns
Observability should cover four chains: plan state changes, model calls (including latency and usage), tool calls (including parameter summaries and return codes), and approval events. With these four types of events, you can reconstruct the complete timeline of any task.
Evaluation is recommended to use a layered approach: first use fixed inputs to verify that plugin contracts are stable, then use an offline test set to evaluate plan completion rate and step retry rate, and finally observe the human approval trigger rate and rejection reasons in small-scale traffic. A high approval rejection rate usually indicates that risk classification is too coarse or context is insufficient; a high retry rate often means the step granularity is poorly designed.
There are four common anti-patterns: pushing business logic back into the kernel; letting the model directly modify plan state; tools without risk classification, which makes approval meaningless; and lacking budget constraints, which causes runaway calls. The way to avoid them all points to the same principle: keep the kernel extremely thin, and externalize constraints in the form of policies and contracts.
8. Rollout Roadmap and Working with General-Purpose Cloud Capabilities
A four-stage approach is recommended: in the first stage, solidify the plugin contracts and plan structure; in the second stage, integrate the sandbox and approval gate; in the third stage, complete observability and evaluation; and in the fourth stage, run a plugin replacement drill to verify whether the architecture is truly decoupled.
When deploying on the cloud, general-category capabilities can carry the responsibilities of each layer: a container platform hosts the sandbox runtime, object storage holds task artifacts, a message queue decouples long-running tasks from notifications, logging services and monitoring alerts support the observability chain, and key management capabilities centrally host credentials. Baidu AI Cloud offers corresponding product forms in these general categories, and teams can select based on their own compliance and scale requirements without changing the kernel design.
Overall, the long-term maintainability of an agent system does not depend on how strong the model is, but on whether the boundaries are clear. Making capabilities replaceable plugins, making the plan the single source of truth, and putting high-risk actions behind an approval gate lets you gain the controllability and auditability that engineering requires while preserving flexibility.
