Context

View as MarkdownOpen in Claude

A Context represents a distinct conversation mode — like “sales”, “support”, or “billing” — within a ContextBuilder. Each context holds an ordered sequence of Step objects and configures its own prompt, system prompt, fillers, and navigation rules.

You obtain a Context by calling add_context() on a ContextBuilder or by calling get_context() to retrieve one that already exists.

Properties

name
strRequired

Unique context name. When using a single context inside a ContextBuilder, this must be "default".

Methods

Example

from signalwire import AgentBase
agent = AgentBase(name="support-agent", route="/support")
contexts = agent.define_contexts()
main = contexts.add_context("default")
main.add_step("menu").set_text("Ask whether the caller needs sales or support.")
support = contexts.add_context("support")
# System prompt for this context
support.set_system_prompt("You are a patient technical support engineer.")
support.set_consolidate(True)
# Fillers for smooth transitions
support.add_enter_filler("en-US", [
"Let me connect you with support...",
"Transferring you now..."
])
support.add_exit_filler("en-US", [
"Thank you for contacting support.",
"Glad I could help."
])
# Navigation
support.set_valid_contexts(["default"])
# Steps
support.add_step("diagnose",
task="Understand the customer's issue and gather relevant details.",
criteria="Issue is clearly identified",
functions=["lookup_account", "check_status"],
valid_steps=["resolve"]
)
support.add_step("resolve",
task="Resolve the issue or escalate to a specialist.",
functions=["create_ticket", "transfer_call"],
valid_steps=["farewell"]
)
support.add_step("farewell") \
.set_text("Thank the caller and end the conversation.") \
.set_functions("none") \
.set_end(True)
agent.serve()