The first tool
An agent that only talks is a fancy chatbot. An agent that can call functions to look things up is the start of a real system. We will hand the agent one read-only tool: lookup_booking.
def lookup_booking(booking_id: str) -> str:
"""Looks up customer booking information by booking ID."""
booking_id = booking_id.upper().strip()
bookings = _get_all_bookings()
if booking_id in bookings:
b = bookings[booking_id]
return (
f"Booking Found:\n"
f"- Booking ID: {b['booking_id']}\n"
f"- Customer: {b['customer_name']}\n"
f"- Hotel: {b['hotel']}\n"
f"- Status: {b['status']}"
)
return f"Booking {booking_id} not found."AutoGen introspects the function signature, docstring, and type hints to build the JSON schema the model sees. A clear docstring is a prompt.
from tools import lookup_booking
agent = AssistantAgent(
name="travel_support_assistant",
model_client=model_client,
system_message="You are a professional travel support assistant. Use tools provided.",
tools=[lookup_booking],
model_client_stream=True,
)Passing tools=[lookup_booking] is all AutoGen needs. The model can now emit a tool call, and the framework will execute the Python function and feed the result back into the conversation.
Flashcards: Flashcards
Loading practice…
AI prompt: Try it: let the agent decide when to call the tool
Loading practice…