Recipes← all recipesView on GitHub

Change a voice AI agent's instructions mid-call

AI Agentsvoice AI prompt switching mid-call

A tool result replaces the system prompt on the call in progress, summarising or dropping the earlier turns, with no transfer.

contexts

The claim

A tool result can carry a context_switch action. The platform replaces the system prompt of the conversation that is already running, on the same call, with no transfer and no second agent. You choose whether the turns so far are summarised into the new context or dropped. The context switch guide documents the action and its fields.

Why it holds

The SDK method is switch_context; the wire key is context_switch. The verifier asserts the key and the complete payload.

How it works

One agent takes the call, finds out what it is about, then hands over to itself.

@AgentBase.tool(name="become_billing", description="...", parameters={...})
def become_billing(self, args, raw_data):
    return FunctionResult("Switching you to billing.").switch_context(
        system_prompt=BILLING_PROMPT, consolidate=True
    )

The function result the platform receives:

{"response": "Switching you to billing.",
 "action": [{"context_switch": {
   "system_prompt": "You are now the billing specialist ...",
   "consolidate": true}}]}

consolidate asks the platform to summarise the conversation so far into the new context. full_reset drops the history instead. start_over uses it and hands back the prompt the call opened with. Both are fields of the documented action object.

With system_prompt alone the SDK emits the prompt as a bare string. The bundled schema documents context_switch as an object, so every switch in this recipe passes consolidate or full_reset and gets the object form. The verifier shows both shapes.

Limitations

The switch replaces the prompt, not the toolset. Every tool on the agent stays registered after the switch. To scope tools, use contexts and steps. Each step’s functions field names the tools it offers, per the steps reference.

consolidate is a summary the platform writes, not a record. This recipe does not carry state across the switch. For a fact that must survive verbatim, see enforce-state-transitions-in-a-tool-handler under Where this sits, where a handler writes global_data.

What to change first

Change consolidate=True to full_reset=True in become_billing and run the verifier. The payload assertion fails, and on a call the billing specialist starts with no memory of what the caller said at the front desk.