Building AI Agents with Models and Harness: A Systems Engineering Approach

    LLMs are strong at reasoning but lack the ability to reliably execute real-world operations. This article explains the "Model + Harness = Agent" design pattern, covering how a Harness handles runtime orchestration, tool execution, state management, context control, security governance, and observability. It outlines a practical workflow for agent execution, tool system design principles, and a phased path from prototype to production-ready agent systems.

    LLMs are highly capable of understanding natural language, summarizing information, generating content, and planning. However, they do not automatically handle real-world file operations, API calls, permission checks, task retries, or result auditing. To make a model genuinely useful for complex work, you need an engineering layer outside the model that handles runtime management. This layer can be collectively called the Harness.

    “Model + Harness = Agent” is not a simple sum of components—it is a systematic design philosophy for intelligent agents. The model provides cognitive capability, while the Harness provides the execution environment, tool connectivity, and process governance. Together they form an agent system that can perceive tasks, make plans, take actions, and continuously adjust based on results.

    1. Dividing Responsibilities Between the Model and the Harness

    The model’s core job is handling uncertainty. It understands context from user goals, breaks tasks into steps, chooses which tools to use, and continues reasoning based on tool outputs. For example, when a user asks to “analyze a batch of business logs and generate an anomaly report,” the model can identify the task goal, determine which data to read, which analysis dimensions to apply, and what the final report should contain.

    But models do not inherently possess reliable execution capability. Generating text does not guarantee files are read correctly, APIs are called securely, or results satisfy business constraints. Therefore, the Harness must take on the following responsibilities:

    1. Runtime orchestration: Managing model calls, tool calls, and task loops.
    2. Context management: Organizing user input, conversation history, intermediate results, and external materials.
    3. Tool execution: Translating model-proposed actions into real, controlled program operations.
    4. State persistence: Saving task progress, execution results, and error information.
    5. Security governance: Restricting permissions, validating parameters, and requiring human confirmation for high-risk operations.
    6. Observability: Recording call chains, latency, errors, and resource consumption.
    7. Reliability: Handling timeouts, retries, rollbacks, idempotency, and concurrency.

    In short, the model acts as the “decision and reasoning engine,” while the Harness acts as the “agent runtime.” Only when the two form a stable closed loop does an agent become engineering-grade and usable.

    2. The Core Workflow of a Harness

    A typical agent execution process can be abstracted into the following loop:

    1. Receive goal
    2. ↓
    3. Build context
    4. ↓
    5. Call model for analysis
    6. ↓
    7. Decide whether action is needed
    8. ├─ No: generate final answer
    9. └─ Yes: select tool and generate arguments
    10. ↓
    11. Validate permissions and arguments
    12. ↓
    13. Execute tool
    14. ↓
    15. Write execution results
    16. ↓
    17. Call model again

    The most critical part is the “model → tool → result → model” loop. The model is not called only once; it must continually revise its judgment based on actual execution results. For instance, a data query may return missing fields, a file read may hit permission errors, or an external service call may time out. The Harness must feed these situations back to the model as structured information, rather than concatenating them into an unreadable error string.

    A clearer internal state can be represented as:

    1. {
    2. "task_id": "task identifier",
    3. "goal": "user goal",
    4. "status": "running",
    5. "steps": [
    6. {
    7. "name": "read data",
    8. "status": "success",
    9. "result_ref": "result reference"
    10. }
    11. ],
    12. "pending_action": {
    13. "tool": "data analysis tool",
    14. "arguments": {}
    15. }
    16. }

    In real systems, large results should not be dumped directly into the context. For long documents, large log volumes, or bulk query results, store them in external storage and provide the model only with summaries, indexes, or result references to reduce context pressure.

    3. The Tool System Is Key to Production Agents

    Without tools, a model can only generate suggestions; with tools, an agent can actually complete real tasks. Tool design should follow the principles of “clear capability, well-defined boundaries, validatable inputs, and parseable outputs.”

    Tools can be grouped into several categories:

    • Information retrieval: Searching resources, reading files, querying databases.
    • Computation and processing: Running statistical analysis, data transformation, and rule validation.
    • Content generation: Producing documents, spreadsheets, or structured reports.
    • Business operations: Submitting approvals, updating records, sending notifications.
    • System administration: Creating tasks, checking run status, triggering deployment flows.

    Tool descriptions should not merely say “perform an operation”—they should specify input fields, data types, required conditions, error formats, and permission requirements. For example, a query tool should constrain query scope, result limits, and accessible data domains, preventing the model from generating overly broad or unauthorized requests.

    Tool results should also remain structured:

    1. {
    2. "success": true,
    3. "data": {
    4. "count": 128,
    5. "summary": "Several anomalous records found"
    6. },
    7. "error": null
    8. }

    When execution fails, machine-readable error types should be returned, such as invalid arguments, insufficient permissions, resource not found, or service timeout. This allows the model to decide whether to correct parameters, ask the user for more information, or end the task—instead of continuing on guesswork.

    4. Task Orchestration and State Management

    Complex tasks rarely finish in a single call. The Harness needs orchestration capability to break tasks into traceable steps, with clear preconditions and completion criteria for each step.

    Common orchestration patterns include:

    1. Sequential execution: For tasks with strict dependencies.
    2. Parallel execution: For multiple independent data collection or analysis steps.
    3. Conditional branching: Choosing different flows based on intermediate results.
    4. Looping: For item-by-item checks, paginated reads, and iterative refinement.
    5. Human confirmation: Pausing before high-risk actions until the user authorizes them.

    State management should not rely solely on conversation text. Production systems should assign each task a unique identifier and record the current stage, completed steps, pending actions, error counts, and final results. This way, even after a process restart, tasks can be resumed instead of starting over.

    For operations with side effects—such as modifying data or sending notifications—you also need idempotency mechanisms. The system should use request identifiers, operation records, or status checks to prevent duplicate execution caused by retries.

    5. Context Management and Memory

    An agent’s context typically consists of four parts: system rules, user goals, interaction history, and tool results. Longer context does not mean better performance—too much irrelevant information degrades the model’s judgment.

    A more reliable approach is layered management:

    • Short-term context: Recent information needed for the current task.
    • Task memory: Key conclusions and execution progress for the current task.
    • Long-term memory: Filtered user preferences, business rules, and historical facts.
    • External knowledge: Loaded on demand via retrieval, rather than injected wholesale.

    Memory writes must go through filtering and access control. Unverified inferences should not be stored as long-term facts; sensitive information requires masking, encryption, and access auditing.

    6. Security Cannot Rely on the Model’s Judgment

    Models may misinterpret instructions or be manipulated by malicious input. Security boundaries must therefore be enforced by the Harness, not left to prompts alone.

    Security design should cover at least the following:

    • Tool allowlists and least-privilege access;
    • Validation of parameter formats, ranges, and content;
    • Secondary confirmation for sensitive operations;
    • Filesystem, network, and data domain isolation;
    • Binding user identity to task permissions;
    • End-to-end logging and auditing;
    • Timeouts, rate limiting, and resource quotas;
    • Filtering sensitive information in outbound outputs.

    For example, a model may propose a plan to “delete a batch of data,” but before actual execution, the Harness should verify the operator’s permissions, target scope, number of affected records, and whether valid approval exists. For irreversible operations, it’s best to provide previews, dry-run execution, or rollback mechanisms.

    7. Observability and Evaluation

    The quality of an agent system should not be judged solely by whether the final answer reads well—the entire execution process matters. Recommended metrics to track include:

    • Task success rate;
    • Tool call success rate;
    • Average execution latency;
    • Number of model calls;
    • Retry count;
    • Ratio of human interventions;
    • Resource consumption per task;
    • Distribution of error types;
    • Accuracy and completeness of results.

    Logs should include task identifiers, step identifiers, tool names, input summaries, output summaries, and timing—while avoiding logging unnecessary sensitive data.

    For evaluation, build datasets covering normal, abnormal, and adversarial scenarios. For example, test whether the agent proactively asks questions when information is missing, retries sensibly when tools fail, refuses execution when permissions are insufficient, and maintains boundaries when user requests conflict with security rules.

    8. From Prototype to Production

    A phased approach is recommended:

    Phase one: Build a minimal closed loop with a single task and a few tools, validating that the model can correctly understand goals and perform basic calls.

    Phase two: Introduce structured state, error handling, context trimming, and task recovery mechanisms to move from “occasionally works” to “reliably works.”

    Phase three: Add permission systems, audit logs, human confirmation, resource controls, and monitoring so the agent can enter a controlled production environment.

    Phase four: Extend to multi-agent collaboration, asynchronous tasks, knowledge retrieval, and cross-system orchestration based on business needs. At this stage, prioritize clear boundaries rather than blindly adding more models or tools.

    Conclusion

    The core value of “Model + Harness = Agent” lies in transforming a model’s reasoning capability into executable, recoverable, and auditable engineering capability. The model determines whether an agent can understand problems and form plans; the Harness determines whether those plans can be implemented safely, stably, and consistently.

    For development teams, building an agent system is not simply about plugging in a model—it is about establishing a complete runtime around tools, state, permissions, context, observability, and evaluation. Only by combining intelligence with engineering governance can agents move beyond demos and become reliable components of real software systems.