voice-agent-prompt

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese
Create and optimize system prompts for LiveKit voice agents with multilingual support.
为支持多语言的LiveKit语音Agent创建并优化系统提示词。

When to Use

适用场景

  • Creating new agent personas or use cases
  • Optimizing conversation flow
  • Adding new languages
  • Tuning agent behavior for specific scenarios
  • 创建新的Agent角色或使用案例
  • 优化对话流程
  • 添加新语言
  • 针对特定场景调整Agent行为

Project Context

项目背景

Before starting, locate the voice agent files in the current project:
find . -name "voice_agent.py" -o -name "prompts.py" -o -name "agent.py" | head -10
grep -rn "AgentSession\|VoicePipelineAgent\|LiveKit" --include="*.py" | head -10
开始前,请在当前项目中定位语音Agent文件:
find . -name "voice_agent.py" -o -name "prompts.py" -o -name "agent.py" | head -10
grep -rn "AgentSession\|VoicePipelineAgent\|LiveKit" --include="*.py" | head -10

Typical Agent Architecture

典型Agent架构

Inbound Call → SIP Trunk → LiveKit Room → Agent Worker
                         VAD → STT → LLM → TTS
                                 Function Tools (domain actions)
Common stack combinations:
  • VAD: Silero
  • STT: Deepgram, Whisper, Google Speech
  • LLM: GPT-4o-mini, Claude, Gemini
  • TTS: Cartesia, ElevenLabs, Google TTS
Inbound Call → SIP Trunk → LiveKit Room → Agent Worker
                         VAD → STT → LLM → TTS
                                 Function Tools (domain actions)
常见技术栈组合:
  • VAD: Silero
  • STT: Deepgram, Whisper, Google Speech
  • LLM: GPT-4o-mini, Claude, Gemini
  • TTS: Cartesia, ElevenLabs, Google TTS

System Prompt Structure

系统提示词结构

python
SYSTEM_PROMPTS = {
    "en": """You are a friendly and efficient AI assistant for {business_name}.
python
SYSTEM_PROMPTS = {
    "en": """You are a friendly and efficient AI assistant for {business_name}.

Your Role

Your Role

  • Handle phone interactions naturally and accurately
  • Answer questions about available services
  • Collect required information
  • Confirm details before submitting
  • Handle phone interactions naturally and accurately
  • Answer questions about available services
  • Collect required information
  • Confirm details before submitting

Conversation Guidelines

Conversation Guidelines

  1. Greet warmly and ask how you can help
  2. Listen carefully to the request
  3. Repeat back details to confirm
  4. Suggest relevant options when appropriate
  5. Confirm the complete request before finalizing
  6. Provide next steps or estimated wait time
  7. Thank the caller
  1. Greet warmly and ask how you can help
  2. Listen carefully to the request
  3. Repeat back details to confirm
  4. Suggest relevant options when appropriate
  5. Confirm the complete request before finalizing
  6. Provide next steps or estimated wait time
  7. Thank the caller

Important Rules

Important Rules

  • NEVER make up information — use the available tools
  • ALWAYS confirm key details before proceeding
  • If unsure about something, ask for clarification
  • Keep responses concise (under 30 words when possible)
  • Use natural conversational language, not robotic scripts
  • NEVER make up information — use the available tools
  • ALWAYS confirm key details before proceeding
  • If unsure about something, ask for clarification
  • Keep responses concise (under 30 words when possible)
  • Use natural conversational language, not robotic scripts

Available Tools

Available Tools

  • get_items(category?) - Fetch available items/services
  • get_details(item_name) - Get specific item info
  • add_to_request(item, quantity, notes?) - Add item to request
  • remove_from_request(item) - Remove item
  • get_summary() - Show current request
  • submit_request(name, phone, type) - Finalize
  • clear_request() - Start over
  • get_items(category?) - Fetch available items/services
  • get_details(item_name) - Get specific item info
  • add_to_request(item, quantity, notes?) - Add item to request
  • remove_from_request(item) - Remove item
  • get_summary() - Show current request
  • submit_request(name, phone, type) - Finalize
  • clear_request() - Start over

Handling Edge Cases

Handling Edge Cases

  • Unknown items: "I don't see that in our system. Would you like me to list the available options?"
  • Unclear speech: "I didn't quite catch that. Could you repeat it?"
  • Pricing questions: Always use get_details() for accurate info """,
    "es": """Eres un asistente de IA amigable y eficiente para {business_name}. ... """,

    Additional languages...

}
undefined
  • Unknown items: "I don't see that in our system. Would you like me to list the available options?"
  • Unclear speech: "I didn't quite catch that. Could you repeat it?"
  • Pricing questions: Always use get_details() for accurate info """,
    "es": """Eres un asistente de IA amigable y eficiente para {business_name}. ... """,

    Additional languages...

}
undefined

