set_valid_contexts

View as MarkdownOpen in Claude

Set which contexts the agent can navigate to from this context. Acts as a context-level default; step-level set_valid_contexts() can further restrict or expand navigation for individual steps.

Parameters

contexts
list[str]Required

List of context names that are reachable from this context.

Returns

Context — Self for method chaining.

Example

from signalwire import AgentBase
agent = AgentBase(name="my-agent", route="/agent")
contexts = agent.define_contexts()
default = contexts.add_context("default")
default.add_step("greet").set_text("Welcome the caller.")
support = contexts.add_context("support")
support.set_valid_contexts(["default", "billing"])
support.add_step("help").set_text("Help the caller with their issue.")
billing = contexts.add_context("billing")
billing.add_step("invoice").set_text("Help with billing inquiries.")
agent.serve()