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

1from signalwire import AgentBase
2
3agent = AgentBase(name="my-agent", route="/agent")
4
5contexts = agent.define_contexts()
6ctx = contexts.add_context("default")
7ctx.add_step("greet").set_text("Hello!")
8
9data = contexts.to_dict()
10# {"default": {"steps": [{"name": "greet", "text": "Hello!"}]}}
11
12agent.serve()