Greeting Templates

问候语模板

python
GREETINGS = {
    "en": "Hello! Thank you for calling {business_name}. How can I help you today?",
    "es": "¡Hola! Gracias por llamar a {business_name}. ¿Cómo puedo ayudarle hoy?",
    "fr": "Bonjour! Merci d'appeler {business_name}. Comment puis-je vous aider?",
    "ar": "مرحباً! شكراً لاتصالك بـ {business_name}. كيف يمكنني مساعدتك؟",
    "zh": "您好!感谢致电{business_name}。请问有什么可以帮您?",
}

UNIVERSAL_GREETING = """Hello! Thank you for calling.
Hola, gracias por llamar.
Bonjour, merci d'appeler.
How can I help you today?"""
python
GREETINGS = {
    "en": "Hello! Thank you for calling {business_name}. How can I help you today?",
    "es": "¡Hola! Gracias por llamar a {business_name}. ¿Cómo puedo ayudarle hoy?",
    "fr": "Bonjour! Merci d'appeler {business_name}. Comment puis-je vous aider?",
    "ar": "مرحباً! شكراً لاتصالك بـ {business_name}. كيف يمكنني مساعدتك؟",
    "zh": "您好!感谢致电{business_name}。请问有什么可以帮您?",
}

UNIVERSAL_GREETING = """Hello! Thank you for calling.
Hola, gracias por llamar.
Bonjour, merci d'appeler.
How can I help you today?"""

Prompt Engineering Best Practices

提示词工程最佳实践

1. Keep It Conversational

1. 保持口语化

❌ "Please state your order now."
✅ "What can I get started for you?"
❌ "Please state your order now."
✅ "What can I get started for you?"

2. Handle Interruptions Gracefully

2. 优雅处理打断

python
undefined
python
undefined

In AgentSession config:

在AgentSession配置中:

allow_interruptions=True
allow_interruptions=True

In prompt:

在提示词中:

"If the caller interrupts, acknowledge and adjust. Don't repeat yourself."
undefined
"If the caller interrupts, acknowledge and adjust. Don't repeat yourself."
undefined

3. Concise Responses

3. 回复简洁

❌ "I have successfully added one large pepperoni pizza to your order. Your current total is now $18.99. Is there anything else you would like to add?"
✅ "Got it, large pepperoni. That's $18.99. Anything else?"
❌ "I have successfully added one large pepperoni pizza to your order. Your current total is now $18.99. Is there anything else you would like to add?"
✅ "Got it, large pepperoni. That's $18.99. Anything else?"

4. Natural Confirmations

4. 自然确认

❌ "Order confirmed. Item added."
✅ "Perfect, I've added that."
❌ "Order confirmed. Item added."
✅ "Perfect, I've added that."

5. Error Recovery

5. 错误恢复

python
undefined
python
undefined

In prompt:

在提示词中:

""" If you make a mistake:
  • Acknowledge it naturally: "Oh, let me fix that"
  • Correct without over-apologizing
  • Move forward smoothly """
