メインコンテンツへ移動

voice.addInstructions()

addInstructions() メソッドは、リアルタイムの対話中にモデルの動作を導く指示を Voice Provider に設定します。会話全体のコンテキストを保持するリアルタイム Voice Provider で特に役立ちます。

使用例
使用例への直接リンク

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()

パラメーター
パラメーターへの直接リンク


instructions:

string
Voice モデルの動作を導く指示

戻り値
戻り値への直接リンク

このメソッドは値を返しません。

注意事項
注意事項への直接リンク

  • 指示は、明確かつ具体的で Voice 対話に関連しているほど効果的です
  • 主に、会話コンテキストを保持するリアルタイム Voice Provider で使用します
  • 指示をサポートしない Voice Provider で呼び出すと、警告を記録して何も実行しません
  • このメソッドで追加した指示は、通常、関連付けられた Agent の指示と組み合わされます
  • 最良の結果を得るには、会話を開始する前(connect() の呼び出し前)に指示を追加してください
  • addInstructions() を複数回呼び出した場合、既存の指示を置換するか追加するかは Provider の実装によって異なります