The features in this chapter build on the fundamentals covered earlier. While basic agents handle free-form conversations well, many real-world applications require more structure: guided workflows that ensure certain information is collected, the ability to transfer between different “departments” or personas, recording for compliance, and integration with knowledge bases.
These advanced features transform simple voice agents into sophisticated conversational applications capable of handling complex business processes.
Contexts are the SDK’s answer to a common challenge: how do you ensure a conversation follows a specific path? Regular prompts work well for open-ended conversations, but many business processes require structure — collecting specific information in a specific order, or routing callers through a defined workflow.
Think of contexts as conversation “states” or “modes.” Each context can have its own persona, available functions, and series of steps. The AI automatically manages transitions between contexts and steps based on criteria you define.
Use contexts when you need:
Common context patterns:
Understanding how contexts, steps, and navigation work together is essential for building effective workflows.
Key concepts:
The AI automatically tracks which context and step the conversation is in. When step criteria are met, it advances to the next allowed step. When context navigation is permitted and appropriate, it switches contexts entirely.

How state flows through contexts:
step_criteria is satisfiedvalid_steps to advance within the contextvalid_contexts allows, AI can switch to a different context entirelyisolated, consolidate, or full_reset settings control what conversation history carries overSteps can be fully configured in a single add_step() call using keyword arguments:
The task parameter creates a POM section titled “Task” with the given text. The bullets, criteria, functions, and valid_steps parameters map to add_bullets(), set_step_criteria(), set_functions(), and set_valid_steps() respectively. You can still use the method-chaining API when you need more control.
Simple text prompt for the step:
POM-style structured prompts:
Define when the step is complete:
Control step navigation:
Restrict available functions per step:
Allow navigation to other contexts:
Control how steps transition without relying on criteria evaluation:
These flags are useful for non-interactive steps like announcements, automated transitions, or terminal farewell steps.
Step criteria tell the AI when a step is “complete” and it’s time to move on. Writing good criteria is crucial — too vague and the AI may advance prematurely; too strict and the conversation may get stuck.
Good criteria are:
Examples of well-written criteria:
Problematic criteria to avoid:
Truncate conversation history when entering:
New system prompt when entering context:
Inject a user message when entering:
Summarize previous conversation when switching:
Completely reset conversation state:
Add transition phrases:
set_valid_steps(["next"]) - Go to next sequential stepset_valid_steps(["step_name"]) - Go to specific stepset_valid_steps(["a", "b"]) - Multiple optionsYou can set valid_steps at the context level to apply default step navigation for all steps in the context. Step-level valid_steps overrides context-level when set.
set_valid_contexts(["other_context"]) - Allow context switchchange_context("context_name") automaticallyisolated=True - Clear conversation historyconsolidate=True - Summarize previous conversationfull_reset=True - Complete prompt replacementAfter defining contexts and steps, you can retrieve, modify, reorder, or remove them programmatically.
Use clear_sections() to remove all POM sections and text from a step so you can repopulate it:
The gather info system lets you define structured question sequences within a step. Questions are presented one at a time via the SignalWire platform’s built-in gather mechanism, producing zero tool_call/tool_result entries in the LLM conversation history. This keeps the history clean and focused.
The ContextBuilder validates your configuration:
valid_steps must reference existing steps (or “next”)valid_contexts must reference existing contextsset_text() with add_section() on same stepset_prompt() with add_section() on same contextWhen the AI switches between contexts, several things can happen depending on your configuration. Understanding these options helps you create smooth transitions.
When isolated=True, the conversation history is cleared when entering the context. This is useful when:
The caller won’t notice — the AI simply starts fresh with no memory of the previous context.
When consolidate=True, the AI summarizes the previous conversation before switching. This preserves important information without carrying over the full history:
The summary includes key facts and decisions, giving the new context awareness of what happened without the full transcript.
full_reset=True goes further than isolation — it completely replaces the system prompt and clears all state:
Use this when the new context needs to behave as if it were a completely different agent.
Fillers provide audio feedback during context switches, making transitions feel natural:
The AI randomly selects from the filler options, providing variety in the transitions.
When contexts don’t behave as expected, use these debugging strategies:
Check step criteria: If stuck on a step, the criteria may be too strict. Temporarily loosen them to verify the flow works.
Verify navigation paths: Ensure valid_steps and valid_contexts form a complete graph. Every step should have somewhere to go (unless it’s a terminal step).
Test with swaig-test: The testing tool shows context configuration in the SWML output:
Add logging in handlers: If you have SWAIG functions, log when they’re called to trace the conversation flow.
Watch for validation errors: The ContextBuilder validates your configuration at runtime. Check logs for validation failures.
DO:
DON’T: