Skip to main content

voice.addInstructions()

The addInstructions() method equips a voice provider with instructions that guide the model's behavior during real-time interactions. This is particularly useful for real-time voice providers that maintain context across a conversation.

Usage Example
Direct link to Usage Example

import { OpenAIRealtimeVoice } from '@mastra/voice-openai-realtime'
import { Agent } from '@mastra/core/agent'

// Initialize a real-time voice provider
const voice = new OpenAIRealtimeVoice({
realtimeConfig: {
model: 'gpt-5.1-realtime',
apiKey: process.env.OPENAI_API_KEY,
},
})

// Create an agent with the voice provider
const agent = new Agent({
name: 'Customer Support Agent',
instructions: 'You are a helpful customer support agent for a software company.',
model: 'openai/gpt-5.1',
voice,
})

// Add additional instructions to the voice provider
voice.addInstructions(`
When speaking to customers:
- Always introduce yourself as the customer support agent
- Speak clearly and concisely
- Ask clarifying questions when needed
- Summarize the conversation at the end
`)

// Connect to the real-time service
await voice.connect()

Parameters
Direct link to Parameters


instructions:

string
Instructions to guide the voice model's behavior

Return Value
Direct link to Return Value

This method does not return a value.

Notes
Direct link to Notes

  • Instructions are most effective when they are clear, specific, and relevant to the voice interaction
  • This method is primarily used with real-time voice providers that maintain conversation context
  • If called on a voice provider that doesn't support instructions, it will log a warning and do nothing
  • Instructions added with this method are typically combined with any instructions provided by an associated Agent
  • For best results, add instructions before starting a conversation (before calling connect())
  • Multiple calls to addInstructions() may either replace or append to existing instructions, depending on the provider implementation
On this page