HASZB_AIHASZB_AI

Search across courses, lessons, glossary terms, prompts and tools.

Stage 10 · Real Projects

Project 2 — a multi-tool agent

Build a research agent with three tools, a step budget and honest failure — the smallest thing that is genuinely an agent.

10 min read

In this lesson

  • Implement the agent loop with real tools
  • Enforce limits and validate every tool call
  • Handle failure without fabricating results

Now something that genuinely qualifies as an agent: it takes actions, decides its own steps, and stops when done.

Goal. Answer a research question by searching, reading and synthesising — citing what it actually used.

The tools

Three, deliberately narrow:

  • search(query) → up to 5 results, each with title, URL, snippet
  • fetch_page(url) → the readable text of one page, truncated to a set length
  • save_note(text, source_url) → records a finding

save_note is what makes this work. Without it, the agent accumulates raw page text in context until the goal is crowded out. With it, findings are extracted and stored while the raw text is discarded.

The loop

Implement the four steps from stage six directly:

  1. Build the state: goal, notes so far, last result
  2. Ask the model for one tool call or a final answer
  3. Validate and execute
  4. Append the result, repeat

Limits from the first version

Not later, when it misbehaves. Now:

  • Maximum 10 iterations
  • Maximum 60 seconds wall clock
  • Maximum 8 fetches per run
  • Stop on three consecutive tool failures

When a limit is hit, return what was found so far and say the limit was reached. A partial answer labelled partial is useful. A partial answer presented as complete is not.

Validate every call

  • fetch_page — is it a real URL? http or https only? Not a private address?
  • search — is the query non-empty and within a sensible length?
  • Repeated identical calls — return "you already fetched this, here is the earlier result" instead of executing again

Honest failure

The behaviour that decides whether this project is good: when the agent finds nothing relevant, it must say so.

I searched for X, Y and Z and found no sources addressing this directly. Here is what I did find, which is adjacent but not an answer.

Test this deliberately. Ask about something obscure or invented. If it produces a confident answer from general knowledge with no sources, your instructions and your loop need work — that is the exact failure the whole course exists to prevent.

Evaluate

Ten questions: five with good sources, three obscure, two with false premises. Score whether it cited real sources, whether claims trace to fetched pages, whether it admitted uncertainty, and whether it finished in budget.

Extend it

  • Add a contradiction note type for sources that disagree
  • Require two independent sources before stating a fact
  • Add approval before any tool that writes