← Back to list

Harness Engineering: Building Production-Grade AI Systems Beyond Prompts and Context

How to design the ‘outside’ of the model — filesystem, tools, orchestration, and feedback loops that actually ship.

Jerry Shao · 2026-03-28 13:49 · 0 claps · 15.6 min read
#ai-engineering-2026 #llmops #ai-production #system-prompt #agentic-ai-architecture
Open on Medium ↗
Wiki topics: LLM · Large Language Models AGT · AI Agents OPS · LLMOps & Inference 🏛️ · Architecture

Harness Engineering: Building Production-Grade AI Systems Beyond Prompts and Context

How to design the ‘outside’ of the model — filesystem, tools, orchestration, and feedback loops that actually ship.

Harness Engineering: The Missing Layer Behind AI Agents

Harness Engineering: The Missing Layer Behind AI Agents

Introduction

Harness engineering represents the next critical evolution in AI development — shifting the focus from models themselves to the systems that surround and operationalize them. While prompt engineering refines how we ask models to behave, and context engineering optimizes what models see, harness engineering governs the full execution environment in which agents operate. It is this surrounding system — filesystem, tools, orchestration, memory, and feedback loops — that ultimately determines whether an AI application is reliable, reproducible, and production-ready.

This shift marks a transition from model-centric to system-centric thinking. For years, progress in AI was measured by improving model capabilities through training. However, as large language models have become increasingly powerful, the bottleneck has moved outward. The challenge is no longer just intelligence — it is control, consistency, and integration. Harness engineering addresses these challenges by enforcing structure, managing state, and embedding safeguards that prevent “system-level deviations” that prompt or context engineering alone cannot resolve.

The concept gained traction in early 2026 when Mitchell Hashimoto introduced the idea of “engineering the harness,” emphasizing that real-world AI systems are not defined solely by models. In practice, an effective agent can be understood as:

Agent = Model + Harness

The model provides raw intelligence, but the harness transforms that intelligence into dependable behavior. It enables agents to plan, act, verify, and improve within complex workflows — turning probabilistic outputs into deterministic systems.

As organizations move from experimentation to production, this distinction becomes decisive. Success is no longer determined by how clever a prompt is, but by how well the surrounding system constrains, guides, and validates the model. Harness engineering is therefore not an optimization layer — it is the foundation for building AI systems that actually ship.

The Six Components of Harness Architecture

The deepagents-demo repository (cloned from deepagents’s examples) offers a practical blueprint for harness engineering, breaking it down into six tightly integrated components. Together, these form the execution layer that transforms a raw model into a production-grade agent system. Each component addresses a specific gap in model capability — collectively enabling reliability, persistence, and controlled autonomy.

At a high level, the principle is simple: a model alone is not enough. Every missing capability — state, execution, memory, external access, control, and coordination — is supplied by the harness.

Harness Architecture

Harness Architecture

1. Filesystem — Durable State and Working Memory

The filesystem provides the agent with a persistent workspace for inputs, outputs, intermediate artifacts, and logs. Unlike ephemeral context windows, it enables continuity across runs and long-lived tasks.

This component turns stateless interactions into stateful workflows, allowing agents to:

  • Persist progress across sessions
  • Store intermediate reasoning artifacts
  • Integrate naturally with Git for versioning, rollback, and collaboration

Without a filesystem, every task starts from scratch. With it, agents can accumulate and refine work over time.

2. Bash + Sandbox — Safe Execution and Iteration Loop

This layer gives the agent the ability to act, not just describe. By executing commands and running code inside a controlled sandbox, the agent can implement, test, and refine solutions autonomously.

Key capabilities include:

  • Code execution with isolation guarantees
  • Write → run → inspect → fix iteration loops
  • Reproducible environments with safety constraints

The sandbox is critical — it ensures that increased capability does not come at the cost of security or stability.

3. Memory (AGENTS.md) — Persistent Knowledge and Behavior

Memory externalizes knowledge that should persist beyond a single run. Stored in structured artifacts like AGENTS.md, it captures instructions, policies, and reusable workflows.

This enables:

  • Consistent behavior across executions
  • Incremental learning without retraining the model
  • Explicit, inspectable, and editable knowledge storage

