validate

View as MarkdownOpen in Claude

Validate the entire context configuration. Called automatically during SWML rendering, but can be called manually to catch errors early.

Checks performed:

  • At least one context exists.
  • A single context is named "default".
  • Every context has at least one step.
  • All step-level valid_steps references point to steps that exist within the same context (the special value "next" is always allowed).
  • All valid_contexts references at the context level point to contexts that exist in the builder.
  • All valid_contexts references at the step level point to contexts that exist in the builder.
  • Every context’s initial_step, when set, names a step in that context.
  • All gather_info configurations have at least one question, no duplicate keys, and valid completion_action targets.
  • When the builder is attached to an agent, no user-defined tool shares a name with a reserved native tool (next_step, change_context, gather_submit).
  • When the builder is attached to an agent, every name a step passes to set_functions([...]) is a registered SWAIG tool or a reserved native tool. A name that matches neither would render a dangling function reference. "none" and [] mean “disable all” and are never treated as references.

Returns

None — Raises ValueError with a descriptive message if validation fails.

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!")
try:
contexts.validate()
except ValueError as e:
print(f"Invalid context config: {e}")
agent.serve()