Skip to navigation

call

View as MarkdownOpen in Claude

The model calls the tool name with args. The call is checked the way the platform checks it:

  • A tool the current step doesn’t offer, or one the agent doesn’t have, doesn’t run. The model gets the platform’s reply, which names the tools it has, or the agent’s unavailable_function_response when one is set.
  • next_step and change_context move the call when the step allows the target.
  • A gated tool runs only when the gate callback passes every gate; otherwise the model gets the first failing gate’s on_fail, or an unclear gate’s on_unclear.
  • Otherwise the tool’s handler, or its stub, runs with a request like the platform’s, including call_id, tool_call_id, global_data, any request_fields, and the conversation when swaig_post_conversation is on. Its result’s actions change the call. A post_process result’s actions wait for the next agent_says(), and a newer one replaces actions still waiting.

Parameters

name
strRequired

The tool’s name.

args
Mapping[str, Any] | NoneDefaults to None

The arguments the model sends. None sends none.

Returns

SimulatedCall — What the call came to.

Raises

  • RuntimeError — the call has ended.
  • ValueError — the tool is a DataMap tool and has no stub.
  • ToolMentionError — with check_tool_mentions=True, the result names a tool the step it leaves the call in doesn’t offer.

Example

from signalwire import AgentBase, FunctionResult
from signalwire.testing import CallSimulator
agent = AgentBase(name="orders", route="/orders")
agent.prompt_add_section("Role", "You take orders.")
agent.define_tool("review_order", "Read the order back", {"type": "object", "properties": {}},
lambda args, raw_data: FunctionResult("Read the order back.").swml_change_step("confirm"))
agent.define_tool("place_order", "Place the order", {"type": "object", "properties": {}},
lambda args, raw_data: FunctionResult("Order placed."))
ctx = agent.define_contexts().add_context("default")
ctx.add_step("take").set_text("Take the order.").set_functions(["review_order"])
ctx.add_step("confirm").set_text("Confirm the order.").set_functions(["place_order"]).set_history("isolate")
sim = CallSimulator(agent)
blocked = sim.call("place_order")
print(blocked.ran, blocked.blocked_by)
# False step
outcome = sim.call("review_order")
print(outcome.ran, sim.step)
# True confirm