ExamplesFrameworks
LiveKit Agents
Voice agents with email capabilities via LiveKit
Overview
Integrate daimon.email with LiveKit voice agents, enabling real-time voice interactions with email capabilities. Your voice agent can read emails aloud, compose messages via voice commands, and manage email operations through natural conversation.
Info
Voice + Email: Build conversational AI agents that can handle email through voice interfaces — perfect for hands-free email management, accessibility features, and voice-first applications.
Installation
pip install livekit livekit-agents daimon-emailComplete Implementation
from livekit import agents, rtc
from livekit.agents import AutoSubscribe, JobContext, WorkerOptions, cli
from livekit.plugins import openai, silero
from daimon_email import DaimonClient
import asyncio
import json
# Initialize daimon.email client
daimon_client = DaimonClient(api_key=os.getenv('DAIMON_API_KEY'))
# Store agent's inbox
agent_inbox = None
class EmailVoiceAgent:
def __init__(self, ctx: JobContext):
self.ctx = ctx
self.assistant = None
self.inbox_id = None
async def create_inbox(self, username: str) -> dict:
"""Create inbox via voice command."""
global agent_inbox
inbox = daimon_client.inboxes.create(
username=username,
client_id=f'livekit-{username}'
)
agent_inbox = inbox['result']
self.inbox_id = inbox['result']['id']
return {
'email': inbox['result']['address'],
'inbox_id': inbox['result']['id']
}
async def check_messages(self) -> list:
"""Check for new messages."""
if not self.inbox_id:
return []
messages = daimon_client.inboxes.messages.list(self.inbox_id)
return messages[:5] # Return 5 most recent
async def read_message_aloud(self, message_id: str):
"""Read a specific message aloud."""
message = daimon_client.messages.get(message_id)
# Compose spoken response
text = f"""
Email from {message['from']}.
Subject: {message['subject']}.
Message: {message.get('reply_body') or message['body']}
"""
return text
async def send_email(self, to: str, subject: str, body: str) -> dict:
"""Send email via voice command."""
if not self.inbox_id:
return {'error': 'No inbox created'}
try:
result = daimon_client.inboxes.send(self.inbox_id, {
'to': to,
'subject': subject,
'body': body
})
return {'success': True, 'message_id': result['message_id']}
except Exception as error:
return {'success': False, 'error': str(error)}
# LiveKit entry point
async def entrypoint(ctx: JobContext):
# Set up voice agent
email_agent = EmailVoiceAgent(ctx)
# Create AI assistant with email functions
assistant = openai.AssistantAgent(
name="Email Voice Assistant",
instructions="""
You are a voice assistant that helps users manage their email.
You can:
- Create email inboxes
- Check for new messages
- Read messages aloud
- Send emails via voice dictation
- Summarize email threads
Always respond in a friendly, conversational tone.
When reading emails, summarize long messages.
""",
functions=[
openai.FunctionCallInfo(
name="create_inbox",
description="Create a new email inbox",
parameters={
"type": "object",
"properties": {
"username": {"type": "string", "description": "Username for the inbox"}
},
"required": ["username"]
},
callable=email_agent.create_inbox
),
openai.FunctionCallInfo(
name="check_messages",
description="Check for new email messages",
parameters={"type": "object", "properties": {}},
callable=email_agent.check_messages
),
openai.FunctionCallInfo(
name="read_message",
description="Read a specific email message aloud",
parameters={
"type": "object",
"properties": {
"message_id": {"type": "string", "description": "ID of message to read"}
},
"required": ["message_id"]
},
callable=email_agent.read_message_aloud
),
openai.FunctionCallInfo(
name="send_email",
description="Send an email",
parameters={
"type": "object",
"properties": {
"to": {"type": "string", "description": "Recipient email"},
"subject": {"type": "string", "description": "Email subject"},
"body": {"type": "string", "description": "Email body"}
},
"required": ["to", "subject", "body"]
},
callable=email_agent.send_email
)
]
)
# Connect to room
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
# Start assistant
assistant.start(ctx.room)
# Greet user
await assistant.say("Hello! I'm your email voice assistant. I can help you create inboxes, check messages, and send emails. What would you like to do?")
if __name__ == "__main__":
cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))Example Voice Interactions
Creating an Inbox
User: "Create an inbox for me with username voice-agent"
Agent: "Creating an inbox with username voice-agent... Done!
Your email address is voice-agent@daimon.email.
What would you like to do next?"Checking Messages
User: "Check my messages"
Agent: "You have 3 new messages.
First message is from john@example.com with subject 'Meeting tomorrow'.
Second message is from support@service.com with subject 'Your account is ready'.
Third message is from team@company.com with subject 'Weekly update'.
Would you like me to read any of these?"Reading a Message
User: "Read the first one"
Agent: "Email from john@example.com.
Subject: Meeting tomorrow.
Message: Hi, just wanted to confirm our meeting tomorrow at 2pm.
Let me know if you can still make it. Thanks!"Sending an Email
User: "Send a reply to john@example.com. Subject: Confirmed.
Body: Yes, I'll be there at 2pm. See you tomorrow."
Agent: "Sending email to john@example.com... Done!
Your message has been sent successfully."Advanced: Email Notifications
# Real-time email notifications via voice
async def monitor_inbox_voice(ctx: JobContext, inbox_id: str):
"""Monitor inbox and speak new messages as they arrive."""
assistant = ctx.assistant
last_check = datetime.now()
while True:
# Check for new messages
messages = daimon_client.inboxes.messages.list(inbox_id)
new_messages = [
m for m in messages
if datetime.fromisoformat(m['received_at']) > last_check
]
if new_messages:
for msg in new_messages:
await assistant.say(
f"New email from {msg['from']}. "
f"Subject: {msg['subject']}. "
f"Would you like me to read it?"
)
last_check = datetime.now()
await asyncio.sleep(30) # Check every 30 secondsUse Case: Hands-Free Email Management
# Complete hands-free workflow
async def hands_free_email_assistant(ctx: JobContext):
"""Voice assistant for hands-free email management."""
assistant = openai.AssistantAgent(
name="Hands-Free Email Assistant",
instructions="""
You help users manage email completely hands-free.
Workflow:
1. Listen for voice commands
2. Perform email operations
3. Confirm actions verbally
4. Read responses aloud
Be conversational and confirm important actions before executing.
""",
functions=[/* email functions */]
)
await ctx.connect()
assistant.start(ctx.room)
# Voice-driven email workflow
await assistant.say("Email assistant ready. Say 'check email' to begin.")Use Case: Accessibility Features
# Email assistant for visually impaired users
async def accessibility_email_agent(ctx: JobContext):
"""Email agent optimized for screen reader users."""
assistant = openai.AssistantAgent(
name="Accessible Email Assistant",
instructions="""
You are an email assistant designed for accessibility.
Guidelines:
- Speak clearly and at a measured pace
- Describe all actions before performing them
- Confirm user intent before sending emails
- Provide clear navigation cues
- Read emails in a structured format (from, subject, body)
""",
functions=[/* email functions */]
)
await ctx.connect()
assistant.start(ctx.room)
await assistant.say(
"Accessible email assistant ready. "
"I can help you read, compose, and manage your emails using voice commands. "
"How can I help you today?"
)Integration with Phone Calls
from livekit.plugins import telephony
# Email assistant accessible via phone
async def phone_email_assistant(ctx: JobContext):
"""Email assistant accessible via phone call."""
# Set up telephony
phone_number = ctx.room.metadata.get('phone_number')
assistant = openai.AssistantAgent(
name="Phone Email Assistant",
instructions="""
You are an email assistant accessed via phone call.
Features:
- Check email via phone
- Have emails read aloud
- Dictate email responses
- Manage inbox by voice
Keep responses brief for phone context.
""",
functions=[/* email functions */]
)
await ctx.connect()
assistant.start(ctx.room)
await assistant.say(
"Welcome to your email assistant. "
"Press 1 to check messages, press 2 to send an email, or say 'help' for more options."
)Voice-Activated Email Summaries
# Daily email summary via voice
async def daily_email_summary(inbox_id: str) -> str:
"""Generate daily email summary for voice delivery."""
messages = daimon_client.inboxes.messages.list(inbox_id)
# Filter today's messages
today_messages = [
m for m in messages
if datetime.fromisoformat(m['received_at']).date() == datetime.now().date()
]
if not today_messages:
return "You have no new emails today."
summary = f"You have {len(today_messages)} emails today. "
# Categorize
urgent = [m for m in today_messages if 'urgent' in m['subject'].lower()]
if urgent:
summary += f"{len(urgent)} marked urgent. "
# Top senders
senders = {}
for msg in today_messages:
sender = msg['from']
senders[sender] = senders.get(sender, 0) + 1
top_sender = max(senders.items(), key=lambda x: x[1])
summary += f"Most emails from {top_sender[0]} with {top_sender[1]} messages."
return summaryTesting Voice Interactions
# Test voice agent locally
async def test_voice_agent():
"""Test email voice agent."""
from livekit.agents import cli
# Create test room
room = rtc.Room()
# Test creating inbox
response = await assistant.create_inbox("test-voice")
assert 'email' in response
# Test checking messages
messages = await assistant.check_messages()
assert isinstance(messages, list)
print("Voice agent tests passed!")Deployment
# Deploy to LiveKit Cloud
export LIVEKIT_URL=wss://your-project.livekit.cloud
export LIVEKIT_API_KEY=your-api-key
export LIVEKIT_API_SECRET=your-api-secret
export DAIMON_API_KEY=dm_live_xxx
python email_voice_agent.py start