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
      • AgentServer
      • Configuration
      • ContextBuilder
      • DataMap
      • FunctionResult
        • addAction
        • addActions
        • addDynamicHints
        • clearDynamicHints
        • connect
        • createPaymentAction
        • createPaymentParameter
        • createPaymentPrompt
        • enableExtensiveData
        • enableFunctionsOnTimeout
        • executeRpc
        • executeSwml
        • hangup
        • hold
        • joinConference
        • joinRoom
        • pay
        • playBackgroundFile
        • recordCall
        • removeGlobalData
        • removeMetadata
        • replaceInHistory
        • rpcAiMessage
        • rpcAiUnhold
        • rpcDial
        • say
        • sendSms
        • setEndOfSpeechTimeout
        • setMetadata
        • setPostProcess
        • setResponse
        • setSpeechEventTimeout
        • simulateUserInput
        • sipRefer
        • stop
        • stopBackgroundFile
        • stopRecordCall
        • stopTap
        • switchContext
        • swmlChangeContext
        • swmlChangeStep
        • swmlTransfer
        • swmlUserEvent
        • tap
        • toDict
        • toggleFunctions
        • updateGlobalData
        • updateSettings
        • waitForUser
      • 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
  • Simple Prompt Swap
  • Full Reset with User Message
AgentsFunctionResult

switchContext

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

swmlChangeContext

Next
Built with

Perform an advanced context switch by replacing the system prompt, injecting a user message, or resetting the conversation entirely. This is more flexible than swmlChangeContext(), which switches to a pre-defined named context.

When only system_prompt is provided (no other arguments), it performs a simple string-based context switch. When multiple arguments are given, it constructs an object-based context switch with fine-grained control.

Parameters

opts
object

Optional context switch configuration.

opts.systemPrompt
string

New system prompt to replace the current one.

opts.userPrompt
string

A user message to inject into the conversation after the context switch.

opts.consolidate
boolean

When true, the existing conversation history is summarized into a condensed form before applying the new context. Reduces token usage on long conversations.

opts.fullReset
boolean

When true, performs a complete context reset, clearing all conversation history and starting fresh with the new prompt.

Returns

FunctionResult — this, for chaining.

Examples

Simple Prompt Swap

1import { FunctionResult } from '@signalwire/sdk';
2
3const result = new FunctionResult()
4 .switchContext({ systemPrompt: 'You are now a billing assistant.' });

Full Reset with User Message

1import { FunctionResult } from '@signalwire/sdk';
2
3const result = new FunctionResult()
4 .switchContext({
5 systemPrompt: 'You are a billing assistant.',
6 userPrompt: 'I need help with my invoice.',
7 fullReset: true,
8 });