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

1from signalwire import AgentBase
2
3agent = AgentBase(name="support-agent", route="/support")
4
5contexts = agent.define_contexts()
6main = contexts.add_context("default")
7main.add_step("menu").set_text("Ask whether the caller needs sales or support.")
8
9support = contexts.add_context("support")
10
11# System prompt for this context
12support.set_system_prompt("You are a patient technical support engineer.")
13support.set_consolidate(True)
14
15# Fillers for smooth transitions
16support.add_enter_filler("en-US", [
17 "Let me connect you with support...",
18 "Transferring you now..."
19])
20support.add_exit_filler("en-US", [
21 "Thank you for contacting support.",
22 "Glad I could help."
23])
24
25# Navigation
26support.set_valid_contexts(["default"])
27
28# Steps
29support.add_step("diagnose",
30 task="Understand the customer's issue and gather relevant details.",
31 criteria="Issue is clearly identified",
32 functions=["lookup_account", "check_status"],
33 valid_steps=["resolve"]
34)
35support.add_step("resolve",
36 task="Resolve the issue or escalate to a specialist.",
37 functions=["create_ticket", "transfer_call"],
38 valid_steps=["farewell"]
39)
40support.add_step("farewell") \
41 .set_text("Thank the caller and end the conversation.") \
42 .set_functions("none") \
43 .set_end(True)
44
45agent.serve()