In effect, memory becomes the agent's long-term brain — separate from model weights and fully under system control.

4. Web Search + MCP — External Awareness and Tooling

No model is fully up to date or self-sufficient. This component connects the agent to the outside world — bringing in fresh information and enabling interaction with external systems.

It includes:

  • Web search for real-time or missing knowledge
  • MCP (Model Context Protocol) for standardized tool integration
  • Access to APIs, services, and enterprise systems

This transforms the agent from an isolated reasoner into a connected operator capable of acting in dynamic environments.

5. Context Engineering — Controlled Attention and Focus

Context engineering determines what information the model sees — and just as importantly, what it does not see. It governs how context is constructed, filtered, and updated over time.

Core mechanisms include:

  • Planning and task decomposition
  • Delegation to sub-agents or tools
  • Progressive disclosure of information
  • Context compression and reset strategies

The goal is to prevent context bloat and drift, ensuring the model remains focused, relevant, and efficient throughout execution.

6. Orchestration + Hooks — Execution Control and Governance

This is the control plane of the harness — coordinating agents, tools, and workflows while enforcing runtime policies.

It enables:

  • Sub-agent coordination and routing
  • Approval workflows and human-in-the-loop checkpoints
  • Middleware and hooks for enforcing constraints at execution time
  • Policy enforcement beyond prompts

Orchestration transforms a collection of capabilities into a coherent, governable system, ensuring that agents behave predictably under real-world conditions.

Putting It Together

Each component individually addresses a specific limitation of LLMs. Together, they form a complete system:

  • Filesystem provides persistence
  • Sandbox enables safe action
  • Memory ensures continuity
  • External tools expand capability
  • Context engineering maintains focus
  • Orchestration enforces control

This layered architecture is what turns probabilistic model outputs into deterministic, production-ready behavior. The harness is not a single feature — it is the system that makes everything else work.

Core Concepts and Frameworks

Harness engineering is not a single pattern but a system of reinforcing control mechanisms. To make it practical, two complementary lenses help structure the space:

  • The Four Quadrants Framework (how systems operate), and
  • The Seven Pillars (what capabilities must exist).

Together, they provide both an operating model and a design checklist for production-grade AI systems.

The Four Quadrants Framework

At its core, harness engineering organizes around four interconnected quadrants that govern how an agent system behaves over time. Each quadrant addresses a distinct failure mode in real-world deployments.

1. Architecture Constraints — Enforcing Correctness by Design

Architecture constraints ensure that systems cannot violate core design principles. Instead of relying on developer discipline or prompt instructions, these constraints are enforced mechanically.

Examples include:

  • Linters and static analysis for agent/tool boundaries
  • Structural tests validating workflow composition
  • Dependency rules preventing unauthorized coupling

The key idea is simple: prevent bad states rather than detect them later.

2. Feedback Loops — Measuring What Matters, Fast

Feedback loops continuously validate system quality. In harness engineering, the speed of feedback is often more important than its sophistication.

This spans multiple timescales:

  • Milliseconds: runtime hooks (e.g., PostToolUse validation)
  • Seconds: task-level checks and retries
  • Minutes: CI/CD pipelines and regression suites

Instrumentation typically includes:

  • Observability (traces, logs, metrics)
  • Automated evaluation pipelines
  • Quality scoring and anomaly detection

The governing principle: what you can’t measure, you can’t stabilize.

3. Workflow Control — Governing Execution and Autonomy

Workflow control defines how agents act — what they are allowed to do, in what order, and under what constraints.

Key mechanisms include:

  • Task decomposition and structured planning
  • Parallelization with bounded concurrency
  • Permission management and scoped tool access
  • Human-in-the-loop (HITL) checkpoints

Effective workflow control prevents:

  • Unauthorized or unsafe actions
  • Execution drift over long tasks
  • Resource overuse (tokens, tools, time)

In essence, this quadrant turns open-ended reasoning into bounded, governable execution.

4. Improvement Cycles — Sustaining Quality Over Time

AI systems degrade without maintenance. Improvement cycles ensure that quality is not just achieved — but sustained.

Core practices include:

  • Entropy management (cleaning stale memory, prompts, artifacts)
  • Automated refactoring and cleanup processes
  • Documentation freshness and alignment with behavior
  • Continuous evaluation and iterative refinement

