Get Started
Agent engineering

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.

80 minAdvancedRoughly $0.30 to $0.80 per full run on SonnetStep 1 free

What you'll do

Build a safe fetch tool

An allow-list, a cache and backoff that retries the right errors and gives up on the wrong ones.

Plan and verify with schemas

Use JSON-schema outputs for the plan and the fact-check, so your code can act on them without parsing prose.

Run the loop with stop rules

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
Before you start
  • Missions 3 and 4 done: tools.py, tools_v2.py in agent-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
01/06Why one call fails and what the loop looks like0 done
STEP 01 of 06~7 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.

  1. 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.

    Terminal
    python -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.

  2. 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.

Checkpoint
You have the single-call output saved, and you have checked at least one of its URLs by hand. That's your baseline: keep it, because you'll compare it with the loop's output at the end.
Stuck? Ask the community
Next mission · Agent engineeringEvals for agents: task suites, graders, trajectories, cost per task, and a regression run in CI
→