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:
- Ensure the model sees the shortest complete context at every step
- Persist state so sessions can be resumed deterministically
- Encode lessons into the environment, not into operator memory
Pattern 1: TUI General Agent
The canonical pattern fromexamples/tui_general_agent_example.py:
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
Pattern 3: Dynamic Environment Block
Inject runtime context via template parameters:Pattern 4: Supervisor Agent
An outer agent that delegates to specialized inner agents:- 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