Skip to content

Session Feedback Loop — Agent Self-Verification

The session feedback loop is an internal verification mechanism that allows an AI coding agent to test, observe, and correct its own work before presenting results to a human engineer. Giving the session a fast, single-command test runner and a quantifiable success target turns the agent from a one-shot code generator into a self-correcting development loop.

Scorecard question: How does the agent verify its own work before presenting it for human review? Max‑score answer (3 pts): Enforced verification: quantifiable targets, automated loop iterations, and verifier subagent running in fresh context.

When agents cannot verify their own work, the human developer becomes a manual testing bottleneck. The engineer must pull the branch, run test suites, inspect logs, and paste failure traces back into the prompt. This back-and-forth loop exhausts context windows and drains developer bandwidth.

In an AI-native SDLC, verification runs inside the agent session. The agent receives an objective metric (such as “all 14 tests in auth.test.ts pass” or “the TypeScript compiler reports zero errors”) and iterates autonomously until that condition is satisfied. For thoroughness, a verifier subagent launches in a fresh context window to inspect the final changes without bias from the build turns.

A max-score Q14 setup provides four key components:

  1. Codified commands: Fast local verification commands (make test, pnpm check, pytest) are documented in CLAUDE.md, .cursor/rules, or AGENTS.md.
  2. Quantifiable target: Every prompt includes an explicit definition of done with measurable pass criteria.
  3. Autonomous iteration: The agent executes the test command, parses any failure, applies a fix, and reruns until the check passes.
  4. Verifier subagent: Before completing the task, an independent subagent with a clean context verifies the changes against plan.md.
  1. Document single-command verification targets.

    Add clear verification commands with expected success outputs to your repository instructions (CLAUDE.md, .cursor/rules/core.mdc, or AGENTS.md):

    ## Verification commands
    - Build: make build (must end with "Build succeeded")
    - Unit tests: make test (all tests pass)
    - Linter: make lint (zero warnings or errors)
    Always run all three checks before reporting a task complete.
    Paste the terminal output showing exit code 0.
  2. Supply quantifiable targets in the prompt.

    Always specify the objective standard the agent must prove before stopping:

    Implement the Stripe webhook handler outlined in plan.md.
    Definition of done:
    1. All existing tests in tests/billing/ pass.
    2. Three new unit tests covering signature verification, duplicate events,
    and malformed payloads are green.
    3. npm run typecheck outputs zero errors.
    Do not ask for human review until all three conditions are satisfied.
  3. Configure a verifier subagent.

    Create a dedicated verifier subagent in .claude/agents/verifier.md (or equivalent Cursor/Codex agent configuration):

    ---
    name: verifier
    description: Inspects changes and verifies behavior in a fresh context
    tools: Bash, Read, Grep
    ---
    You are an adversarial verifier. Review the latest git diff against plan.md.
    Run the test suite with `npm test`. Exercise neighboring modules for unintended
    regressions. Report all discrepancies. Do not apply fixes; report findings only.
  4. Automate the verification invocation.

    Instruct your agent to invoke the verifier or run verification in the final turn:

    All tests are passing locally. Launch the verifier subagent to validate
    the diff against plan.md before finishing the task.
  • Subjective prompts: Asking the agent to “make sure the code looks good” rather than “ensure npm test exits 0”.
  • Infinite failure loops: Failing to limit agent retries when an external service or database is unreachable. Provide clear mock boundaries.
  • Cheating the verification: The agent modifies the test to make it pass rather than fixing the code. Enforce strict protection on test files (see Q15).
  • Agent turns consistently show command executions (npm test, pytest) without prompting.
  • The agent pastes terminal evidence of passing tests before claiming completion.
  • Pull requests opened by agents have green CI runs on the first push.
  • Engineers review code for architecture and intent rather than checking for compile errors.