Function calling for phone agents: how tools work
Outcome of this lesson
You can define a tool the model will call at the right moment with the right arguments.
How tool calling works
- You describe each tool: a name, a description and a schema of parameters.
- During the call the LLM decides whether a tool is needed and returns a structured request, e.g.
check_availability(date="2027-02-14", service="cleaning"). - The platform sends that request to your webhook (your server).
- Your server runs the logic (calendar, CRM, database) and returns a result as JSON.
- The LLM reads the result and speaks the answer naturally.
A well-defined tool
{
"name": "check_availability",
"description": "Find open appointment slots. Use BEFORE offering any time to the caller. Returns up to 3 slots.",
"parameters": {
"type": "object",
"properties": {
"date": {"type": "string", "description": "Preferred date, YYYY-MM-DD"},
"service": {"type": "string", "enum": ["cleaning", "filling", "crown", "emergency"]}
},
"required": ["date", "service"]
}
}
Tool design rules
- Small and specific. One job per tool. “check_availability” and “book_appointment”, not “do_everything”.
- Descriptions are instructions. State when to use the tool and when not to.
- Use enums for fixed choices to avoid made-up values.
- Return clean, short JSON. The model reads it on the live call; huge payloads slow everything.
- Return useful errors.
{"ok": false, "reason": "slot_taken", "alternatives": [...]}lets the agent recover gracefully. - Be idempotent. If a booking call is retried, it must not create two appointments.
- Least privilege. The tool can book; it cannot delete customers or issue refunds unless that is explicitly required and gated.
Narrate the wait
Tools add delay. Tell the agent in the prompt to say a short bridge line (“Let me check Thursday for you”) and to keep it honest — never to claim something is done before the tool confirms.
Do this now
Write schemas for two tools your agent needs. For each, write one sentence for “use when…” and one for “do not use when…”.
💡 Real-world example
Illustrative scenario. An agent told callers “You’re booked!” before the booking tool had returned. When the slot turned out to be taken, the caller was confused and annoyed. Fix: the prompt now says “Only say a booking is confirmed after book_appointment returns ok:true.”
✅ Checklist
🛠 Your assignment
Pick one risky action (refund, cancel, share data). Decide what extra check or human approval it needs.
📝 Check your understanding
Answer 2 of 3 correctly to complete this lesson.