Menu
CoddyTech

Recap: Weather Desk

Part of the Tools and Agents section of Coddy's AI Engineering journey. Lesson 5 of 22.

challenge icon

Challenge

Medium

Build a weather desk that answers with two tools. The starter defines get_weather and get_air_quality and reads the question.

  1. Define two tools, each with one required string property city: get_weather with the description Get the current weather for a city, and get_air_quality with the description Get the air quality index for a city.
  2. Send the question with both tools, model="claude-opus-5-5" and max_tokens=300.
  3. If the stop reason is "tool_use": print Tool: , the tool's name, a space and its input; run the matching function; send the assistant turn and the tool_result; and call the model again. Otherwise print Tool: none.
  4. 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 sunny

Try 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

Practice on your own: Online Python compiler