Back to Mastra

Reference: voice.addInstructions() | Voice

docs/src/content/en/reference/voice/voice.addInstructions.mdx

2025-12-182.0 KB
Original Source

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

typescript
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.4',
  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

<PropertiesTable content={[ { name: 'instructions', type: 'string', description: "Instructions to guide the voice model's behavior", isOptional: false, }, ]} />

Return value

This method doesn't return a value.

Notes

  • Instructions are most effective when they're 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