Ever built an AI agent that pretends it's finished before it actually should be? You're not alone.
The Simple Version
Think of the LLM as a helpful narrator who reads a script.
The harness is the director who checks every line, makes sure the story follows the plan, and never lets the narrator skip ahead.
How It Actually Works
Contract Enforcement
Each step gives the LLM a tiny contract: 'Return the next instruction in this exact format.'
State Machine Flow
The agent moves through a fixed sequence: intro → teach → check → grade → advance → wrap.
The harness watches the LLM's reply, validates it, then decides which node to run next.
Why the LLM Shouldn't Own Decisions
If the model declares the lesson done early, the harness simply ignores that claim.
Similarly, it won't trust a 'I'm ready to grade' response unless the check step actually succeeded.
Technical Deep Dive
In code, the harness might look like a loop that reads the LLM output, parses the JSON payload, and matches it against a whitelist of allowed actions.
Only actions that pass validation are executed; everything else is logged and rejected.
This pattern also supports interruption handling: if the user speaks over the lesson, the harness can abort the current node and jump to a recovery state.
Why This Matters
When an AI tutor is used by real learners, reliability trumps creativity.
Skipping a validation step can cause confusion, wasted time, or even incorrect learning outcomes.
By keeping the flow under programmatic control, developers ship agents that feel polished rather than gimmicky.
Key Takeaways
- LLMs are great at generating text but should not dictate workflow order.
- A narrow contract tells the model exactly what to return.
- A harness validates and advances the state machine.
- Never let the model decide lesson completion or grading.
- State machines provide predictability for multi‑step agents.
- Tool‑use discipline closes the gap between demo and production.
- Authority over critical decisions stays with the system, not the model.