Mid-call lookups
The phone persona has been faking it. If a caller asks whether flight SH101 is on time, the agent should actually know. Tool calls let the LLM ask your Python process for real data mid-turn. The voice loop has to cover the tool latency without dropping into dead air.
DEMO_FLIGHTS = {
"SH101": {"from": "San Francisco", "to": "New York", "departure": "08:30", "status": "on time"},
"SH204": {"from": "Los Angeles", "to": "Seattle", "departure": "11:15", "status": "delayed 20 min"},
"SH309": {"from": "Chicago", "to": "Miami", "departure": "14:45", "status": "on time"},
}A tiny in-memory data source stands in for a real flights API. The interesting part is not the data, it is the tool-calling contract the agent uses to ask for it.
FLIGHT_TOOLS = [
{
"type": "function",
"function": {
"name": "get_flight_status",
"description": "Look up the status of a SkyHop flight by its flight number (e.g. SH101).",
"parameters": {
"type": "object",
"properties": {
"flight_number": {"type": "string", "description": "The flight number, e.g. SH101"},
},
"required": ["flight_number"],
},
},
},
]
def get_flight_status(flight_number: str) -> dict:
from constants import DEMO_FLIGHTS
return DEMO_FLIGHTS.get(flight_number.upper(), {"error": f"Unknown flight {flight_number}"})Two parts: a JSON schema the LLM receives so it knows the tool exists and what arguments it takes, and a plain Python function that actually runs the lookup. Tool calling is a contract between the prompt and the runtime, nothing more.
Quiz: Quiz
Loading practice…