中文 EN
← Back to Home

Harness Engineering: The Engineering Art of Steering AI Agents

Harness Engineering Cover
Core Formula: Agent = Model + Harness

"Harness engineering is the idea that anytime you find an agent makes a mistake, you take the time to engineer a solution such that the agent will not make that mistake again in the future."
— Mitchell Hashimoto (HashiCorp co-founder, Terraform co-creator), February 2026

I. What is Harness Engineering?

The most important paradigm shift in AI in 2026 isn't larger models — it's Harness Engineering: building systems, tools, constraints, and feedback loops around AI Agents so that powerful but unpredictable AI models can reliably accomplish complex tasks.

Harness is not Prompt Engineering. Prompt Engineering cares about "what to say to the model," while Harness Engineering cares about "what to build around the model." The former is fragile and model-dependent; the latter is robust and model-agnostic.

An analogy to understand the distinction:

LLM is the brain; Harness is the body. Without Harness, the model can only "theorize"; with Harness, AI becomes a true "doer."

II. Agent = Model + Harness

This formula is becoming industry consensus:

ComponentResponsibilityExample
ModelIntelligence, reasoning, decision-makingClaude, GPT-4, DeepSeek
HarnessHands, eyes, memory, safety boundariesTools, permissions, memory, verification loops

Key Insight: An excellent Harness is often more important than a better Model.

The LangChain Terminal Bench 2.0 comparison experiment proved this:

The optimizations included only: better context files (AGENTS.md), structured output constraints, self-verification loops, and tool optimization. No model change, no prompt change.

III. Seven Core Components of a Harness

1. Context Engineering

Give the Agent a "map" of the codebase, not a "1000-page manual."

Core Principle: Context file ≤ 60 lines. Anything longer causes Agent attention drift.

# CLAUDE.md / AGENTS.md example
## Architecture
- src/app/ — Main application logic
- src/lib/ — Shared utility library
- src/components/ — React components

## Rules
- All API calls go through src/lib/api.ts
- No direct node_modules imports in components
- Commit messages in English

2. Architectural Constraints

Don't rely on hope — rely on enforcement. Use lint rules, tests, and type systems to forcibly constrain Agent behavior, rather than expecting it to "voluntarily" comply.

"Constrain the solution space — don't expand it. Fewer valid options means fewer wrong answers."

3. Tools & MCP Servers

The Agent's hands and feet. Giving the model the ability to interact with the external world.

4. Sub-Agents & Context Firewalls

Context is a consumable. In long sessions, model performance degrades as context accumulates (context rot).

Solutions:

Anthropic's dual-Agent architecture:

  1. Initializer Agent — makes the plan, generates feature list
  2. Coding Agent — executes each feature one by one

5. Hooks & Back-Pressure

Automated feedback loops that catch errors before they compound.

"Success should be silent; failure should be loud." — Only push errors into Agent context; don't drown it in redundant success logs.

6. Self-Verification Loops

Force the Agent to verify its own work before marking a task complete:

"This is the difference between an agent that 'thinks it's done' and one that actually is."

7. Progress Documentation

For tasks longer than ~30 minutes, maintain structured progress records to ensure replacement sessions can seamlessly resume.


IV. Can WorkBuddy Use a Harness?

Yes — and WorkBuddy itself is a Harness.

WorkBuddy (CodeBuddy) implements multiple core components of Harness Engineering:

Harness ComponentWorkBuddy Implementation
Context EngineeringSOUL.md / IDENTITY.md / USER.md / MEMORY.md working memory system
ToolsComplete toolset (File I/O, Shell, Web, Agent, Task)
HooksAutomated triggers, scheduled tasks
PermissionsSecurity policies (content_policy, personal_files_safety, working_modes)
Sub-AgentsAgent tool (sub-Agent dispatch, TeamCreate)
Self-VerificationIterative verification in the Agent Loop
ProgressTaskCreate/Update/List task management system
MemoryCross-session persistent memory (MEMORY.md + daily logs)

