AI Hints
Home›Agentic AI Tutorial›Finishing Well
Agentic AI · Lesson 35 of 100

Mini Project: A Research Agent

Everything so far.

⏱ 2 min read▶ Video at 1:01:59🎓 Free
Watch this lesson in the Agentic AI courseWatch on YouTube ↗Full Agentic AI course

The founder has a question for you. Which product line should we push next quarter? It isn't a lookup. It needs searching, comparing, and judgment. That's a task for an agent. And you know how to build one.

Mini Project: A Research Agent
From the video: Mini Project: A Research Agent
  • Which product line next?
  • Search, compare, and judge
  • A task for an agent

A small research agent

We've got one tool, which searches some market notes. Notice that its description lists the topics, which helps the model to choose. The instructions say to search first, and to base every claim on the notes. Then we ask our question. Run it. It made several searches by itself, on different topics. And its answer points to real notes, not to things it made up. That's a real research agent, and it's only twenty five lines long.

research.pypython
from google import genai
from google.genai import types

SOURCES = {
    "tubeless tyres": "Tubeless tyres grew 40% in sales this year, led by gravel riders.",
    "gravel bikes": "Gravel bikes are now the fastest-growing category in Europe.",
    "chain wax": "Chain wax lasts longer than oil, but takes more time to apply.",
}

def search_notes(topic: str) -> dict:
    """Search market notes. Topics: tubeless tyres, gravel bikes, chain wax."""
    return {"note": SOURCES.get(topic.lower(), "Nothing found. Try another topic.")}

client = genai.Client()
r = client.models.generate_content(
    model="gemini-flash-latest",
    config=types.GenerateContentConfig(
        system_instruction="You are a research analyst. Search before you answer. "
                           "Base every claim on the notes. Keep it to three sentences.",
        tools=[search_notes]),
    contents="Which product line should a bike shop push next quarter, and why?")

print(r.text)
print("Searches:", sum(1 for t in r.automatic_function_calling_history
                       for p in t.parts if p.function_call))
Output
The bike shop should push gravel bikes next quarter. Market notes show that gravel bikes are currently the fastest-growing category in Europe. Furthermore, this category is driving strong broader demand, with tubeless tyre sales growing 40% this year led by gravel riders.
Searches: 3

What makes it trustworthy

Look at what makes this good. It's got a narrow tool, so it can't wander. It's got clear instructions to base claims on notes. Its answer is short. And we counted the searches, which is the beginning of measurement. In a real product, you'd add citations, a budget, and a test set.

A narrow toolit can't wander
Grounded claimsbased on notes
Short answereasy to check
Measuredwe counted the searches

Your turn

Now it's your turn. Add a tool of your own, and a rule that says, if the notes disagree, say so. Then ask a question that the notes can't answer, and check that the agent admits that. Pause, and try it. Handling a question that it can't answer is the true test of an agent.

✍️ Exercise: Your turn

Add a second tool, plus a rule to admit when the notes have no answer.

Show hint

Add it to the tools list.

Show solution
solution.pypython
def compare_notes(a: str, b: str) -> dict:
    """Fetch two notes side by side."""
    return {"a": SOURCES.get(a), "b": SOURCES.get(b)}

Summary

You've built agents with your bare hands. You know exactly what's inside them. Now we'll go up a level. Next, the framework that's become the standard for building controllable agents.

Key takeaways
  • Narrow tools
  • Grounded answers
  • Test what it can't answer
Next up: Why Graphs? — from loops to LangGraph