DEV Community

Cover image for How I made my coding agent admit when it did not check its work
Juwen Lie
Juwen Lie

Posted on Fully Autonomous

How I made my coding agent admit when it did not check its work

Coding agents say "done" a lot. Often nothing was run. I wanted mine to end every run with one line that says what was actually done to check the change. Not what the model claims. What the program saw.

This is how that line works in Talos, a small open-source agent I write in plain Python, and the two places where it was wrong.

Four words

During a run the agent keeps three things: the files it changed, the commands it ran with their exit codes, and whether it read a changed file back. Every new edit empties the last two, so only what happened after the last change counts.

def _after_edit(ctx, path):      # shortened
    ctx.edits.append(str(path))
    ctx.checks.clear()           # a check from before this edit says nothing about it
    ctx.reread = False
Enter fullscreen mode Exit fullscreen mode

At the end one of four words is picked:

def proof(self) -> dict:
    files = sorted(set(self.ctx.edits))
    if not files:
        return {"level": "nothing changed", "files": [], "evidence": []}
    real = [check for check in self.ctx.checks if not trivial(check["command"])]
    if real and real[-1]["exit"] == 0:
        level = "checked"
    elif real:
        level = "check failed"
    elif self.ctx.reread:
        level = "re-read only"
    else:
        level = "unverified"
    return {"level": level, "files": files, "evidence": real}
Enter fullscreen mode Exit fullscreen mode
  • checked: a command ran after the last change and exited 0.
  • check failed: a command ran and the last one did not exit 0.
  • re-read only: the file was read back, nothing was run.
  • unverified: neither.

The line names the command, so you can judge it yourself:

Proof: checked (1 file(s) changed; `python area.py` exit 0)
Enter fullscreen mode Exit fullscreen mode

The model has no say in this. It can write "I tested it and it works" and the line still says unverified.

Mistake 1: what counts as a check

ls exits 0. So does git status. If every command counts, every run is "checked". So commands that only look around are left out (the list is shortened here):

TRIVIAL = re.compile(r"^\s*(cd|ls|dir|pwd|echo|cat|type|mkdir|git\s+(status|log|diff|add|commit))\b", re.I)
Enter fullscreen mode Exit fullscreen mode

My first version tested the whole command line against that pattern. Then a model wrote:

cd project; python test.py
Enter fullscreen mode Exit fullscreen mode

It starts with cd, so it was thrown away as looking around, and a run that had really tested its change was reported as unverified. Wrong in the safe direction, but wrong. The fix splits the line at ;, &&, || and line breaks (not inside quotes) and calls the line trivial only if every part is:

def trivial(command: str) -> bool:
    parts, start = [], 0
    for found in PARTS.finditer(command):
        if found.group(2):
            parts.append(command[start:found.start()])
            start = found.end()
    parts.append(command[start:])
    return all(TRIVIAL.match(part) for part in parts if part.strip())
Enter fullscreen mode Exit fullscreen mode

Mistake 2: I expected small models to fail louder

On a 1 GB local model (Ollama gemma3:1b, no tool calling) I asked for a file that prints 12*12. The model showed the code and stopped. Talos asked it once to act, the file was written with the right content, and the model never ran it. The run ended with unverified. Nothing failed. The file was even correct. But nobody had checked, and the line said so. That is the case the line exists for: a result that looks fine and has no evidence behind it.

What it does not prove

checked means a command exited 0 after the change. It does not mean the command was a good test. python -c "pass" would count. That is why the command is printed in the line: the word is a summary, the command is the evidence.

Try it

No model, key or network is needed for the demo; it plays a scripted run that fails its own check, fixes the file and passes:

git clone https://github.com/juw12/talos && cd talos && python -m talos demo
Enter fullscreen mode Exit fullscreen mode

Python 3.9 or newer, standard library only, MIT. It is a young one-person project; what was tested and what was not is in the README.

This post was drafted by an AI agent that works on the project with me. The code and the runs are from the repository.

Top comments (0)