As a WorkBuddy user, you can directly leverage these Harness capabilities:

  1. Write AGENTS.md / SOUL.md: Define Agent behavior specs, project architecture, coding rules
  2. Use the Skills system: Load domain knowledge on demand
  3. Leverage Task management: Break down complex tasks, track progress
  4. Build MEMORY.md: Accumulate cross-session knowledge, making the Agent "understand you better over time"
  5. Custom Automations: Scheduled tasks and event-driven automation

Advanced tip: WorkBuddy users can build a powerful personal Harness through quality SOUL.md + MEMORY.md configuration, without writing a single line of code.


V. How to Use Harness for a Custom OpenClaw

Option 1: Integrate OpenHarness

OpenHarness is a lightweight Agent Harness framework open-sourced by HKU (12.2K+ Stars), implementing 80% of Claude Code's core architecture in 11,000 lines of Python.

# 1. Install OpenHarness
pip install openharness-ai

# 2. Configure model provider
oh setup
# Provider: anthropic → Claude series
# Provider: openai → GPT-4
# Provider: deepseek → DeepSeek
# Provider: ollama → Local open-source models

# 3. Create project CLAUDE.md
cat > CLAUDE.md << 'EOF'
## Project: OpenClaw Custom Agent
## Architecture
- src/core/ — Agent loop & tool execution
- src/tools/ — Custom tools
- src/memory/ — Persistent memory

## Rules
- All API calls go through src/lib/gateway.ts
- Commit messages in English
- Tests required for new tools
EOF

# 4. Launch Harness
oh

Option 2: Build Core Harness Components from Scratch

# Minimal usable Harness implementation
class AgentHarness:
    def __init__(self, model, tools, memory_path="MEMORY.md"):
        self.model = model
        self.tools = tools          # Tool registry
        self.memory = self.load_memory(memory_path)
        self.constraints = []       # Architecture constraint rules
        self.hooks = {"pre": [], "post": []}  # Lifecycle hooks

    def run(self, task):
        # 1. Inject context
        context = self.build_context(task)

        # 2. Agent Loop
        while not done:
            response = self.model.stream(messages, self.tools)

            if response.has_tool_calls:
                # Permission check → Hook → Execute → Result
                for tool_call in response.tool_calls:
                    if self.check_permission(tool_call):
                        self.run_hooks("pre", tool_call)
                        result = self.execute(tool_call)
                        self.run_hooks("post", tool_call, result)
                        messages.append(result)
            else:
                done = True

        # 3. Self-verification
        self.verify(result)

        # 4. Update memory
        self.save_memory()

        return result

Key Practices Checklist

PracticeHow
ContextMaintain a ≤60 line CLAUDE.md in project root
MemoryAuto-maintain MEMORY.md, recording preferences, known issues, architecture decisions
ToolsPrefer standard CLIs (git, npm) — agents are naturally familiar with them
PermissionsPath whitelist + block dangerous commands (rm -rf, git push --force)
VerificationAuto-run lint + test after every code change
SplittingUse sub-Agents for complex tasks, each in an independent session
ProgressStructured task list + frequent commits

VI. Harness vs. Prompt Engineering

Prompt EngineeringHarness Engineering
FocusWhat to say to the modelWhat to build around the model
DurabilityFragile, model-dependentRobust, model-agnostic
Compound EffectDoes not improve over timeStronger with each iteration
ScopeSingle interactionEntire workflow
Skill TypeWritingSystems engineering

VII. Conclusion

The AI competition in 2026 has shifted from "whose model is stronger" to "whose Harness is better." Mitchell Hashimoto's insight changed everything:

"The model is the engine; the harness is the car. No one wins a race with just an engine."

For WorkBuddy users: you're already using a Harness today — by optimizing SOUL.md, MEMORY.md, and Skills, you can continuously improve its capabilities.

For OpenClaw custom builders: OpenHarness provides a proven starting point. There's only one core principle: every time the Agent makes a mistake, invest time in designing an engineering solution so it won't make the same mistake again.

That's Harness Engineering — the engineering art of taking AI from "works" to "reliable."