Contexts
ContextBuilder API
API reference for ContextBuilder and Step classes, enabling multi-step conversation workflows.
Class Definitions
Overview
Contexts define structured conversation workflows with multiple steps.
Context Structure:
- Context - A named conversation workflow
- Steps - Sequential conversation phases
- Prompt text or POM sections
- Completion criteria
- Available functions
- Navigation rules
- Steps - Sequential conversation phases
Step Class
Constructor
set_text
Set the step’s prompt text directly.
add_section
Add a POM section to the step.
add_bullets
Add a section with bullet points.
set_step_criteria
Define when this step is complete.
set_functions
Set which functions are available in this step.
set_valid_steps
Set which steps can be navigated to.
set_valid_contexts
Set which contexts can be navigated to.
Step Context Switch Methods
set_reset_system_prompt
Set system prompt for context switching.
set_reset_user_prompt
Set user prompt for context switching.
set_reset_consolidate
Set whether to consolidate conversation on context switch.
set_reset_full_reset
Set whether to do full reset on context switch.
ContextBuilder Class
Constructor
Create a new context builder.
add_context
Add a context with its steps.
set_default_context
Set the default starting context.
build
Build the contexts structure for SWML.
Using with AgentBase
Multiple Contexts Example
Step Flow Diagram

Generated SWML Structure
The contexts system generates SWML with this structure:
Context Design Tips
Step criteria best practices:
- Be specific: “Complete when user provides full name AND phone number”
- Avoid ambiguity: Don’t use “when done” or “when finished”
- Include failure conditions: “Complete when verified OR after 3 failed attempts”
Function availability:
- Use
set_functions("none")for greeting/farewell steps where no actions are needed - Limit functions to what’s relevant for each step to prevent LLM confusion
- Always include escape routes (transfer, escalate) where appropriate