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

import { ContextBuilder } from '@signalwire/sdk';
const builder = new ContextBuilder();
const main = builder.addContext('default');
main.addStep('menu').setText('Ask whether the caller needs sales or support.');
const support = builder.addContext('support');
// System prompt for this context
support.setSystemPrompt('You are a patient technical support engineer.');
support.setConsolidate(true);
// Fillers for smooth transitions
support.addEnterFiller('en-US', [
'Let me connect you with support...',
'Transferring you now...',
]);
support.addExitFiller('en-US', [
'Thank you for contacting support.',
'Glad I could help.',
]);
// Navigation
support.setValidContexts(['default']);
// Steps
support.addStep('diagnose', {
task: 'Understand the customer\'s issue and gather relevant details.',
criteria: 'Issue is clearly identified',
functions: ['lookup_account', 'check_status'],
validSteps: ['resolve'],
});
support.addStep('resolve', {
task: 'Resolve the issue or escalate to a specialist.',
functions: ['create_ticket', 'transfer_call'],
validSteps: ['farewell'],
});
support.addStep('farewell')
.setText('Thank the caller and end the conversation.')
.setFunctions('none')
.setEnd(true);