跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

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
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({
id: 'customer-support-agent',
name: 'Customer Support Agent',
instructions: 'You are a helpful customer support agent for a software company.',
model: 'openai/gpt-5.6-sol',
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
Parameters的直接链接


instructions:

string
Instructions to guide the voice model's behavior

Return value
Return value的直接链接

This method doesn't return a value.

Notes
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 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