
Mission 5 of 8
Build a research agent that checks its own facts, and knows when to stop.
A single model call gives you fluent prose with invented citations. You'll build a loop that plans, reads real pages, drafts from its notes, then has a separate checker test every claim.
What you'll do
An allow-list, a cache and backoff that retries the right errors and gives up on the wrong ones.
Use JSON-schema outputs for the plan and the fact-check, so your code can act on them without parsing prose.
Assemble the phases with a round limit, a token budget, no-progress detection and two human gates.
- A four-file agent, under 200 lines in total
- Four stopping conditions that actually fire
- Human gates before spending and before publishing
- Missions 3 and 4 done:
tools.py,tools_v2.pyinagent-lab, venv active, key set pip install httpx(the Anthropic SDK already depends on an HTTP client, but we use httpx directly for the fetch tool)- An internet connection and about $1 of credit for the runs
- Optional: the local research agent if you want to see the same shape built with Crawl4AI and a local model
Your progress0/6
- 01Why one call fails and what the loop looks like7 min
- 02Act: a fetch tool with an allow-list, a cache and backoff14 min
- 03Plan: structured output your code can iterate12 min
- 04Verify: a strict checker with no stake in the draft12 min
- 05The loop: gates, budget, rounds, no-progress20 min
- 06What transfers, and what comes next5 min
Why one call fails and what the loop looks like
Before writing any code, name the four phases and the places each one goes wrong.
You'll start by seeing the problem for yourself. Try the single call first, so the comparison at the end is yours.
Run the single call below. It asks the model for 300 words on the UK state pension age, with a source URL for each date.
Terminalpython -c "import anthropic; r=anthropic.Anthropic().messages.create(model='claude-sonnet-5-5',max_tokens=1500,messages=[{'role':'user','content':'Write 300 words on how the UK state pension age has changed since 2010, with dates and a source URL for each date.'}]); print(r.content[-1].text)"Read it with a sceptical eye. The dates may be right. The URLs are usually plausible and often do not exist, or exist and do not say what is claimed.
The model is not lying; it is completing a pattern, and "with sources" produces source-shaped text. Nothing in a single call can check anything.
Save the output, then open at least one of its URLs by hand to see for yourself.
The four jobs in the loop
The loop fixes this by separating four jobs that a single call blurs together:
- Plan. Turn the brief into concrete questions, each with the pages that should answer it and a definition of done. Output: structured data your code iterates over, not a paragraph.
- Act. For each question, an agent reads the pages with a tool and writes notes that quote sentences with URLs. Tools can fail, so this phase needs retries, timeouts and an allow-list.
- Verify. A separate call, with a different system prompt and no memory of writing the draft, extracts every claim and looks for the supporting sentence in the fetched text. Output: structured verdicts.
- Revise, or stop. Fix only the failed claims, re-verify, and stop when clean, when rounds run out, when the budget is spent, or when a round makes no progress.
Why the verifier matters most
The verifier is the part people skip and the part that matters most. The same model that wrote a sentence will defend it.
A fresh call that only sees the draft and the sources, and is told to be strict, will not. Separation of roles beats a better prompt. The rest of the mission builds each of these jobs in turn.