The Model + Harness Formula: Building AI Agents That Actually Deploy

    This article explores why strong model capabilities alone do not guarantee a deployable AI agent, and presents a practical framework centered on the "Model + Harness" formula. It breaks down the engineering layers, context management, tool orchestration, task planning, plugin architecture, evaluation loops, and a phased rollout strategy for building production-grade agents. Aimed at developers and technical decision-makers, the piece emphasizes engineering discipline, safety boundaries, and measurable quality over one-off demonstrations, offering a vendor-neutral approach that remains applicable across cloud environments.

    From Formula to Engineering Boundaries: Three Distinct Layers

    A maintainable agent system typically splits into three layers. The first is the model layer, responsible for semantic understanding, reasoning candidate planning, natural language generation, and structured output constraints. It should remain as stateless and replaceable as possible, avoiding hardcoded business logic inside model calls. The second is the harness layer—the engineering scaffold—responsible for translating a user goal into executable steps: selecting context, invoking retrieval, writing intermediate artifacts, triggering tools, handling retries on failure, and recording traces. The third is the business and environment layer, including enterprise data, permission systems, tickets, code repositories, knowledge bases, approval workflows, and runtime resources.

    Clear contracts must be defined across these layers: the model only receives structured tasks and observations; the harness decides when to let the model reason and when the deterministic system should execute; business systems expose only the least necessary capabilities.

    An anti-pattern commonly seen in practice is pushing all logic into oversized prompts. That can look impressive in a demo, but over time leads to context bloat, behavioral drift, lack of regression control, and over-privileged permissions. A more reliable approach is to delegate “strategy” to the model while assigning “facts, state, and action boundaries” to the harness. For example, a model may propose “reading a configuration file and generating a patch,” but whether the path is allowed to be read, whether the patch goes into review, or whether tests are triggered—these decisions are made by the harness’s policy engine.

    Context Management: Not Longer, but Computable Relevance

    Context serves as an agent’s short-term working memory. High-quality context management involves four operations: selection, compression, isolation, and expiration. Selection dynamically assembles system instructions, tool schemas, retrieved snippets, historical summaries, and constraints based on the current task phase. Compression converts long histories into verifiable summaries while retaining reference pointers for traceability. Isolation prevents mixing data of different tenants, projects, or sensitivity levels in the same reasoning context. Expiration gives temporary credentials, cached conclusions, and intermediate files a defined lifecycle.

    A practical engineering approach uses a combination of working memory, episodic memory, and semantic memory. Working memory stores the current subtask and recent observations; episodic memory records key events such as failure reasons, user preferences, and confirmed constraints; semantic memory accumulates reusable knowledge, but writes should go through review and version tagging. For coding agents, maintain symbol indexes, dependency graphs, change sets, and test results rather than naively concatenating source code. Context budget should be treated as a first-class resource: before each call, estimate token cost, latency cost, and data-leak risk, and trigger summarization or layered retrieval when thresholds are exceeded.

    Tool Invocation and Execution: Deterministic First, Model Chooses and Explains

    Tools are the interface through which an agent touches the real environment. When designing the tool layer, four principles are recommended: narrow interfaces, strong validation, reentrancy, and observability. Narrow interface means each tool does one thing—read a file snippet, run tests, create a branch, query logs. Strong validation requires checking parameter types, path whitelists, command risks, and rate limits before invocation. Reentrancy ensures that failure recovery does not double-charge, double-send, or duplicate resource creation. Observability requires each tool call to produce structured events containing input summary, output summary, elapsed time, error codes, and an audit ID.

    A generic execution loop can be expressed as follows:

    1. while not done and within_budget:
    2. obs = harness.observe(state)
    3. plan = model.propose(goal, obs, tools, policy)
    4. action = harness.guard(plan, policy, sandbox)
    5. result = executor.run(action)
    6. state = harness.reduce(state, action, result)
    7. eval.record(trace_id, action, result)

    The two critical points here are guard and reduce. Guard intercepts unsafe actions after the model proposes them but before real execution. Reduce writes execution results back into the state machine to form the next observation. The model does not directly “change the world”; it only generates action intent. Any mutation of real-world state must pass through policy, sandboxing, and audit.

    Task Planning: From One-Shot Answers to Recoverable State Machines

    Real-world tasks are rarely single-turn Q&A. They are multi-stage processes: clarifying requirements, collecting materials, generating proposals, executing changes, verifying results, rolling back, or handing off. The harness should model tasks as a state machine or a directed acyclic graph, where each node contains inputs, outputs, success criteria, failure handling, and human intervention points. High-risk nodes should default to human approval; reversible low-risk nodes may run automatically while retaining rollback snapshots.

    Planning should also distinguish between deliberate reasoning and fast reflexes. Simple classification, format conversion, and status queries can be handled by smaller models or rules. Cross-file refactoring, architecture trade-offs, and complex fault diagnosis should invoke stronger models. Through routing policies that map task difficulty, context length, data sensitivity, and latency requirements to different model and tool combinations, you can balance quality, cost, and response time. When deploying on a general cloud platform such as Baidu AI Cloud, teams can use object storage, message queues, container services, logging, and monitoring alerting to support asynchronous tasks, elastic execution, trace retention, and alert correlation—but the core design should remain vendor-neutral.

    Plugin Architecture: Everything Is an Extension Point, but the Core Must Stay Stable

    The value of “everything is a plugin” lies not in the number of plugins, but in separating volatile parts from a stable core. The stable core includes the task lifecycle, permission model, event bus, trace schema, evaluation interfaces, and resource quotas. The volatile parts include retrievers, tool adapters, domain prompts, parsers, executors, evaluators, and UI components. Plugins should declare capabilities, dependencies, required permissions, input/output protocols, and degradation strategies through a versioned manifest, avoiding implicit coupling.

    Plugin-based architectures also introduce supply-chain risk. Every plugin should be treated as an untrusted input source: signature or origin verification, least-privilege authorization, runtime isolation, dependency vulnerability scanning, canary enablement, and one-click disable are all non-negotiable. For code-modification plugins, produce patches rather than writing files directly. For terminal-execution plugins, restrict network access, filesystem, and system calls within a container. For external data plugins, label trustworthiness and present evidence levels in the final answer.

    Feedback, Evaluation, and Release: No Closed Loop, No Agent Product

    Agent quality cannot be judged by subjective experience alone. An evaluation system should include at least offline sets, online sampling, and adversarial regression. Offline sets cover typical tasks, edge cases, refusal scenarios, and permission violations. Online sampling extracts high-failure, high-cost, and frequent-user-correction samples from real traces. Adversarial regression specifically tests prompt injection, tool misuse, data leakage, and cascading failures. Metrics should not only track success rates, but also task completion degree, step efficiency, tool misuse rates, human takeover rates, rollback rates, per-task cost, latency percentiles, and security incident counts.

    A progressive release strategy is recommended: preview, internal beta, canary rollout, then general availability. The preview phase validates architecture and developer experience; internal beta focuses on high-value scenarios and engaged feedback from users; canary rollout gradually expands by tenant, scenario, and risk level; general availability requires supporting audit reports, quota systems, disaster recovery, and model/plugin version compatibility commitments. When upgrading the base model, the harness should run behavioral comparison snapshots: trace differences, tool-selection differences, and artifact differences on the same task set between the old and new models, confirming that benefits outweigh regression risks before switching.

    The Implementation Path: Start with a Single Workflow, Not a General Assistant

    The most practical way to implement agents is not chasing a “universal assistant” from day one. Instead, pick one high-frequency workflow with clear boundaries and verifiable outcomes—for example, log triage, API change-impact analysis, test case completion, knowledge-base Q&A with citations, or pre-release checks. First define completion criteria and forbidden zones, then integrate a minimal toolset, and spend about four weeks building trace collection, evaluation sets, and a human feedback channel. Once a single scenario stabilizes, distill the shared capabilities into the harness core, and wrap scenario differences into plugins and policy configurations.

    In summary, “Model + Harness = Agent” moves intelligence from probabilistic generation to controlled execution. The model provides cognitive flexibility; the harness provides engineering determinism. The former sets the ceiling, the latter sets the floor. A genuinely deployable agent product must close the loop across context, tools, planning, plugins, security, evaluation, and release—and remain explainable, rollback-safe, and continuously evolvable through model iterations, business changes, and emerging risks.