Agent Planning and a Minimal Harness Architecture: A Practical Guide
This article explains a proven engineering pattern for agent systems: a minimal orchestration core paired with five replaceable plugin types (model, tool, memory, sandbox, and agent). It details the core design principles, plugin contracts, and the role of the task plan as a first-class state machine, along with approval mechanisms, sandbox and memory coordination, reliability engineering, a four-step adoption path, and common anti-patterns to avoid.
Agent Planning and a Minimal Harness Architecture: A Practical Guide
1. The Problem: Why Agent Systems Keep Getting Heavier
Over the past two years, most agent applications have followed a similar trajectory. They start as a simple script with a model and a few tools. Then, to handle real business needs, developers keep stuffing more logic into the inner layers: retries, caching, permission checks, context trimming, result parsing, and audit logging. A few months later, the orchestration layer has evolved into a massive function that is hard to test, hard to replace, and hard to observe. Any model upgrade or tool change triggers a cascade of regressions.
The root cause is not too many features, but that concerns are not properly layered. When “what to do” (policy) and “how to execute” (mechanism) are mixed in the same code, system complexity grows multiplicatively. The industry is converging on a consensus: capabilities should be built as pluggable components, and the orchestration core should be compressed to be as thin as possible, keeping only the responsibilities that must be centrally arbitrated.
This article discusses a proven, general engineering paradigm: a minimal orchestration core plus five types of replaceable plugins (model, tool, memory, sandbox, and agent). It focuses on the most easily overlooked yet reliability-critical component: the task plan.
2. Core Design Principle: Make the Orchestration Layer as Thin as Possible
A thin orchestration core takes on only three responsibilities that cannot be delegated:
- Schedule models and tools: Decide which model and which tool to call next, and return structured results to the context.
- Request approval before high-risk operations: Pause and wait for human confirmation for actions that are irreversible, exceed authority, involve costs, or cross data boundaries.
- Maintain a task plan: Record goals, steps, dependencies, and artifacts in an explicit, persistable, and auditable state machine.
Everything else should be pushed down into plugins. A simple test for whether a piece of logic belongs in the core: Does it require a global view to make the right decision? If yes, pull it up; if no, push it down. For example, “how to chunk documents” belongs to the memory plugin, “how to isolate command execution” belongs to the sandbox plugin, and “which model to use and how to retry” belongs to the model plugin.
This division yields three direct benefits: replaceability (swap models without changing business logic), testability (plugins can be unit-tested, and the core can be verified via record and replay), and observability (all cross-boundary calls have a unified instrumentation point).
3. Capability Boundaries and Contract Design for the Five Plugin Types
The key to plugin-based design is not the “split,” but contract stability. Each plugin type should expose only a few semantically clear methods, with serializable inputs and outputs, to facilitate cross-process and cross-language replacement.
- Model plugin: Abstracts away differences between inference services and provides a unified interface of “message list + tool declarations → text or tool call”; handles retries, rate limiting, timeouts, fallback, and cost accounting.
- Tool plugin: Declaratively describes its own name, purpose, parameter schema, and risk level; the risk level is an input to the approval policy and must be explicitly labeled by the tool author.
- Memory plugin: Distinguishes working memory (current context window), episodic memory (summaries of historical traces), and semantic memory (retrievable knowledge), and exposes only two operations externally: write and recall.
- Sandbox plugin: Provides three types of isolation—filesystem, process, and network—with least privilege and no external network by default; artifacts are returned through a controlled channel.
- Agent plugin: Is itself a composable unit that can be called by upper layers as “a tool,” supporting multi-role collaboration without changing the core.
Illustrative contracts (pseudocode, structure only):
class ToolPlugin(Protocol):name: strrisk: Literal["safe", "caution", "critical"]def schema(self) -> dict: ...def run(self, args: dict, ctx: Context) -> Result: ...class ModelPlugin(Protocol):def complete(self, messages: list, tools: list) -> Completion: ...class MemoryPlugin(Protocol):def write(self, key: str, value: Any) -> None: ...def recall(self, query: str, top_k: int) -> list: ...class SandboxPlugin(Protocol):def exec(self, cmd: list[str], timeout_s: int) -> ExecResult: ...
4. The Essence of a Plan: From a “Checklist in the Prompt” to a “First-Class State Machine”
Many implementations put the plan in the prompt and let the model maintain to-do items in natural language. This works in demos but is fragile in production: the plan cannot be validated, recovered, or audited. Once the context is compressed, progress is “forgotten.”
A more robust approach is to elevate the plan to a first-class object with four characteristics:
- Structured: Each step has a unique identifier, goal description, dependency set, risk level, status, and artifact reference.
- Persistable: Integrates with log services or object storage capabilities so it can be recovered after a process restart.
- Validatable: The core checks whether dependencies are met and artifacts exist before each advance, and directly rejects illegal transitions.
- Auditable: Every state change records the trigger (model/human/system), time, and reason.
A minimal state machine is as follows:
pending → ready → running → (succeeded | failed | awaiting_approval)awaiting_approval → running | canceledfailed → ready (replanning, with a limited count)
The key constraint is: the plan can only be modified by the core, and the model can only “propose” changes. The model outputs a change intent (add a step, mark as complete, request replanning), and the core validates and persists it. This rule confines “model hallucination” to the suggestion layer and prevents it from directly polluting the execution state.
def propose_and_apply(plan, proposal, checker):if not checker.validate(plan, proposal): # dependency, permission, and budget checksreturn Rejected(reason=checker.last_error)plan.apply(proposal) # the only write pointplan.persist()return Accepted(next_step=plan.next_ready())
5. Approval Mechanism: Designing “Human Confirmation” as an Orchestratable First-Class Citizen
Approval is often implemented as a single input() call, resulting in a blocked flow that cannot be batched or replayed. A more engineered approach has four elements:
- Risk-tier driven: Whether approval is needed is determined jointly by the risk levels of tools and plan steps;
criticalalways requires human confirmation. - Configurable policy: A policy table composed of “action type × resource scope × budget threshold” supports automatic whitelisting, gradual rollout periods, and dual review.
- Minimal context: The approval request shows only necessary information (goal, scope of impact, irreversibility, estimated cost) to avoid leaking irrelevant data.
- Revocable and timeout-aware: The default is fail-closed on timeout (deny), with a revocation entry point and a complete receipt retained.
Illustrative policy:
approval_policy:default: askrules:- when: {action: "read", scope: "internal"} # read-only and limited scopethen: auto_approve- when: {action: "write", irreversible: true}then: human_confirm- when: {action: "external_call", budget_usd: ">10"}then: dual_reviewtimeout: 15mon_timeout: deny
6. Sandbox and Memory Coordination: Security Boundaries and Context Economy
The value of the sandbox is not only to “isolate dangerous commands,” but also to make the cost of trial and error controllable. It is recommended to default to no network, a read-only root filesystem, an independent temporary directory, hard timeouts, and resource quotas; when external access is needed, authorize it separately by domain whitelist, and write all artifacts to a controlled directory for the core to decide whether to include them as plan artifacts.
The memory plugin needs to solve “context economy”: instead of stuffing all history back into the window, retain it in layers—recent verbatim text, mid-term summaries, and long-term retrievable snippets. When combined with the plan, each step’s artifact should be written to memory as a referenceable record, and subsequent steps should reference it by identifier rather than repeatedly pasting content, thereby keeping the context size stable.
# Write step artifacts to memory and use them by reference latermem.write(f"plan/{plan.id}/step/{step.id}", artifact)ctx.append(reference=f"plan/{plan.id}/step/{step.id}") # pass only the reference
7. Reliability Engineering: Idempotency, Retries, Budgets, and Observability
A thin core does not mean simplicity; it must build “failure is the norm” into the design:
- Idempotency keys: Each tool call carries an idempotency key derived from the plan step identifier to avoid duplicate writes caused by retries.
- Tiered retries: Model calls can be automatically retried and fall back to a backup model; write-type tools do not retry automatically by default and go to approval instead.
- Budget guardrails: Set upper limits on steps, token volume, call count, and elapsed time; exceeding them triggers replanning or termination to prevent infinite loops.
- Full-chain tracing: Use the plan identifier as a dimension throughout to link model calls, tool executions, approval records, and artifacts, making replay and debugging easier.
- Bounded replanning: Failed steps are allowed to return to
ready, but both the replanning count and the total budget are limited to avoid “thinking drift.”
If running on top of container platforms or function-computing general capabilities, each execution can be treated as a stateless instance, with the plan and artifacts externalized to object storage, logging, and monitoring and alerting services, thereby naturally gaining elasticity and recoverability. Such capabilities belong to general industry categories; when selecting them, evaluate primarily on the degree of interface standardization and the completeness of observability.
8. Adoption Roadmap: Four-Step Evolution to Avoid a One-Time Rewrite
- Extract contracts: First define the five plugin interfaces and a unified context structure, and wrap existing code with adapters so behavior remains unchanged.
- Introduce the plan: Bring in a structured plan and a single write point, migrate the checklist in the prompt to a state machine, and complete persistence.
- Add approval: Label tool risk levels, build a policy table and fail-closed timeouts, and first apply them to
criticalactions. - Strengthen observability: Unify tracing, budget guardrails, and replay capabilities, then gradually expand to multi-agent collaboration (agents called as tools).
Acceptance can use three types of benchmarks: task completion rate, human intervention rate (number of approvals / total steps), and cost per task and mean time to recovery. Only when all three metrics improve simultaneously does it indicate that the layering is truly effective, rather than just moving complexity elsewhere.
9. Common Anti-Patterns
- Fat core: Writing parsing, caching, and permissions into the orchestration layer, causing a regression whenever the model is swapped.
- Stateless plan: The plan exists only in the context, is forgotten upon compression, and cannot be recovered.
- Decorative approval: Asking about every action, leading users to click through mindlessly out of fatigue, rendering security meaningless.
- Over-privileged sandbox: Enabling external network and write permissions by default for convenience, rendering the isolation layer meaningless.
- Unbounded replanning: Lacking budget and count constraints, causing the system to fall into inefficient loops.
10. Conclusion
The maturity of agent engineering is often not reflected in how long the capability list is, but in how thin the core is, how stable the contracts are, and how verifiable the plan is. Making the model, tools, memory, sandbox, and agents into replaceable plugins, and letting the orchestration core focus on just three things—scheduling, approval, and planning—is the key path to balancing complexity and controllability. For teams that want to build such systems in their own cloud environments, it is recommended to first solidify the two foundational pieces—plugin contracts and the plan state machine—and then gradually introduce containerized execution and an observability system, so as to obtain stable, auditable, and evolvable agent capabilities at a controllable cost.
