Multimodal Voice and Text Agents
Coordinating spoken responses with on-screen text in voice agent systems.
Multimodal Voice and Text Agents is a free AI Prompt Engineering lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AI Prompt Engineering learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Voice-Only vs Multimodal Contexts
Voice AI agents operate in two fundamentally different contexts:
- Voice-only: Smart speakers, IVR, phone calls — users hear audio only, no screen
- Multimodal: Mobile apps, web apps, car dashboards — users can see a screen AND hear audio simultaneously
These contexts require different response strategies. In voice-only, everything must be spoken. In multimodal, you can coordinate what's spoken with what's displayed.
Prompting for Voice-Only Responses
In voice-only contexts, the LLM must produce responses that work entirely without visuals. This means no references to screen elements, no lists that require visual scanning, and no content that only makes sense with formatting.
VOICE_ONLY_SYSTEM_PROMPT = (
'You are a voice-only assistant. The user cannot see any screen.\n\n'
'Requirements:\n'
'- Never reference visual elements ("tap here", "see the chart", "the blue button")\n'
'- Never use numbered or bulleted lists — use spoken sequences instead:\n'
' BAD: "1. First do X 2. Then do Y"\n'
' GOOD: "Start by doing X. When that is done, do Y."\n'
'- Limit responses to what can be comfortably spoken in 30 seconds\n'
'- Offer to give more detail rather than overwhelming the user\n'
'- Use verbal signposts: "First", "Next", "Finally"\n'
'- Read out all important data: codes, dates, amounts as full words'
)
print(VOICE_ONLY_SYSTEM_PROMPT)Coordinating Spoken and On-Screen Text
In multimodal contexts, you can divide content between audio and screen. Audio handles conversational, emotional, and dynamic content. The screen handles dense information, tables, and long-form text.
MULTIMODAL_SYSTEM_PROMPT = (
'You are a multimodal assistant with both a voice and a screen.\n\n'
'When responding, consider what each modality does best:\n\n'
'SPEAK (voice):\n'
'- Conversational summary, emotional tone, key highlights\n'
'- Guide the user to look at the screen when needed:\n'
' "I have shown the details on screen. The key number to notice is..."\n\n'
'SHOW (screen):\n'
'- Detailed data, tables, long lists, code, maps, images\n\n'
'When your response includes structured data, respond in this format:\n'
'SPOKEN: <what to say aloud>\n'
'VISUAL: <what to display on screen in markdown>'
)
# Example LLM output for multimodal response:
EXAMPLE_MULTIMODAL_OUTPUT = (
'SPOKEN: Your top three expenses this month are food, transport, and entertainment. '
'Food was the biggest, almost double your budget. Check the screen for the full breakdown.\n\n'
'VISUAL: | Category | Budget | Actual | Difference |\n'
'|---|---|---|---|\n'
'| Food | $400 | $780 | -$380 |\n'
'| Transport | $150 | $162 | -$12 |\n'
'| Entertainment | $100 | $145 | -$45 |'
)
print(EXAMPLE_MULTIMODAL_OUTPUT)Structuring LLM Output for Voice Agents
For voice agent applications, prompt the LLM to return structured output you can parse and route to audio vs screen separately. JSON or a defined section format works well.
import anthropic
import json
client = anthropic.Anthropic(api_key='sk-ant-...')
VOICE_AGENT_SYSTEM = (
'You are a financial voice assistant. For each response, return JSON with:\n'
'{\n'
' "spoken": "Short spoken response (max 2 sentences)",\n'
' "visual_title": "Header for the on-screen card (optional)",\n'
' "visual_content": "Detailed content for screen (markdown, optional)",\n'
' "action_label": "Button label if action needed (optional)",\n'
' "action_type": "one of: none, confirm, navigate, call"\n'
'}\n'
'Return only the JSON object.'
)
def voice_agent_query(user_message):
r = client.messages.create(
model='claude-opus-4-5',
max_tokens=500,
system=VOICE_AGENT_SYSTEM,
messages=[{'role': 'user', 'content': user_message}]
)
try:
response_data = json.loads(r.content[0].text)
return response_data
except json.JSONDecodeError:
return {'spoken': r.content[0].text, 'visual_content': None}
result = voice_agent_query('What is my account balance?')
print('SPEAK:', result.get('spoken'))
print('SHOW:', result.get('visual_content', 'Nothing to display'))Transcript Formatting for Voice Agents
Voice agent conversations must be logged as transcripts for debugging, compliance, and quality review. Format transcripts to capture speaker identity, timestamps, and both audio and visual outputs.
import datetime
import json
class VoiceTranscript:
def __init__(self, session_id):
self.session_id = session_id
self.turns = []
def add_user_turn(self, text, audio_duration_ms=None):
self.turns.append({
'speaker': 'user',
'timestamp': datetime.datetime.utcnow().isoformat(),
'text': text,
'audio_duration_ms': audio_duration_ms,
})
def add_agent_turn(self, spoken_text, visual_content=None, action=None):
self.turns.append({
'speaker': 'agent',
'timestamp': datetime.datetime.utcnow().isoformat(),
'spoken': spoken_text,
'visual': visual_content,
'action': action,
})
def save(self, filepath):
with open(filepath, 'w') as f:
json.dump({'session_id': self.session_id, 'turns': self.turns}, f, indent=2)
print(f'Transcript saved: {filepath}')
# Usage
transcript = VoiceTranscript('session_001')
transcript.add_user_turn('What is my balance?', audio_duration_ms=1200)
transcript.add_agent_turn('Your balance is four hundred dollars.', visual_content='Balance: $400')
transcript.save('/tmp/session_001_transcript.json')Handling Voice Input Errors
Voice agents must gracefully handle speech recognition errors — mishearing words, incomplete utterances, or background noise. Prompt the LLM to detect and recover from ambiguous input.
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-...')
AMBIGUITY_HANDLING_SYSTEM = (
'You are a voice assistant. User input comes from speech recognition '
'and may contain transcription errors.\n\n'
'When input seems unclear or ambiguous:\n'
'1. State what you think the user might have meant.\n'
'2. Ask a single clarifying yes/no question to confirm.\n'
'3. Never ask more than one question at a time.\n'
'4. Offer the most likely interpretation as the default.\n\n'
'Example:\n'
'Input: "transfer five hundred to john or gene" (ambiguous name)\n'
'Response: "It sounds like you want to transfer five hundred dollars. '
'Did you mean John Smith or Gene Lee?"'
)
def handle_voice_input(user_speech):
r = client.messages.create(
model='claude-opus-4-5',
max_tokens=200,
system=AMBIGUITY_HANDLING_SYSTEM,
messages=[{'role': 'user', 'content': user_speech}]
)
return r.content[0].text
print(handle_voice_input('pay the electric company bill thing'))Turn-Taking in Voice Conversations
Unlike text chat, voice requires explicit turn management. The agent must know when to stop talking and listen, and the user must know when the agent is done. Design prompts that produce responses with natural ending signals.
TURN_TAKING_SYSTEM = (
'You are a voice assistant. Responses must be designed for spoken conversation:\n\n'
'End each response with exactly ONE of:\n'
'- A direct question inviting the user to respond\n'
'- A clear statement that the task is complete (e.g., "That is done.")\n'
'- An explicit offer to continue (e.g., "Is there anything else?")\n\n'
'Never end mid-thought. Never trail off. '
'Avoid open-ended statements that leave the user unsure if they should speak.\n\n'
'GOOD endings:\n'
'- "The transfer is complete. Would you like a confirmation number?"\n'
'- "That is all I have. Is there anything else?"\n'
'BAD endings:\n'
'- "You might also want to consider..." (open, unclear)\n'
'- "The balance is..." (incomplete)'
)
print(TURN_TAKING_SYSTEM[:300])Interruption Handling
Users interrupt voice agents. The system must detect interruptions (via VAD — voice activity detection) and prompt the agent to gracefully resume or redirect. Prompt the LLM to accept mid-conversation topic changes.
import anthropic
client = anthropic.Anthropic(api_key='sk-ant-...')
INTERRUPTION_SYSTEM = (
'You are a voice assistant. Users may interrupt mid-conversation.\n\n'
'If the user changes topic abruptly, smoothly acknowledge the change:\n'
'"Of course. Let us switch to that." Then answer the new question.\n\n'
'If the user says something like "wait", "stop", "hold on":\n'
'Pause and say "Sure, take your time" and wait for them to continue.\n\n'
'If the user repeats a question, they likely did not hear the answer:\n'
'Say "Let me repeat that." and say it again more slowly.\n\n'
'Never express frustration at interruptions or repetition.'
)
def handle_conversation(turns):
"""Handle multi-turn voice conversation with interruptions."""
messages = []
for speaker, text in turns:
messages.append({'role': speaker, 'content': text})
r = client.messages.create(
model='claude-opus-4-5',
max_tokens=200,
system=INTERRUPTION_SYSTEM,
messages=messages
)
return r.content[0].text
# Simulate an interruption scenario
conversation = [
('user', 'What is my balance?'),
('assistant', 'Your checking account balance is four hundred dollars and—'),
('user', 'Actually wait, can you tell me my savings instead?'),
]
print(handle_conversation(conversation))On-Screen Companion to Voice
When a screen is available, design the on-screen content to complement (not duplicate) the spoken audio. The screen handles detail; the voice handles navigation and emotional engagement.
def render_multimodal_response(agent_output):
"""
Render a voice agent response to both TTS and screen components.
agent_output: dict with 'spoken', 'visual_content', 'action_label'
"""
# Route to TTS
spoken = agent_output.get('spoken', '')
if spoken:
send_to_tts(spoken) # Your TTS function
print(f'[AUDIO] {spoken}')
# Route to screen
visual = agent_output.get('visual_content')
if visual:
render_card_on_screen(visual) # Your UI function
print(f'[SCREEN] {visual[:100]}')
# Optional action button
action_label = agent_output.get('action_label')
if action_label:
show_action_button(action_label) # Your UI function
print(f'[BUTTON] {action_label}')
def send_to_tts(text):
print(f'TTS: {text}')
def render_card_on_screen(content):
print(f'Screen card: {content[:50]}')
def show_action_button(label):
print(f'Button: {label}')
# Test it
render_multimodal_response({
'spoken': 'I found three flights to New York.',
'visual_content': '| Flight | Departs | Price |\n|---|---|---|\n| AA101 | 08:00 | $299 |',
'action_label': 'Book cheapest'
})Accessibility Considerations
Voice AI is itself an accessibility feature for users with vision impairments or motor difficulties. Design your agent to also support users who rely on voice as their primary interface.
ACCESSIBILITY_VOICE_SYSTEM = (
'This voice assistant serves users who may be using voice as their '
'primary access method due to disability or preference.\n\n'
'Guidelines:\n'
'- Never require the user to see a screen to complete a task.\n'
'- Read out all information that matters, including confirmation codes, '
'totals, and status messages.\n'
'- Offer to repeat any information: '
'"I can repeat that if you would like."\n'
'- Describe any actions you took: '
'"I have sent the confirmation to your email."\n'
'- Accept multiple phrasings for the same command — users phrase '
'voice commands inconsistently.\n'
'- Confirm all destructive or financial actions before executing:\n'
' "Just to confirm: you want to transfer $500 to John. Is that right?"'
)
print(ACCESSIBILITY_VOICE_SYSTEM[:300])Testing Voice Agent Responses
Testing voice agent responses requires a different approach than testing text responses. You must evaluate both the spoken audio (prosody, clarity, naturalness) and the visual component (completeness, formatting). A text response that reads well may sound awkward when spoken.
Build a testing pipeline that converts agent outputs to audio using your TTS engine, then applies an automated quality check: sentence length, pronunciation of abbreviations, absence of markdown artifacts, and turn-taking signals.
Knowledge Check: Voice-Only Constraint
In a voice-only context (smart speaker with no screen), which type of agent response is MOST appropriate?
Recap: Multimodal Voice and Text Agents
Voice agents operate in two modes: voice-only (no screen) and multimodal (voice + screen). Voice-only responses must avoid visual references and work entirely as spoken audio with verbal signposts. Multimodal responses divide content: voice for conversational summaries and emotional tone, screen for detailed data and long-form text. Prompt LLMs to return structured output (JSON with spoken/visual fields) for easy routing. Design for turn-taking with clear response endings, graceful interruption handling, and explicit repetition support. Always consider accessibility — voice is often a primary interface for users who need it most.
Frequently asked questions
Is the “Multimodal Voice and Text Agents” lesson free?
Yes — the full text of “Multimodal Voice and Text Agents” is free to read here on the web, and the AI Prompt Engineering course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AI Prompt Engineering course, upgrade to CoddyKit PRO.
What will I learn in “Multimodal Voice and Text Agents”?
Coordinating spoken responses with on-screen text in voice agent systems. You practise AI Prompt Engineering with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AI Prompt Engineering?
No prior experience is required. AI Prompt Engineering on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Multimodal Voice and Text Agents” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AI Prompt Engineering lesson?
Yes. Every AI Prompt Engineering lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- TTS Prompt Patterns for Natural Speech
- SSML and Prosody Control
- Voice AI Persona Design
- Multimodal Voice and Text Agents