Menu
CoddyTech

Project Overview

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

challenge icon

Challenge

Medium

Over four lessons you build a travel agent: a program that lets the model search flights and hotels, then book a seat. The starter holds the trip data and three Python functions; today you give the model one of them.

  1. Define a tool named search_flights with the description Search flights to a destination and give the ticket price and one required string property, destination, described as The destination city.
  2. Send the request as the only user message with tools=[...], model="claude-opus-5-5" and max_tokens=500.
  3. For each tool_use block, print Tool: , the tool's name, a space and its input, then run search_flights with the destination.
  4. Append the assistant's content and a user message with the tool_result blocks, call the model again with the same tools, and print Agent: and the text of the text block.

For example, for the input Find a flight to Lisbon the program prints:

Tool: search_flights {'destination': 'Lisbon'}
Agent: Here is what I found: Flight to Lisbon: 120 dollars

Try it yourself

import coddy_ai as anthropic  # in production: import anthropic

client = anthropic.Anthropic()

FLIGHTS = {"Lisbon": 120, "Rome": 95, "Tokyo": 640, "Oslo": None}
HOTELS = {"Lisbon": 80, "Rome": 110, "Tokyo": 150, "Oslo": 130}


def search_flights(destination):
    if destination not in FLIGHTS:
        raise ValueError(f"No flights to {destination}")
    if FLIGHTS[destination] is None:
        raise ConnectionError("The flight service is temporarily unavailable, try again")
    return f"Flight to {destination}: {FLIGHTS[destination]} dollars"


def find_hotel(city):
    if city not in HOTELS:
        raise ValueError(f"No hotels in {city}")
    return f"Hotel in {city}: {HOTELS[city]} dollars a night"


def book_flight(destination):
    return f"Booked a seat to {destination} for {FLIGHTS[destination]} dollars"


request = input()

# Write your code below

All lessons in Tools and Agents

Practice on your own: Online Python compiler