Debug the weather agent (~15 min)
debug_weather_agent.py is a weather agent with a working-looking loop, two tools (get_weather, calculate) and three test prompts in PROMPTS.
Run them one at a time and make all three pass:
python -m debug_weather_agent
| Prompt | Expected |
|---|---|
weather | Answer mentions 18 (Tokyo's temperature in °C) |
math | Answer mentions 187.5 |
unknown | The agent doesn't crash and tells the user it can't find the city, naming it (e.g. Atlantis, any casing) |
Find the root cause of each failure by reading the raw tool_use inputs and tool results, then fix it where it belongs (tool schema, tool function, or loop). Say out loud what you expect the model to send before you run each prompt.
You may edit anything in debug_weather_agent.py. The tool names and run_agent(prompt, client=None, max_turns=10) -> str must stay.
Running the module with a key prints a trace of every model call to stderr: tool calls with their ids and inputs, the results sent back, and token counts (ABH_TRACE=0 turns it off).
Check it: pytest tests/test_debug_weather_agent.py