addContext

View as MarkdownOpen in Claude

Create a new context and add it to the builder. Returns the Context object for further configuration.

A single-context agent must name its context "default" or validation will fail. Multi-context agents can use any names.

Parameters

name
stringRequired

Unique context name. When using a single context, it must be named "default".

Returns

Context — The newly created context, ready for adding steps.

Examples

Single context

1import { ContextBuilder } from '@signalwire/sdk';
2
3const builder = new ContextBuilder();
4const ctx = builder.addContext('default');
5ctx.addStep('greet').setText('Greet the caller and ask how you can help.');

Multiple contexts

1import { ContextBuilder } from '@signalwire/sdk';
2
3const builder = new ContextBuilder();
4const main = builder.addContext('default');
5const sales = builder.addContext('sales');
6const support = builder.addContext('support');
7
8main.addStep('menu').setText('Ask whether the caller needs sales or support.');
9sales.addStep('qualify').setText('Understand what product the caller wants.');
10support.addStep('diagnose').setText('Understand the customer\'s issue.');