For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
Log inSign up
Support
GuidesReference
GuidesReference
    • Core
      • Overview
    • Agents
      • Overview
      • AgentBase
        • addAnswerVerb
        • addFunctionInclude
        • addHint
        • addHints
        • addInternalFiller
        • addLanguage
        • addMcpServer
        • addPatternHint
        • addPostAiVerb
        • addPostAnswerVerb
        • addPreAnswerVerb
        • addPronunciation
        • addSkill
        • addSkillByName
        • addSwaigQueryParams
        • asRouter
        • autoMapSipUsernames
        • clearPostAiVerbs
        • clearPostAnswerVerbs
        • clearPreAnswerVerbs
        • clearSwaigQueryParams
        • defineContexts
        • defineTool
        • defineTools
        • defineTypedTool
        • enableDebugEvents
        • enableDebugRoutes
        • enableMcpServer
        • enableSipRouting
        • extractSipUsername
        • getApp
        • getBasicAuthCredentials
        • getFullUrl
        • getMcpServers
        • getName
        • getPostPrompt
        • getPrompt
        • getPromptPom
        • getRegisteredTools
        • getTool
        • handleMcpRequest
        • hasSkill
        • isMcpServerEnabled
        • listSkills
        • manualSetProxyUrl
        • onDebugEvent
        • onFunctionCall
        • onSummary
        • onSwmlRequest
        • promptAddSection
        • promptAddSubsection
        • promptAddToSection
        • promptHasSection
        • registerSipUsername
        • registerSwaigFunction
        • removeSkill
        • removeSkillByName
        • renderSwml
        • resetContexts
        • run
        • serve
        • setDynamicConfigCallback
        • setFunctionIncludes
        • setGlobalData
        • setInternalFillers
        • setLanguages
        • setNativeFunctions
        • setParam
        • setParams
        • setPostPrompt
        • setPostPromptLlmParams
        • setPostPromptUrl
        • setPromptLlmParams
        • setPromptPom
        • setPromptText
        • setPronunciations
        • setupGracefulShutdown
        • setWebHookUrl
        • updateGlobalData
        • validateBasicAuth
        • validateToolToken
      • AgentServer
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
      • Helper Functions & Utilities
      • LiveWire
      • PomBuilder
      • Prefabs
      • SkillBase
      • SkillManager
      • SkillRegistry
      • Skills
      • SwaigFunction
      • SwmlBuilder
      • SWMLService
    • RELAY
      • Overview
      • Actions
      • Call
      • Constants
      • Events
      • Message
      • RelayClient
      • RelayError
    • REST Client
      • Overview
      • Addresses
      • Calling
      • ChatResource
      • Compat
      • Datasphere
      • Fabric
      • ImportedNumbersResource
      • Logs
      • LookupResource
      • MFA
      • Number Groups
      • Phone Numbers
      • Project
      • PubSubResource
      • Queues
      • Recordings
      • Registry
      • RestClient
      • RestError
      • Short Codes
      • SIP Profile
      • Verified Callers
      • Video
LogoLogoSignalWire Docs
Log inSign up
Support
On this page
  • Parameters
  • Returns
  • Examples
  • Fluent ContextBuilder
  • Using an existing ContextBuilder
AgentsAgentBase

defineContexts

|View as Markdown|Open in Claude|
Was this page helpful?
Edit this page
Previous

defineTool

Next
Built with

Define contexts and steps for multi-step conversation workflows. Contexts allow an agent to guide the caller through a structured sequence of interactions — such as gathering information, verifying identity, and then performing an action.

Returns a ContextBuilder for fluent context definition. If an existing ContextBuilder instance is passed, it is used directly. Otherwise a new empty ContextBuilder is created and returned.

Contexts can coexist with traditional prompts. The only restriction is that POM sections and raw text cannot be mixed in the main prompt.

Parameters

contexts
ContextBuilder | Record<string, unknown> | undefined

An existing ContextBuilder instance to use directly. If omitted or a plain object is passed, a new empty ContextBuilder is created instead.

Returns

ContextBuilder — The active ContextBuilder for further configuration.

Examples

Fluent ContextBuilder

1import { AgentBase } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'intake', route: '/intake' });
4const ctx = agent.defineContexts().addContext('default');
5
6ctx.addStep('greeting')
7 .setText('Greet the caller and ask for their name.')
8 .setStepCriteria('The caller has provided their name.')
9 .setFunctions(['lookup_account'])
10 .setValidSteps(['verify']);
11
12ctx.addStep('verify')
13 .setText('Verify the caller\'s identity.')
14 .setStepCriteria('Identity verified.')
15 .setValidSteps(['assist']);
16
17ctx.addStep('assist')
18 .setText('Help the caller with their request.')
19 .setFunctions(['search_orders', 'process_return']);
20
21await agent.serve();

addStep() is a method on Context, not on Step. Since Step methods like setValidSteps() return the Step (not the parent Context), you must keep a reference to the Context and call addStep() on it for each new step.

Using an existing ContextBuilder

1import { AgentBase, ContextBuilder } from '@signalwire/sdk';
2
3const builder = new ContextBuilder();
4const ctx = builder.addContext('default');
5ctx.addStep('greeting').setText('Greet the caller.');
6ctx.addStep('verify').setText('Verify identity.');
7
8const agent = new AgentBase({ name: 'intake', route: '/intake' });
9agent.defineContexts(builder);
10await agent.serve();