This quadrant addresses a critical reality: AI systems are living systems, and require ongoing care to remain reliable.

The Seven Pillars of Production-Grade Harness

If the quadrants describe how systems operate, the seven pillars define what must be in place for a harness to be production-ready. These components form the minimal capability set for reliable agent execution.

1. Intent Compiler — From Ambiguity to Specification

Transforms vague user requests into structured, machine-readable task definitions. This reduces ambiguity and enables consistent execution across runs.

2. Context Indexing & Dynamic Delivery — Relevance at Runtime

Maintains an intelligent map of available knowledge and delivers only what is relevant at each step, including “what changed since the last run.” This prevents context overload while preserving continuity.

3. Tool Pruning & Deterministic Wrappers — Safe Capability Exposure

Restricts the agent to a minimal, well-defined set of tools with explicit contracts. Deterministic wrappers ensure predictable inputs/outputs, reducing variability and failure modes.

4. Orchestration Brain Stem — Structured Execution Loops

Implements the core plan → act → verify cycle, including sub-task decomposition, coordination, and state checkpointing. This is the execution backbone of the harness.

5. Verification Hooks — Quality Gates Before Output

Applies pre-completion validation through checklists, automated graders, and rule-based verification. This ensures outputs meet defined standards before being returned.

6. Trace-Driven Telemetry — Full-System Observability

Captures detailed traces of all LLM calls, tool invocations, and decision paths. This enables debugging, optimization, and regression analysis at scale.

7. Safety & Permission Sandboxing — Controlled Autonomy

Enforces least-privilege access, explicit approvals, and runtime safeguards. This ensures that increased agent capability does not compromise security or governance.

Bringing the Frameworks Together

The Four Quadrants and Seven Pillars are complementary:

  • Quadrants define system behavior over time
  • Pillars define required system capabilities

A useful mental model:

  • Constraints and safety come from Architecture + Sandboxing
  • Reliability comes from Feedback + Verification + Telemetry
  • Scalability comes from Workflow Control + Orchestration
  • Longevity comes from Improvement Cycles + Context Management

Together, these frameworks move AI systems beyond experimentation into repeatable, governable, and production-grade operation.

Harness engineering is ultimately about one thing: turning probabilistic intelligence into deterministic systems.

Real-World Implementation: The Deep Research Agent

To ground these concepts in reality, let’s examine a practical implementation: the Deep Research Agent — a demo designed to autonomously explore, synthesize, and validate information across diverse sources.

At first glance, a research agent may seem like a straightforward application of prompting and retrieval. In practice, however, it quickly becomes a complex orchestration problem. The agent must navigate ambiguity, manage long-running workflows, and continuously evaluate the quality of its own outputs. This is precisely where harness architecture becomes essential.

Architecture in Practice — From Prompting to Orchestration

The Deep Research Agent is not a single model call — it is a coordinated system composed of multiple interacting components:

  • Task Decomposition Engine: Breaks down high-level research questions into structured sub-tasks
  • Planning Module: Dynamically determines execution order and adapts based on intermediate results
  • Tooling Layer: Integrates with search APIs, document stores, and external knowledge systems
  • Memory System: Maintains both short-term context and persistent research artifacts
  • Evaluation Harness: Continuously scores relevance, accuracy, and completeness of findings
  • Control Loop: Governs iteration, retry logic, and stopping conditions

This transforms the agent from a reactive responder into a goal-driven system capable of sustained reasoning over time.

Key Implementation Details

Strategic Delegation Pattern:

# From research_agent/prompts.py - SUBAGENT_DELEGATION_INSTRUCTIONS
"""
Concrete delegation strategies with examples:
- Simple queries: 1 sub-agent
- Comparisons: 1 per element  
- Multi-faceted research: 1 per aspect
Limits: max 3 concurrent, max 3 iteration rounds
"""

Research Workflow:

RESEARCH_WORKFLOW_INSTRUCTIONS = """
5-step research workflow:
1. Save request to workspace
2. Plan with TODOs (batch similar tasks, scale rules for query types)
3. Delegate to sub-agents (parallel execution with limits)
4. Synthesize findings
5. Respond with final report
"""

