Agent Self-Correction
Pattern for using the wiki as a runtime oracle — not startup context — to re-align agents when they drift from established workflow patterns. Zero startup overhead; agents query on deviation.Core principle
The wiki is not injected at session start. Agents query it autonomously when they detect they are about to deviate from the workflow. One targetedqmd query re-aligns the agent. This is cheaper and more reliable than bulk context injection.
Known limitation — pull systems require metacognition
This pattern is a pull system: the agent must recognize it is drifting before it queries. That is precisely the capability that context-poisoned or distracted agents lack. An agent that is already drifting — confidently hallucinating an API, misreading scope — will not fire the trigger because, from inside its degraded context, it believes it is proceeding correctly. Implication: do not rely on agent discretion alone. Where possible, enforce triggers via harness hooks rather than agent norms:
Until hook-enforced gates exist in a project’s harness, treat self-correction as a best-effort layer, not a reliable gate. Instinct Clustering (Homunculus Pattern) (push — injects patterns at session start) is theoretically stronger for agents that are already drifting; ECC v2 is a reference implementation of it, though hook enforcement remains the validated gate in this harness.
Deviation Triggers → Wiki Queries
When an agent detects any of these situations, it MUST run the correspondingqmd query before proceeding:
How agents use this
In AGENTS.md:Wiki pages behind each trigger
Why wiki-as-oracle beats startup injection
Startup injection loads N pages of wiki content into every session — most of it irrelevant to the current task. This burns tokens and dilutes attention. Oracle pattern: 0 tokens at startup, ~500 tokens per targeted query, only fired on actual deviation. For a typical session with 0–2 deviations, total wiki cost is near zero. For a session that drifts repeatedly, the queries catch it before damage compounds. This is the Context Engineering principle applied to meta-cognition: just-in-time retrieval rather than front-loaded injection.Relation to homunculus instinct system
Instinct Clustering (Homunculus Pattern) mines behavioral patterns from tool-call telemetry and injects high-confidence “instincts” at session start. That is automatic and implicit. Agent self-correction is explicit and query-driven. They are complementary — but not symmetric. Instinct clustering is a push pattern (high-confidence instincts injected at session start, no agent action required). Self-correction is a pull pattern (agent must recognize deviation and query). Push would be more reliable for agents that are already drifting; pull is cheaper for agents that are not. Where instinct clustering isn’t wired into a harness, prefer hook enforcement over relying on pull for critical gates (commit, merge, claiming completion).Relation to Self-Refine
Self-Refine (Madaan et al., 2023) is a related but distinct pattern: generate output → self-feedback (same model critiques its own output) → refine → repeat. Key distinction:- Self-Refine: same model, same turn, self-feedback — iterative refinement within one task
- Agent Self-Correction: external oracle (wiki), cross-turn, triggered on deviation — re-alignment across a session
Related Pages
- Context Engineering — JIT retrieval principle
- Instinct Clustering (Homunculus Pattern) — complementary implicit learning system
- Verification Pipeline — UI/visual verification before claiming completion
- Unit Testing — backend/logic verification
- CI/CD Testing — test pyramid and pipeline-level verification
- Multi-Vendor Adversarial Review — when to trigger council
- Branch Strategy for Agents — worktree and merge decisions
- Rules vs. Hooks — why hook enforcement is stronger than pull-based self-correction
- Lean Agentic Coding Workflow — the core workflow agents self-correct toward
- Self Refinement — Self-Refine paper (same-model iterative refinement; related but distinct)
- Preference Feedback Loop — automatic judge-driven correction (complements agent self-correction)