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 toState.
salon/state.py
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
whentells the model when to start the task. The library turns the task into a tool,verify_customer.- With
openingset tolisten, a step with no saved number says itsannounceline and waits for the caller. - When a number is saved,
opens_withandconfirmwork together. Code asks theconfirmline. The tool runs only when the model calls it again after the caller heard the question and said yes. assigncopies fields from the tool result into the state. This is the step that confirmscustomer_phone, asCONFIRMsays.
A group: verify, then book
manage_booking finds a time and books it. The book group runs both steps in order.
salon/agent.py
skip_when_confirmedskipsverify_customerwhen the number is already confirmed.argumentsare values the model passes when it starts the group. They are saved into the state.task_only_toolshides the diary tools from the main agent. Only the steps call them.sayis a line code speaks after the save. The model makes no request to confirm it. Its values are said by their type inAppointment: 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.”TasksSpecandTaskPlancheck everything at startup. A wrong tool name stops the agent before any call.
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.- “I’d like a haircut on Friday.” Robin starts
book. - Robin asks for your number, then reads it back. Say yes.
- Robin offers free times. Pick one.
- 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.