Skip to main content

Harness Patterns

A “harness” is the code around your @llm_chat agent that manages state, context planning, and orchestration. The framework gives you the ReAct loop; you build the harness that makes it production-ready.

Core Philosophy

An agent is not a person. It is a method for constructing the right context for each reasoning step.
The harness engineer’s job:
  1. Ensure the model sees the shortest complete context at every step
  2. Persist state so sessions can be resumed deterministically
  3. Encode lessons into the environment, not into operator memory

Pattern 1: TUI General Agent

The canonical pattern from examples/tui_general_agent_example.py:
The harness layer (agent) wraps the core agent to:
  • Inject compaction instructions when context is large
  • Build dynamic template parameters (environment detection, workspace info)
  • Prepare history format
  • Route abort signals
  • Connect to the TUI

Pattern 2: Context Window Management

This pattern keeps context fresh without manual intervention.

Pattern 3: Dynamic Environment Block

Inject runtime context via template parameters:

Pattern 4: Supervisor Agent

An outer agent that delegates to specialized inner agents:
The supervisor pattern enables:
  • Different models for different tasks (cheap model routes, expensive model implements)
  • Isolated context per specialist (each starts fresh)
  • Clear delegation boundaries

Pattern 5: Session Persistence

Persist history externally for resume:

Pattern 6: Custom Tool Runtime Override

Override which tools the agent sees based on context:

The Key Insight

The harness is where context engineering happens:
  • What the model sees = what you put in the template params + history + tool results
  • When the model forgets = when you fail to compact or persist
  • Why the model fails = usually missing context, not missing capability
Build harnesses that make the right context inevitable, not optional.