set_initial_step

View as MarkdownOpen in Claude

Set which step the context starts on when entered. By default, a context starts on its first step (index 0). When a context has a preamble step that should only run on first entry — for example, a greeting — later entries via change_context can skip it by setting initial_step to a different step name.

initial_step is honoured both at conversation creation (when the context is first activated) and when switching to this context via change_context during the conversation.

Parameters

step_name
strRequired

Name of the step to start on. Must exist in this context’s step list; validated by ContextBuilder.validate().

Returns

Context — Self for method chaining.

Example

1from signalwire import AgentBase
2
3agent = AgentBase(name="support", route="/support")
4contexts = agent.define_contexts()
5
6ctx = contexts.add_context("support")
7ctx.add_step("greeting").set_text("Welcome the caller to support.")
8ctx.add_step("triage").set_text("Ask what they need help with.")
9ctx.set_initial_step("triage") # skip greeting on re-entry
10
11agent.serve()