Lesson 7 of 7 · Projects
Project: Appointment Booking Agent
Build an appointment booking agent: tools to resolve dates, check availability and book slots, a confirmation step, double-booking protection and a real LLM.
- 5 min read
- Intermediate
- Reviewed
- Design tools for a booking assistant: dates, availability and booking
- Keep date maths and availability in code, not in the model
- Require confirmation before booking, and prevent double bookings
- Connect the tools to a real model with an agent loop
The task
A hair salon wants an assistant that books appointments by chat. Customers say things like “next Tuesday afternoon” and change their minds. Bookings must be correct: right date, a free slot, the customer's name, and never two customers in one slot.
Booking is a good fit for a small agent: the conversation's path varies (customers ask about different days, pick, change), but the actions are few and well defined.
The tools and the conversation
The customer's and assistant's turns below follow a script, so you can see the flow; in production a model chooses each step:
from datetime import date, timedelta
TODAY = date(2026, 11, 18) # a Wednesday
CALENDAR = {"2026-11-24": {"10:00": None, "14:00": None, "16:30": None, "15:00": "Ari P."}}
WEEKDAYS = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
# ---------- Tools: exact work done by code, never guessed by the model ----------
def resolve_date(text):
"""Turn 'next tuesday' into a real date, relative to today."""
target = WEEKDAYS.index(text.lower().replace("next ", ""))
days_ahead = (target - TODAY.weekday()) % 7 or 7
return (TODAY + timedelta(days=days_ahead)).isoformat()
def check_availability(day, after="00:00"):
slots = CALENDAR.get(day, {})
return sorted(t for t, who in slots.items() if who is None and t >= after)
def book(day, time, name):
if CALENDAR.get(day, {}).get(time, "taken") is not None:
return {"error": f"{time} on {day} is no longer free"}
CALENDAR[day][time] = name
return {"confirmation": f"BK-{day.replace('-', '')}-{time.replace(':', '')}", "day": day, "time": time}
# ---------- The conversation (the model's turns are scripted stand-ins) ----------
def say(who, text):
print(f"{who:>6}: {text}")
say("user", "Can I get a haircut next Tuesday afternoon?")
day = resolve_date("next Tuesday") # model -> tool call
slots = check_availability(day, after="12:00") # model -> tool call
say("agent", f"On Tuesday {day} I have {' or '.join(slots)}. Which would you like, and what name should I use?")
say("user", "16:30, Sam Lee")
say("agent", f"To confirm: haircut on {day} at 16:30 for Sam Lee. Shall I book it?") # policy: confirm first
say("user", "Yes please")
result = book(day, "16:30", "Sam Lee") # only now does the booking tool run
say("agent", f"Booked! Your confirmation number is {result['confirmation']}.")
print("\nSomeone else tries the same slot:", book(day, "16:30", "Jo K."))The important design choices:
- Date maths is a tool. “Next Tuesday” from Wednesday 18 November is 24 November. Models can get relative dates wrong;
resolve_dategets them right every time. - Availability comes from the calendar, never from the model's memory of the conversation.
- Confirmation before booking. The assistant repeats date, time and name, and books only after a clear yes.
- The booking tool re-checks the slot. When a second customer tried the same time, it returned a clear error instead of double-booking. Between showing slots and booking, someone else may have taken one.
With a real model
On your own computer, the same tools plug into the agent loop from the Tool and Function Calling course. The system prompt carries the rules and today's date:
SYSTEM = (
"You book appointments for Studio Nine hair salon. Today is Wednesday 2026-11-18.\n"
"- Always use resolve_date for relative dates and check_availability before offering times.\n"
"- Offer at most three times. Ask for the customer's name if you don't have it.\n"
"- Before calling book, repeat the date, time and name and wait for a clear yes.\n"
"- If book returns an error, apologise and offer the remaining free times."
)And the policy layer in code makes sure book can't run unless the user's last message confirmed the exact slot, whatever the model decides.
Common mistakes
Write the date tool a booking agent needs, so relative dates are calculated, not guessed.
from datetime import date, timedelta
TODAY = date(2026, 11, 18) # a Wednesday (weekday() == 2)
WEEKDAYS = ["monday", "tuesday", "wednesday", "thursday", "friday", "saturday", "sunday"]
def next_weekday(name):
# Return the date of the next given weekday after TODAY (never TODAY itself),
# as YYYY-MM-DD. "next wednesday" from a Wednesday means 7 days later.
return TODAY.isoformat()
print(next_weekday("friday"))
print(next_weekday("monday"))
print(next_weekday("wednesday"))
Why does the book tool check the slot again, even though availability was checked a moment earlier?
Summary
- A booking assistant is a small agent with a few precise tools: resolve dates, check availability, book.
- Keep dates and availability in code; the model handles the conversation.
- Confirm before booking, enforce it in the policy layer, and re-check slots at booking time.
- The same tools plug into a real model's agent loop.
Course complete
You can now build the standard agentic workflow patterns (prompt chaining with gates, routing, parallel sectioning and voting, orchestrator-workers and evaluator-optimiser loops) and combine them into practical automations and assistants, using full agents only where they add something workflows can't.
Finished reading? Tick it off to track your progress.