set_valid_contexts

View as MarkdownOpen in Claude

Set which contexts the agent can navigate to from this step. Overrides any context-level set_valid_contexts() for this step.

Parameters

contexts
list[str]Required

List of context names that are reachable from this step.

Returns

Step — Self for method chaining.

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("Welcome the caller.")
8step = ctx.add_step("transfer")
9step.set_text("Transfer the caller to the appropriate department.")
10step.set_valid_contexts(["billing", "support"])
11billing = contexts.add_context("billing")
12billing.add_step("invoice").set_text("Help with billing inquiries.")
13support = contexts.add_context("support")
14support.add_step("help").set_text("Help with support issues.")
15
16agent.serve()