Level 3 · Loop Engineering

Closing the Loop: Adversarial Validation and Proof-of-Work

Advanced agentic engineering requires replacing trust with verification by implementing recursive interview cycles, adversarial planning loops, and objective proof-of-work gates.

Recursive Extraction and the Design Tree

The primary cause of failure in autonomous agents is context drift. When an agent moves from planning to execution, it often lacks the specific decision-making logic or architectural taste of the developer. To solve this, builders should implement a recursive interview loop. Instead of providing a static prompt, the harness forces the agent to grill the user. The agent must ask targeted, one-at-a-time questions until it has fully mapped the project design tree. This process ensures that the AI extracts nuances that generic prompts miss, such as specific error-handling preferences or legacy constraints within the codebase.

During this interview phase, the agent should not merely listen. It must autonomously explore the current codebase to validate user assertions and identify knowledge gaps. All discoveries must be written to a persistent markdown file in a dedicated directory. This acts as an external memory bank, preventing the model from losing its place during high-token-count sessions. By checkpointing every discovery, the agent maintains a high-fidelity map of the intent, which serves as the ground truth for all subsequent implementation steps. This extraction layer is the first gate in a high-integrity autonomous system.

Adversarial Staging and Multi-Agent Consensus

Once the context is extracted, the risk shifts to logic collapse within a single model. Using the same model instance for planning and execution often leads to a feedback loop where the agent confirms its own flawed logic. High-integrity harnesses break this cycle by separating roles into a staged pipeline: feature interview, plan generation, adversarial plan critique, and execution. By employing different model architectures for different stages, you reduce the probability of shared blind spots. A plan generated by one model is handed to a second model whose sole task is to act as a chaos monkey, identifying edge cases and architectural violations.

This adversarial loop should continue until the agents reach a deterministic consensus. You can implement this as a state machine where a 'Reviewer' agent must sign off on the 'Planner' agent's work before a single line of code is written. If the critique identifies a flaw, the planner must refactor its strategy and present it again. This debate ensures that the final plan has been stress-tested against potential failures. Only after the adversarial gate is passed does the execution model receive the instructions, ensuring that the implementation phase is a matter of translation rather than discovery.

Evidence-Based Gates and Objective Proof-of-Work

The most dangerous moment in an autonomous loop is when an agent claims a task is complete without actually performing the work correctly. Advanced builders eliminate this risk by requiring objective proof-of-work. A harness should never rely on a model's natural language assertion of success. Instead, it must enforce code-based gates. This involves requiring the agent to provide verifiable evidence of execution, such as SHA-256 hashes of test outputs or Playwright video recordings of UI interactions. If the agent cannot produce a bit-perfect match of the expected output, the state machine triggers an automatic rollback and enters a diagnostic loop.

This approach treats agent failures as bugs in the environment rather than one-off model errors. By integrating automated validation loops, the system forces the agent to iterate until unit tests, linting, and type checking pass deterministically. The harness uses LSP integration to provide real-time feedback, creating a closed-loop system where success is defined by technical state rather than model confidence. This shift from trust-based to evidence-based execution allows agents to work overnight with a high degree of reliability, as the system will not move to the next task until the current one is mathematically verified.

System Evolution and the Minimal Gotchas Layer

To maintain long-term performance, the engineering focus must shift from prompt tuning to system evolution. Every time an agent fails, it is an opportunity to update global rules or add safety hooks. Rather than bloating the agent’s context with massive documentation, the most effective strategy is to use a minimal set of manually curated 'gotchas.' Research suggests that reducing agent context by focusing only on specific project traps significantly improves accuracy. These hooks act as pre-tool use filters, programmatically blocking destructive commands or ensuring security protocols are followed before the agent executes a code block.

Finally, the harness must include a retrospective agent that analyzes execution logs at the end of every session. This agent identifies repeating patterns of failure and updates the persistent memory files to prevent the system from making the same mistake twice. This creates a self-improving loop where the environment becomes more robust over time. By combining recursive context extraction, adversarial planning, and hard proof-of-work gates, you build an autonomous system that does not require human steering because the integrity is baked into the architecture of the harness itself.

Key takeaways

  • Replace trust with evidence by requiring SHA-256 hashes or session recordings to verify agent success.
  • Use recursive 'grill me' loops to extract deep context and write all discovery to persistent markdown files.
  • Implement adversarial planning where a second agent must critique and approve a plan before execution begins.
  • Minimize agent context by replacing large document libraries with a curated list of high-impact 'gotchas.'
  • Treat every agent failure as a system bug that requires an update to global rules or pre-tool execution hooks.