← Building with AI

Project part 1: the tools

Give the bot two tools that read your study notes.

Start this lesson

You will build a study buddy that answers from a student's own notes. It has two tools: define (look a term up in the notes) and quiz (make a practice question about a term). In this part you write the tools, their descriptions, and the run_tool dispatcher. The pretend model will ask for define when a question starts with 'define' or 'what is', and for quiz when it starts with 'quiz me on'.

NOTES = {"evaporation": "when a liquid turns into a gas"}

def define(term):
    term = term.lower().strip()
    if term in NOTES:
        return term + ": " + NOTES[term]
    return "I don't have notes on " + term + " yet."

print(define("Evaporation"))   # evaporation: when a liquid turns into a gas

Cleaning the input (lower, strip) makes the tool forgiving about how the model wrote the term.

Plan first: which tools, what inputs, what each returns, and what happens when something is missing. Then write and test each tool on its own before connecting it to the model.

To run this project for real, you would swap the pretend ask_model for the client.messages.create call from the tool-loop lesson, using the same tool descriptions.