Custom Tools with Deterministic Contracts:

  • tavily_search: URL discovery engine with HTTP fetching and markdown conversion
  • think_tool: Strategic reflection mechanism between searches
  • read_pdf_folder: Local document ingestion
  • generate_slide_markup: Structured output formatting

Harness in Action

The defining characteristic of this implementation is not intelligence at the model level, but control at the system level.

Each step in the research process is instrumented and evaluated:

  • Intermediate outputs are validated before being propagated
  • Sources are cross-checked to reduce hallucination risk
  • Confidence scores inform whether to continue, refine, or terminate
  • Failures trigger fallback strategies rather than silent degradation

This is the harness operating as a governance layer, ensuring that the agent behaves predictably under real-world conditions.

Iteration, Not Perfection

A key insight from deploying the Deep Research Agent is that production reliability emerges from an iteration loop, not from perfect prompts.

The system is explicitly designed to:

  • Revisit weak or conflicting findings
  • Expand or narrow the search space dynamically
  • Incorporate new evidence into prior conclusions
  • Maintain traceability across the entire reasoning chain

This iterative capability is what enables the agent to handle open-ended, ambiguous research tasks — something static prompt pipelines cannot achieve.

Observability and Trust

In production environments, trust is non-negotiable. The Deep Research Agent addresses this through deep observability:

  • Full trace logs of decisions and tool usage
  • Source attribution for every synthesized insight
  • Scoring metrics for quality and confidence
  • Replayability for debugging and audit

This transparency transforms the agent from a “black box” into a traceable, inspectable system, making it suitable for enterprise use cases.

Performance Impact and Benefits

Large Language Models are inherently non-deterministic. Harness architecture introduces guardrails — evaluation loops, validation layers, and fallback strategies — that convert unpredictable outputs into consistent, production-grade behavior.

  • Reduced hallucination rates through iterative validation
  • Stable outputs across repeated runs
  • Built-in failure handling and recovery mechanisms

The result: AI systems you can trust in mission-critical workflows.

Quantifiable Results

The impact of harness engineering is evident across the industry:

  • GroK Code Fast Experiment: Improved from 6.7% to 68.3% on coding benchmarks through harness modifications alone — a tenfold improvement without model changes
  • LangChain’s Terminal Bench: Same model jumped from 30th to 5th place (13.7-point improvement) through harness engineering
  • Output Token Reduction: ~20% reduction through improved harness design
  • Development Speed: OpenAI built a 1-million-line product in 5 months with zero hand-written code — approximately 10x faster than manual development

The Deep Research Efficiency Gains

The repository’s deep research implementation demonstrates specific efficiency patterns:

  • Parallel Sub-agent Execution: Batches similar research tasks to reduce overall latency
  • Token Optimization: Uses Tavily for URL discovery only, fetches full content via HTTP to avoid token-heavy summarization
  • Deterministic Tool Boundaries: Hard limits on search iterations prevent runaway token consumption
  • State Persistence: Filesystem backend allows resuming long-running research tasks

The true value of harness architecture lies in its ability to bridge the gap between LLM potential and production reality. It transforms AI systems from experimental tools into robust, efficient, and enterprise-ready platforms — capable of delivering sustained, measurable impact at scale.

Implementation Approaches

Translating harness architecture from concept into production requires deliberate design choices. There is no single “correct” implementation — only trade-offs shaped by system complexity, scale, and organizational maturity. The following approaches represent proven patterns for operationalizing harness engineering in real-world AI systems.

Minimal Viable Harness Template

For teams starting with harness engineering, the repository suggests:

  • Task spec compiler: Formalize user intent into structured specifications
  • Small essential toolset: Expose only relevant tools with crisp contracts (as seen in the deep research agent’s limited toolset: tavily_search, think_tool, write_file, read_file)
  • Basic plan-act loop: The 5-step research workflow demonstrates this pattern
  • Pre-completion verification: Research sub-agents verify coverage before synthesis
  • Basic tracing: LangSmith integration for observability
  • Regression eval set: Test queries to validate harness behavior

1. Monolithic Harness (Embedded Control)

In early-stage systems, the harness often lives directly within the application layer. Orchestration logic, prompt construction, tool invocation, and response handling are tightly coupled within a single service.

