Skip to main content
You have: a typed diary tool, from Check the diary. The caller picks a time, the agent asks “Shall I book it?”, and the diary changes only after a yes.

What you add

A task is a step with its own prompt, its own tools and a finish check. The model does not have to remember the order. Code runs it. First, the state needs the values the steps save. Add these fields to State.
salon/state.py
Next, add the other two diary methods to the registry from the last page.
salon/agent.py
Customer and BookingAction are the answers’ models, in salon/store.py. A booking’s answer holds its appointment, typed as the Appointment above.

One task: verify the caller

verify_customer reads the number from the state, asks the caller to confirm it, and saves the result.
salon/agent.py
  1. when tells the model when to start the task. The library turns the task into a tool, verify_customer.
  2. With opening set to listen, a step with no saved number says its announce line and waits for the caller.
  3. When a number is saved, opens_with and confirm work together. Code asks the confirm line. The tool runs only when the model calls it again after the caller heard the question and said yes.
  4. assign copies fields from the tool result into the state. This is the step that confirms customer_phone, as CONFIRM says.

A group: verify, then book

manage_booking finds a time and books it. The book group runs both steps in order.
salon/agent.py
  1. skip_when_confirmed skips verify_customer when the number is already confirmed.
  2. arguments are values the model passes when it starts the group. They are saved into the state.
  3. task_only_tools hides the diary tools from the main agent. Only the steps call them.
  4. say is a line code speaks after the save. The model makes no request to confirm it. Its values are said by their type in Appointment: the service as words, the day from today, the time on the clock. The caller hears “Lovely, your hair color is booked for tomorrow, October 16 at 9:00 AM.”
  5. TasksSpec and TaskPlan check everything at startup. A wrong tool name stops the agent before any call.
Add to the prompt: “Every booking request goes to book. Never ask for the number yourself.” Last, give the spec the plan instead of the tools, and the salon’s timezone. Build the CallState with confirm=CONFIRM.

Try it

Start the agent as before.
  1. “I’d like a haircut on Friday.” Robin starts book.
  2. Robin asks for your number, then reads it back. Say yes.
  3. Robin offers free times. Pick one.
  4. Robin asks “Shall I book your haircut for …?” Say yes. Robin says the booking line and asks what else.

Why it works this way

On a plain agent the model decides the order, so it can skip a check or write to the diary on a guess. Here the order is code. A write waits for the caller’s yes, and the saved number is confirmed by the step that asked. The step also cannot get stuck. When the model says “Noted” and no finish check passes, the library asks it directly: finished, or not yet?

What you have now

Next: Hand off complaints

Add a second agent for complaints, and a handoff to it.
Go deeper: Tasks.