Teach an agent to use a tool
A 75-minute facilitator kit for developer meetups, teams, and classrooms. Learners debug a tool call and prove the fix with a regression check.
Before the session
- Ask learners to bring a laptop, a text editor, and Python 3. Familiarity with functions and dictionaries is enough.
- Download the v1 starter and run
python3 first_agent.py --check. The fresh starter passes four of five checks and exits with code 1. - Open the browser replay and pick one routing example and one ReAct example. Use the default input for each recording. If internet access is limited, stage the starter locally and use slides 2–3 to explain the flow.
Session plan
- 0–10 min · Read a trace. Replay routing and ReAct. Ask where the application decides the next step and where the model does. Point out that both demo runs are recorded.
- 10–25 min · Establish a baseline. Have learners run the starter before editing it. Ask each pair to say what passed, which case failed, and where they would look next.
- 25–45 min · Follow the argument. Have learners replay the failing notebook prompt and inspect its entry in
RESPONSES. Ask whether they can explain the failure with the model output held fixed. - 45–60 min · Run the regression suite. Have learners normalize the lookup input and rerun all five cases. Ask why a quantity of zero still counts as a successful lookup.
- 60–75 min · Compare fixes. Ask each pair to add one fixture and case. Discuss what the replay can verify, and what needs measurement against a real model. End with an invitation to Week 2.
Assessment
- Explain: identify the tool name, the recorded argument and the reason the lookup failed.
- Verify: show
5/5 passedand explain what the zero-stock, unknown-item and no-tool cases protect. - Extend: write one useful new case and justify its expected result.
Answer key and reset
Reveal the answer key
Normalize at the boundary of the tool. A call with " Notebook " should return 5. A missing key should return the existing error message. A greeting should return an empty tool trace.
def lookup_stock(item):
return INVENTORY.get(item.strip().casefold(), NOT_FOUND)Example extension: add a replay returning " PeN " as the tool argument, with an expected result of 0 and exactly one lookup_stock call.
Reset by downloading the v1 starter to a new folder. If a learner sees five passes before editing, check which copy they are running.
Share the workshop and its results
Link to these pages or present the hosted slides and exercises in a session. The separate diagram-agent and harness repositories carry MIT licenses. For redistribution or adaptation of the site’s teaching materials, contact the instructor. [Diagram workshop] [Harness workshop]
If your team or class runs the workshop, share an optional teaching report on GitHub or send feedback privately. The version, group size, and first point where learners needed help are enough.