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 addContext() on a ContextBuilder or by calling getContext() to retrieve one that already exists.

Properties

name
stringRequired

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

Methods

Example

1import { ContextBuilder } from '@signalwire/sdk';
2
3const builder = new ContextBuilder();
4const main = builder.addContext('default');
5main.addStep('menu').setText('Ask whether the caller needs sales or support.');
6
7const support = builder.addContext('support');
8
9// System prompt for this context
10support.setSystemPrompt('You are a patient technical support engineer.');
11support.setConsolidate(true);
12
13// Fillers for smooth transitions
14support.addEnterFiller('en-US', [
15 'Let me connect you with support...',
16 'Transferring you now...',
17]);
18support.addExitFiller('en-US', [
19 'Thank you for contacting support.',
20 'Glad I could help.',
21]);
22
23// Navigation
24support.setValidContexts(['default']);
25
26// Steps
27support.addStep('diagnose', {
28 task: 'Understand the customer\'s issue and gather relevant details.',
29 criteria: 'Issue is clearly identified',
30 functions: ['lookup_account', 'check_status'],
31 validSteps: ['resolve'],
32});
33support.addStep('resolve', {
34 task: 'Resolve the issue or escalate to a specialist.',
35 functions: ['create_ticket', 'transfer_call'],
36 validSteps: ['farewell'],
37});
38support.addStep('farewell')
39 .setText('Thank the caller and end the conversation.')
40 .setFunctions('none')
41 .setEnd(true);