Skip to main content
You have: a call state that keeps the caller’s number, from Remember the caller. The caller asks for Friday, and the agent reads the diary.

What you add

The diary is a plain Python class, Salon, in salon/store.py. It keeps customers and bookings in memory. Copy the file from the example. You do not write it here. Each method is typed, and each argument says what it means. Each answer has a Pydantic model too. This is the shape of find_slots and its answer, Diary.
salon/store.py
Now turn the method into a tool. local_tool reads the types and the descriptions and builds the tool schema. A ToolRegistry holds the tools of one agent.
salon/agent.py
Three options matter here.
  1. output names the answer’s model. The method returns a dict, so it names the model here. A method that returns a Diary needs no output=. Every answer is checked against it, and an answer of the wrong shape fails the call.
  2. locked fills customer_phone from the call state. The model never sees that argument, so it cannot invent a number. While no number is saved, the call is refused with a hint.
  3. announce is a line the agent says as the tool starts. A refused call says nothing.
Last, give the registry to the agent. Build it once, not for each call.

Try it

Start the agent as before.
  1. “I’d like a haircut on Friday.” Robin has no number yet, so the tool is refused. Robin should ask for your number.
  2. Give a number with its country code. Then say “Friday” again.
  3. You should hear “Let me have a look.” Then Robin should read out free times from the diary.
The demo diary offers 9:00 AM, 11:30 AM and 3:00 PM for each service.

Why it works this way

The model fills tool arguments from what it heard. It can mishear or invent a value. So the library checks every call against the schema before your code runs, and a bad one goes back to the model with what to fix. A value the caller never chooses, like the number of the person on the line, comes from the state instead. And a slow tool is not silence, because the announce line plays first.

What you have now

Next: Book step by step

Turn booking into a task, so Robin confirms before it writes.
Go deeper: Tools.