This approach prioritizes speed and simplicity. Teams can iterate quickly, experiment with prompts, and validate core workflows without investing in additional infrastructure.

uv run python research_agent.py "Research AI Agents" --pdf-folder ./docs --slides

However, this tight coupling becomes a liability as complexity grows. Changes to orchestration logic require full redeployments, observability is limited, and reuse across use cases is minimal.

Best suited for:

  • Prototyping and MVPs
  • Low-complexity workflows
  • Small teams prioritizing velocity over scalability

2. Modular Harness (Service-Oriented Composition)

As systems mature, the harness evolves into a set of modular, loosely coupled components. Core capabilities — such as orchestration, memory management, tool routing, and evaluation — are separated into distinct services or layers.

This modularity enables independent scaling, testing, and iteration. Teams can upgrade components (e.g., swap a retrieval strategy or introduce a new evaluation pipeline) without disrupting the entire system.

More importantly, it introduces clear contracts between components, making the system easier to reason about and extend.

Key characteristics:

  • Separation of concerns across harness components
  • Reusable orchestration patterns
  • Improved observability and debugging
  • Easier integration with enterprise systems

Best suited for:

  • Production systems with multiple workflows
  • Teams adopting platform engineering practices
  • Environments requiring flexibility and extensibility

3. Event-Driven Harness (Reactive and Scalable)

For high-scale, asynchronous workloads, an event-driven architecture provides a powerful alternative. Instead of linear request-response flows, the harness reacts to events — triggering orchestration steps, tool invocations, or evaluations as needed.

This model enables parallelism, resilience, and decoupling. Long-running tasks (e.g., research agents, multi-step reasoning pipelines) can be distributed across workers, with state managed through event streams or queues.

It also aligns naturally with agentic systems, where workflows are dynamic rather than predefined.

Key advantages:

  • Horizontal scalability
  • Fault tolerance through retry and replay mechanisms
  • Natural fit for multi-agent and long-running processes

Challenges:

  • Increased operational complexity
  • Requires robust state and event management
  • Harder to debug without strong observability

Best suited for:

  • Deep research agents and autonomous workflows
  • High-throughput AI platforms
  • Systems requiring resilience and distributed execution

4. Platform-Based Harness (Internal AI Control Plane)

At the highest level of maturity, organizations consolidate harness capabilities into a shared internal platform. This “AI control plane” abstracts orchestration, memory, tools, and evaluation behind standardized APIs and SDKs.

Instead of building harness logic per application, teams build on top of the platform, accelerating development while enforcing consistency and governance.

This approach unlocks organizational scale:

  • Centralized observability and evaluation
  • Governance, compliance, and guardrails by design
  • Rapid reuse of proven patterns across teams

It also enables continuous improvement loops, where learnings from one application enhance the entire ecosystem.

Best suited for:

  • Large enterprises with multiple AI applications
  • Organizations prioritizing governance and standardization
  • Teams investing in long-term AI platform strategy

Choosing the Right Approach

These approaches are not mutually exclusive — they represent an evolutionary path. Most organizations start with a monolithic harness, transition to modular architectures, and eventually adopt event-driven or platform-based models as their needs expand.

The key is to align architecture with ambition:

  • If you’re exploring → optimize for speed
  • If you’re scaling → optimize for modularity
  • If you’re orchestrating complexity → optimize for events
  • If you’re industrializing AI → build a platform

Harness engineering is ultimately about control at scale. The right implementation approach ensures your system remains adaptable, observable, and resilient — no matter how sophisticated the underlying models become.

Design Philosophy and Evolution

The “Bitter Lesson” Principle

As Phil Schmid emphasizes, “general methods using computation beat hand-coded human knowledge.” As models improve, complex control flows become unnecessary. This drives a philosophy of modularity — build harnesses that allow easy removal of custom logic, making the architecture ready for new model updates.

The deep research agent embodies this through its declarative instruction sets (RESEARCH_WORKFLOW_INSTRUCTIONS, etc.) that can be easily modified or removed as models become more capable of self-directing research.

Relationship to Prompt and Context Engineering

The containment view suggests: harness ⊇ context ⊇ prompt, meaning prompt engineering operates within a context framework, which operates within harness.