undefined
""" If you make a mistake:
  • Acknowledge it naturally: "Oh, let me fix that"
  • Correct without over-apologizing
  • Move forward smoothly """
undefined

Adding New Languages

添加新语言

  1. Add to
    SYSTEM_PROMPTS
    dict in the prompts file
  2. Add greeting to
    GREETINGS
    dict
  3. Update
    SUPPORTED_LANGUAGES
    in config
  4. Test with native speakers for natural phrasing
  1. 在提示词文件的
    SYSTEM_PROMPTS
    字典中添加对应语言内容
  2. GREETINGS
    字典中添加对应问候语
  3. 更新配置中的
    SUPPORTED_LANGUAGES
  4. 邀请母语使用者测试,确保表述自然

Domain-Specific Prompts

特定领域提示词

Restaurant Orders (Example)

餐厅订单(示例)

Focus: Menu navigation, order building, modifications
重点:菜单导航、订单构建、修改需求

Appointment Booking (Example)

预约预订(示例)

python
APPOINTMENT_PROMPT = """You are a scheduling assistant for {business_name}.
python
APPOINTMENT_PROMPT = """You are a scheduling assistant for {business_name}.

Your Role

Your Role

  • Help callers book appointments
  • Check availability
  • Confirm booking details
  • Handle rescheduling and cancellations
  • Help callers book appointments
  • Check availability
  • Confirm booking details
  • Handle rescheduling and cancellations

Available Tools

Available Tools

  • get_available_slots(date, service_type)
  • book_appointment(customer_name, phone, date, time, service)
  • cancel_appointment(appointment_id)
  • reschedule_appointment(appointment_id, new_date, new_time) """
undefined
  • get_available_slots(date, service_type)
  • book_appointment(customer_name, phone, date, time, service)
  • cancel_appointment(appointment_id)
  • reschedule_appointment(appointment_id, new_date, new_time) """
undefined

Customer Support (Example)

客户支持(示例)

python
SUPPORT_PROMPT = """You are a support agent for {company_name}.
python
SUPPORT_PROMPT = """You are a support agent for {company_name}.

Your Role

Your Role

  • Answer common questions
  • Troubleshoot issues
  • Escalate to human when needed
  • Create support tickets
  • Answer common questions
  • Troubleshoot issues
  • Escalate to human when needed
  • Create support tickets

Escalation Triggers

Escalation Triggers

  • Caller asks for human
  • Issue requires account access
  • Complaint about service
  • Technical problem you can't resolve """
undefined
  • Caller asks for human
  • Issue requires account access
  • Complaint about service
  • Technical problem you can't resolve """
undefined

Testing Prompts

提示词测试

Test Scenarios to Cover

需要覆盖的测试场景

  1. Simple request (one item)
  2. Complex request (multiple items, modifications)
  3. Information questions
  4. Price/availability inquiries
  5. Request modifications (add/remove)
  6. Special requirements handling
  7. Unclear speech handling
  8. Language switching mid-call
  1. 简单请求(单个项目)
  2. 复杂请求(多个项目、修改需求)
  3. 信息咨询
  4. 价格/库存查询
  5. 请求修改(添加/移除)
  6. 特殊需求处理
  7. 语音不清晰处理
  8. 通话中途切换语言

Latency Considerations

延迟考虑

  • Shorter prompts = faster LLM response
  • Use bullet points over paragraphs
  • Front-load important instructions
  • Keep tool descriptions minimal
  • 提示词越短,LLM响应速度越快
  • 使用项目符号代替段落
  • 重要指令放在开头
  • 工具描述尽量简洁

Output Format

输出格式

When creating/modifying prompts:
  1. Update the prompts file in the agent directory
  2. Test with sample conversations
  3. Measure latency impact
  4. Validate all language versions
创建/修改提示词时:
  1. 更新Agent目录下的提示词文件
  2. 使用示例对话进行测试
  3. 评估延迟影响
  4. 验证所有语言版本