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)
sim.caller("A large tea, please.").agent_says("A large tea. Anything else?")
sim.caller("No, that's all.")
print([entry["role"] for entry in sim.call_log])
# ['system', 'user', 'assistant', 'user']