Maintaining Context

Every lever the Voice Agent API gives you for shaping what the agent knows and remembers across a session.
Voice Agent

A voice agent’s behavior on any call is the sum of a few moving parts: the prompt that shaped it, the history you handed it on connect, anything either side has injected during the call, and any function results it has gathered. This page covers every lever the API gives you for managing that context.

Levers at a glance

LeverWhen it appliesWhere it livesEffect
System promptConnectagent.think.prompt in SettingsSets persona and rules for the whole session
Prompt updateMid-callUpdatePrompt client messageReplaces the system prompt for the rest of the session
HistoryConnectagent.context.messages in SettingsLoads prior turns and function calls before the session starts
Inject agent messageMid-callInjectAgentMessageMakes the agent speak a specific line
Inject user messageMid-callInjectUserMessageAdds a synthetic user turn the agent reacts to
Function resultsMid-callFunction call response payloadsBecomes part of the agent’s working memory
Reusable configurationPre-callReusable Agent ConfigurationsStores a full agent block for reuse
History flagConnectsettings.flags.historyDisables history retention entirely

The rest of this page walks each lever in detail. You can mix all of them in the same session.

System prompt

The system prompt is the agent’s initial brief. It defines persona, scope, and any rules the agent should follow throughout the call. Set it inside the agent.think.prompt field of your Settings message at connect time.

1{
2 "type": "Settings",
3 "agent": {
4 "think": {
5 "provider": { "type": "open_ai", "model": "gpt-4o-mini" },
6 "prompt": "You are a friendly support agent for Acme. Always confirm the customer's account number before answering billing questions."
7 }
8 }
9}

For voice-specific prompt-writing patterns (formatting numbers for TTS, keeping turns short, avoiding markdown the agent will try to read aloud), see Prompting Voice Agents.

Prompt update at runtime

If you need to change the agent’s behavior part-way through a call (a phase change, a hand-off to a new persona, an updated rule), send an UpdatePrompt message. The new prompt replaces the system prompt for the rest of the session.

1{
2 "type": "UpdatePrompt",
3 "prompt": "You are now a billing specialist. Resolve the dispute the customer just described."
4}

Combine UpdatePrompt with UpdateThink if you also want to swap the LLM provider mid-call.

History

When you start a new session, you can hand the agent the history of prior interactions so it picks up where the last call left off. History is provided through agent.context.messages and supports two message shapes that can be mixed in the same array.

Conversation history

Plain back-and-forth between user and assistant.

1{
2 "type": "Settings",
3 "agent": {
4 "context": {
5 "messages": [
6 { "type": "History", "role": "user", "content": "I'm trying to recover my account." },
7 { "type": "History", "role": "assistant", "content": "Sure, I can help. What email did you use to sign up?" }
8 ]
9 }
10 }
11}

Function call history

Function calls executed in earlier sessions, with arguments and results.

1{
2 "type": "Settings",
3 "agent": {
4 "context": {
5 "messages": [
6 { "type": "History", "role": "user", "content": "What's the weather in New York?" },
7 {
8 "type": "History",
9 "function_calls": [
10 {
11 "id": "fc_weather_12345",
12 "name": "get_weather",
13 "client_side": true,
14 "arguments": "{\"location\": \"New York\"}",
15 "response": "Partly cloudy, 22°C."
16 }
17 ]
18 },
19 { "type": "History", "role": "assistant", "content": "It's partly cloudy in New York, around 22 degrees." }
20 ]
21 }
22 }
23}

The full schema and field-by-field reference live on the History page.

Toggling history

History is enabled by default. To disable it, set:

1{
2 "type": "Settings",
3 "settings": {
4 "flags": { "history": false }
5 }
6}

Inject messages

Two client messages let you add to context mid-call.

InjectAgentMessage

Make the agent say something specific, immediately. The injected text is treated as if the agent had just produced it.

1{ "type": "InjectAgentMessage", "content": "Hold on a moment while I check that for you." }

Useful for filler responses, status updates while a slow tool runs, or scripted follow-ups. Reference: Inject Agent Message.

InjectUserMessage

Push a synthetic user turn into the conversation. The agent processes it as if the user said it. Useful for orchestrated hand-offs from your application to the agent without going through the microphone.

1{ "type": "InjectUserMessage", "content": "The customer's authentication is now complete." }

Reference: Inject User Message.

Function results as context

Function call responses returned to the agent become part of its working context. The agent can reference them in later turns, decide whether to call again, and use the results to shape what it says next. See Function Calling for the full request/response loop and Function Call Context for how function results interact with conversation history.

Reusable configurations

If your agent’s prompt, providers, and tools are stable across many sessions, save them as a Reusable Agent Configuration. You get back a UUID that you can pass in place of the full agent object on every connection.

Reusable configurations are most useful when:

  • The same prompt is used by many sessions
  • You want to update prompts without redeploying the client
  • Multiple environments need to share the same agent definition

The reusable configuration only covers the agent block. Per-session context (history, runtime injections) is still passed at connect time or during the call.

Choosing which lever for which job

You want to…Use
Set persona and rules at the start of the callSystem prompt
Change the agent’s behavior part-way through a callUpdatePrompt
Resume a prior conversation seamlesslyHistory
Replay function results from a prior sessionHistory with function calls
Have the agent speak a specific line right nowInjectAgentMessage
Tell the agent what just happened in your applicationInjectUserMessage
Reuse the same agent definition across sessions or environmentsReusable Agent Configurations
Disable history entirelysettings.flags.history: false