CallSimulator
CallSimulator runs an agent’s tools through a simulated call in a test. It reads
the agent’s rendered SWML as the platform would and plays the model’s side: your
test says what the caller says and which tools the model calls. Where
swaig-test runs one tool call, the simulator runs a whole flow,
such as a confirmation that spans several steps.
Each call is checked the way the platform checks it:
- A tool the current step’s function list doesn’t offer doesn’t run, and the model gets the platform’s reply naming the tools it has.
- A tool with semantic gates runs only when your gate callback passes every gate.
- A result’s actions change the call: global data and
semantic_state, the step and context, which functions are on,say,wait_for_user,back_to_back_functions, gate marks, and the end of the call. Apost_processresult’s actions run after the model’s next reply, given withagent_says().
The simulator is an approximation of the platform, for testing your code’s
decisions. It doesn’t run a model, DataMap tools (give a stub), gather
questions, consolidation, the sliding window, or the gates’ decision model (give a
callback). model_view()
and gate_conversation()
raise NotImplementedError once the call has entered a step with a reset.
Parameters
agent
The agent to simulate a call to.
call_id
Keyword-only. The call’s id, as the agent’s tools see it in raw_data["call_id"].
gates
Keyword-only. Answers each semantic gate in place of the decision model, called as
gates(gate, sim, args) with the gate’s dictionary, the simulator, and the
call’s arguments. Return True or a probability at or above the gate’s threshold
to pass, False or a probability below it to fail, or "unclear". A failed gate
gives the model its on_fail; an unclear one gives its on_unclear. Without a
callback, every gate passes.
stubs
Keyword-only. Results for tools that don’t run locally, such as DataMap tools, by
name: fn(args) returns a FunctionResult, a dict, or text. Calling a DataMap
tool without a stub raises ValueError.
global_data
Keyword-only. Global data to start the call with, applied over the agent’s own.
check_tool_mentions
Keyword-only. True makes call()
raise ToolMentionError when a result, or the gate output
that blocked the call, names a tool that the step the call ends up in doesn’t
offer.
request_fields
Keyword-only. More fields for every simulated tool request, as the platform sends
them for a call, such as {"caller_id_num": "+15551234567"}.
Properties
step
The current step, or None when the agent has no contexts.
context
The current context, or None when the agent has no contexts.
global_data
The call’s global data, as the results so far have left it.
semantic_state
global_data["semantic_state"], or None.
params
The ai verb’s params, as the agent rendered them.
functions
The rendered function definitions, by name.
call_log
The conversation so far, as call log entries, each with a timestamp in
microseconds. Step text is kept as it went in; model_view() shows it expanded.
calls
Every tool call so far, as SimulatedCall objects.
marks
The semantic gate marks set so far, by name: the length of call_log when each
was set, so call_log[marks[name]:] is everything since it. The call keeps its
16 newest marks.
chaining
The back_to_back_functions setting, as the last result left it. Starts at
"forever".
waiting_for_user
Whether a result asked the model to wait for the caller. The caller’s next words clear it.
ended
Whether a result ended the call with hangup or stop.
Methods
Example
A test of a confirm flow built with
Proposal: the
order tool runs only after a read-back, and a yes
moves the call to the last step. To check changed code against real calls, record
tool requests with RequestRecorder.