The complementarity view provides practical distinctions:

  • Context engineering asks: “What do we show the agent?”
  • Harness engineering asks: “What does the system prevent, measure, and fix?”

A practical heuristic: Single-output issues typically indicate context problems, while quality degradation over time indicates harness problems.

Challenges and Limitations

Field Maturity

Harness engineering remains an emerging field, having crystallized only in early 2026. Definitions and approaches vary significantly across organizations. The repository demonstrates this evolution through its iterative examples (the deep research agent represents one pattern among several in the repo).

Metaphor and Terminology

The “harness” metaphor implies controlling an entity, which becomes problematic as AI autonomy increases. The repository’s implementation — particularly the ralph_mode example showing autonomous looping with fresh context—demonstrates the tension between control and autonomy.

Complexity and Maintenance

While harness engineering offers benefits, it introduces complexity. The repository shows this through:

  • Multiple middleware layers (PatchToolCallsMiddleware, SummarizationMiddleware)
  • Sub-agent orchestration logic
  • State management across distributed components

Over-engineering harnesses can run counter to model evolution and require frequent rewrites .

Common Anti-Patterns to Avoid

The repository examples help illustrate what NOT to do:

  • One giant system prompt: Instead, the deep research agent splits instructions into three focused files (RESEARCH_WORKFLOW_INSTRUCTIONS, SUBAGENT_DELEGATION_INSTRUCTIONS, RESEARCHER_INSTRUCTIONS)
  • Giving every tool to the LLM: The deep research agent exposes only 4–5 carefully selected tools with specific contracts
  • Shipping without verification: The agent includes think_tool for self-reflection and synthesis verification
  • Relying only on logging: LangSmith tracing provides comprehensive telemetry beyond simple logs

Future Directions

Emerging Trends

  • Convergence of training and inference environments: As models become more sophisticated, development and deployment environments blur
  • Context durability: Focus on maintaining consistent context over long-running tasks (demonstrated by the deep research agent’s filesystem persistence)
  • Model drift detection: Mechanisms for detecting when models stop following instructions, feeding data back into training
  • Competitive advantage shifting: From prompts to the trajectories harnesses capture, enabling sophisticated capabilities through system design

Research Opportunities

  • Automated harness optimization: Systems that tune harness parameters based on performance data
  • Standardized frameworks: Adaptable harness patterns across different use cases (the repository’s six-component model is one approach)
  • Cross-modal harnesses: Extending principles beyond text to multimodal systems
  • Human-AI collaboration patterns: New frameworks for oversight as seen in the repository’s interrupt_on hooks for human approval

Conclusion

Harness engineering represents a fundamental shift in AI development — from model-centric to system-centric thinking. While prompt and context engineering optimize what goes into LLMs, harness engineering addresses the surrounding environment that determines how effectively those models deploy in real-world scenarios.

The deepagents-demo repository provides concrete evidence that well-designed harnesses deliver dramatic improvements:

  • 10x performance gains on benchmarks without model changes
  • 10x development speed through reliable automation
  • Sustainable complexity through the six-component architecture

As AI capabilities advance, harness engineering becomes increasingly critical for managing complex, long-running workflows. The principles of modular design, observability, and continuous improvement — exemplified by the deep research agent’s planning, delegation, and verification patterns — will become essential skills for AI developers.

For organizations seeking to leverage LLMs effectively, investing in robust harness infrastructure is not just an optimization but a necessity. As models continue to improve, the systems surrounding them will determine how effectively those improvements translate into real-world value.

The repository’s final insight resonates: these examples are better understood as harness patterns for agents, not just prompt examples. The future belongs not to those who engineer better prompts, but to those who engineer better harnesses.

Sources


메타데이터
post_id
5fcdffdd6b4c
slug
harness-engineering-building-production-grade-ai-systems-beyond-prompts-and-context-5fcdffdd6b4c
url
https://medium.com/@jerry.shao/harness-engineering-building-production-grade-ai-systems-beyond-prompts-and-context-5fcdffdd6b4c
canonical_url
https://medium.com/@jerry.shao/harness-engineering-building-production-grade-ai-systems-beyond-prompts-and-context-5fcdffdd6b4c
author_url
https://medium.com/@jerry.shao
status
ok
fetched_at
2026-06-09 15:37:30