Operations
The signalwire.operations package builds an agent from the things it can change
for a caller, such as cancelling an order or moving a booking. You write each
operation once: its fields, a docstring the model reads, and prepare(), which
checks the request and returns a Change or raises Need or
Refuse. The SDK generates the tools, the steps, the confirm gate, and
the call’s record in global data, and runs every change the same way.
Change lifecycle
Every change goes through the same steps:
- The model calls an operation’s tool with everything the caller said. The tool of
an operation that takes fields has a required
data_supplied_by_userargument, and nothing runs unless the model sets it totrue. An operation with no fields has no such argument, and lookups don’t take it either. - A required
Fieldwithaskthat the model sent empty,null, or as"not said"is asked for beforeprepare()runs. prepare()returns aChange, or raisesNeed(something wasn’t said) orRefuse(the request breaks a rule). Nothing is written yet.- The change becomes the one waiting for the caller’s answer, the call moves to the
confirmstep, and the platform says the change’sread_backword for word. - The model calls
confirm_changeordecline_change.confirm_changecarries one semantic gate: did the caller agree to the change read back. A yes said while the read-back was still playing counts. - The change’s writes run in order. A write that raises
WriteFailedstops the change, and the writes before it stay made. - The change is added to the call’s record, with any money it moved. A change set aside for after this one is offered next.
When the caller asks for something else while a change waits, the SDK compares the
two by what both touch. It merges them, sets one aside for after the other, replaces
part of the waiting change, or refuses. The hooks for this are on
Operation.
What the SDK generates
- Steps:
identify(when the service identifies callers),main,confirm, a step for each operation withguidance, each declared phase, andtransferred(when the service offers a transfer). Tool handlers move between them. - Prompt sections: Role, from
role=, and Rules, fromDEFAULT_RULESorrules=. - Tools: one per operation and lookup,
confirm_changeanddecline_changewhen any operation confirms,find_accountwithidentify(), andtransfer_to_humanwithtransfer_with(). - The call’s record, in
global_data.ops, whosenowline theconscienceparam shows on every request.
Every generated tool’s result starts with back_to_back_functions set to
"forever", so a refused gate doesn’t stop the model from chaining tools for the
rest of the call.
Example
preview() prints each generated step’s text and tools as the model gets them.
The CallSimulator in signalwire.testing runs an operations agent’s tools
offline, including the steps they move to and the gates.
Replacing deprecated prefabs
ConciergeAgent, ReceptionistAgent, and
FAQBotAgent are deprecated:
- For bookings, use
FrontDeskAgentwith theAppointmentspack in place ofConciergeAgent, andInfoBotKnowledgefor amenities and hours. - For transfers to departments, use
FrontDeskAgentin place ofReceptionistAgent. - For answers from a knowledge base, use
InfoBotKnowledgein place ofFAQBotAgent.