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

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