Menu
CoddyTech

סקירת הפרויקט

חלק מהיחידה כלים וסוכנים במסלול ה-AI Engineering של Coddy. שיעור 16 מתוך 22.

challenge icon

אתגר

בינוני

במשך ארבעה שיעורים תבנה סוכן נסיעות: תוכנית שמאפשרת למודל לחפש טיסות ומלונות, ולאחר מכן להזמין מקום. הקוד ההתחלתי מכיל את נתוני הנסיעה ושלוש פונקציות Python; היום תיתן למודל אחת מהן.

  1. הגדר כלי בשם search_flights עם התיאור Search flights to a destination and give the ticket price ותכונת מחרוזת חובה אחת, destination, המתוארת כ-The destination city.
  2. שלח את הבקשה כהודעת המשתמש היחידה עם tools=[...], model="claude-opus-5-5" ו-max_tokens=500.
  3. לכל בלוק tool_use, הדפס Tool: , את שם הכלי, רווח ואת הקלט שלו, ואז הרץ את search_flights עם היעד.
  4. הוסף את התוכן של ה-assistant והודעת משתמש עם בלוקי ה-tool_result, קרא למודל שוב עם אותם כלים, והדפס Agent: ואת הטקסט של בלוק הטקסט.

לדוגמה, עבור הקלט Find a flight to Lisbon התוכנית תדפיס:

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

נסו בעצמכם

import coddy_ai as anthropic  # בסביבת ייצור: 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()

# כתוב את הקוד שלך למטה

כל השיעורים ביחידה כלים וסוכנים

תרגלו בעצמכם: קומפיילר Python אונליין