Recap: Weather Desk
Part of the Tools and Agents section of Coddy's AI Engineering journey. Lesson 5 of 22.
Challenge
MediumBuild a weather desk that answers with two tools. The starter defines get_weather and get_air_quality and reads the question.
- Define two tools, each with one required string property
city:get_weatherwith the descriptionGet the current weather for a city, andget_air_qualitywith the descriptionGet the air quality index for a city. - Send the question with both tools,
model="claude-opus-5-5"andmax_tokens=300. - If the stop reason is
"tool_use": printTool:, the tool's name, a space and its input; run the matching function; send the assistant turn and thetool_result; and call the model again. Otherwise printTool: none. - Print
Answer:and the text of the last reply's text block.
For example, for the input What is the weather in Lisbon? the program prints:
Tool: get_weather {'city': 'Lisbon'}
Answer: Here is what I found: Lisbon: 19 C and sunnyTry it yourself
import coddy_ai as anthropic # in production: import anthropic
client = anthropic.Anthropic()
WEATHER = {"Lisbon": "19 C and sunny", "Delhi": "31 C and hazy", "Montreal": "-3 C and snowing"}
AIR = {"Lisbon": "index 22, good", "Delhi": "index 168, unhealthy", "Montreal": "index 35, good"}
def get_weather(city):
return f"{city}: {WEATHER.get(city, 'no weather data')}"
def get_air_quality(city):
return f"{city}: {AIR.get(city, 'no air quality data')}"
question = input()
# Write your code below
All lessons in Tools and Agents
1Tool Use Basics
Defining a ToolReading a Tool CallReturning Tool ResultsChoosing Between ToolsRecap: Weather DeskPractice on your own: Online Python compiler