***

title: switchContext
slug: /reference/typescript/agents/function-result/switch-context
description: Perform an advanced context switch with prompt replacement and history control.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[swml-change-context]: /docs/server-sdks/reference/typescript/agents/function-result/swml-change-context

[functionresult]: /docs/server-sdks/reference/typescript/agents/function-result

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()`][swml-change-context],
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**

<ParamField path="opts" type="object" toc={true}>
  Optional context switch configuration.
</ParamField>

<Indent>
  <ParamField path="opts.systemPrompt" type="string" toc={true}>
    New system prompt to replace the current one.
  </ParamField>

  <ParamField path="opts.userPrompt" type="string" toc={true}>
    A user message to inject into the conversation after the context switch.
  </ParamField>

  <ParamField path="opts.consolidate" type="boolean" toc={true}>
    When `true`, the existing conversation history is summarized into a condensed
    form before applying the new context. Reduces token usage on long conversations.
  </ParamField>

  <ParamField path="opts.fullReset" type="boolean" toc={true}>
    When `true`, performs a complete context reset, clearing all conversation
    history and starting fresh with the new prompt.
  </ParamField>
</Indent>

## **Returns**

[`FunctionResult`][functionresult] -- `this`, for chaining.

## **Examples**

### Simple Prompt Swap

```typescript {4}
import { FunctionResult } from '@signalwire/sdk';

const result = new FunctionResult()
  .switchContext({ systemPrompt: 'You are now a billing assistant.' });
```

### Full Reset with User Message

```typescript {4}
import { FunctionResult } from '@signalwire/sdk';

const result = new FunctionResult()
  .switchContext({
    systemPrompt: 'You are a billing assistant.',
    userPrompt: 'I need help with my invoice.',
    fullReset: true,
  });
```