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

1from signalwire import AgentBase
2
3agent = AgentBase(name="my-agent", route="/agent")
4
5contexts = agent.define_contexts()
6default = contexts.add_context("default")
7default.add_step("greet").set_text("Welcome the caller.")
8support = contexts.add_context("support")
9support.set_valid_contexts(["default", "billing"])
10support.add_step("help").set_text("Help the caller with their issue.")
11billing = contexts.add_context("billing")
12billing.add_step("invoice").set_text("Help with billing inquiries.")
13
14agent.serve()