to_dict

View as MarkdownOpen in Claude

Convert all contexts to a dictionary for SWML generation. Calls validate() first and raises ValueError if the configuration is invalid.

Returns

dict[str, Any] — A mapping of context names to their serialized dictionaries, ready for inclusion in the SWML document.

Example

from signalwire import AgentBase
agent = AgentBase(name="my-agent", route="/agent")
contexts = agent.define_contexts()
ctx = contexts.add_context("default")
ctx.add_step("greet").set_text("Hello!")
data = contexts.to_dict()
# {"default": {"steps": [{"name": "greet", "text": "Hello!"}]}}
agent.serve()