The agent confidently says the task is done when it isn't

L2 · PractitionerDesign~8 minPlanning & multi-agent

Your coding agent ends runs with "All done! The bug is fixed." In about 20% of those runs the tests still fail, or were never run. Users stopped trusting the message. How do you fix "done" without making every run slower?

Answer it out loud or on paper first. Then open the short answer.

Short answer

Don't let the model decide "done"; let a verifier decide. Define completion as evidence that code can check: the relevant tests ran after the last edit and passed, the linter is clean, the diff touches only allowed files. The loop checks this before accepting a final answer. If it's missing, the agent gets an observation ("tests haven't run since your last edit") and continues. Report the evidence to the user alongside the claim. The extra cost is one test run, which is cheaper than a false "fixed".

Full answer

Verifiers by task

TaskVerifier
Code changeTests after the last edit; type check; lint
Data extractionSchema validation; totals reconcile
Research answerEvery claim cites a retrieved source
Booking or refundRead back the created record and compare
SQL queryRun on a sample; check row counts and types

Where it sits in the loop

When the model replies without tool calls, run the completion check. Pass: return the answer and the evidence. Fail: append the failure as an observation and continue, within the step budget. The model never gets to skip it.

"Fresh" evidence

Any edit after a passing test invalidates it. Track the order of events: a passing test followed by an edit to the README is still unverified if the policy says so.

Show evidence, not claims

"Fixed: test_payments.py 14 passed (run 12 s ago, after the last edit)." Users trust evidence.

Follow-ups

  1. L2. What if there are no tests for the bug?

    Expected answer

    Make writing a failing test part of the task (test-driven loop), or require a reproduction script whose output changes.

  2. L3. Can the agent game the verifier?

    Expected answer

    Yes, by editing or deleting tests. Forbid edits to test files unless required, diff-check them, and flag deleted assertions.

  3. L3. Is an LLM reviewer a verifier?

    Expected answer

    A weak one; useful for style or plausibility, but prefer executable checks for correctness.

Wrong answers interviewers hear
  • "Tell the model to always run tests before saying done." It mostly will; 20% of runs show "mostly" isn't enough.
  • "Ask the model if it's sure." Self-assessment is poorly calibrated; it will say yes.
  • "Add a second model to review the final message." Reviewing the claim isn't checking the code; run the tests.

Taught in

Improve this answer