Files
paseo/packages/agent-python/agent.py
Mohamed Boudra f3b8cc689d Based on the git diff, this commit makes three distinct improvements to terminal management:
```
feat: improve terminal state tracking and creation reliability

- Switch to ElevenLabs TTS (eleven_turbo_v2_5) in voice agent
- Add current command tracking to terminal listings
- Use session prefix '__voice-dev' to avoid conflicts
- Create windows with working directory and run initial commands atomically
- Disable automatic window renaming to preserve user-set names
- Improve working directory detection with lsof fallback
- Enhance command detection to show full command with arguments
```
2025-10-14 13:11:57 +02:00

92 lines
2.2 KiB
Python

"""
LiveKit Voice Agent with MCP Support (Python)
Migrated from Node.js version with added MCP integration
"""
import asyncio
import os
from pathlib import Path
from typing import Annotated
from dotenv import load_dotenv
from livekit import rtc
from livekit.agents import (
AutoSubscribe,
JobContext,
JobProcess,
WorkerOptions,
cli,
llm,
voice,
inference,
)
from livekit.agents.llm.mcp import MCPServerHTTP
# Load environment variables
load_dotenv()
def load_system_prompt() -> str:
"""Load system prompt from agent-prompt.md file."""
prompt_path = Path(__file__).parent / "agent-prompt.md"
return prompt_path.read_text()
# Load system prompt from external file for easier editing
SYSTEM_PROMPT = load_system_prompt()
async def entrypoint(ctx: JobContext):
"""Main entry point for the voice agent."""
# Get MCP server URL from environment
mcp_server_url = os.getenv("MCP_SERVER_URL")
# Prepare MCP servers list
mcp_servers = []
if mcp_server_url:
print(f"✓ MCP Server configured: {mcp_server_url}")
server = MCPServerHTTP(
url=mcp_server_url,
timeout=10
)
mcp_servers.append(server)
else:
print("⚠ No MCP_SERVER_URL found in environment")
# Connect to the room
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
# Create the voice agent with MCP tools
agent = voice.Agent(
instructions=SYSTEM_PROMPT,
mcp_servers=mcp_servers, # Native MCP support!
)
# Create the agent session with LiveKit Inference
# Using same configuration as Node.js version
session = voice.AgentSession(
stt="assemblyai/universal-streaming:en",
llm="openai/gpt-4.1-mini",
tts= inference.TTS(
model="elevenlabs/eleven_turbo_v2_5",
voice="Xb7hH8MSUJpSbSDYk0k2",
language="en"
),
)
# Start the session
await session.start(agent=agent, room=ctx.room)
print(f"✓ Agent started successfully in room: {ctx.room.name}")
print(f"✓ MCP servers: {len(mcp_servers)} configured")
if __name__ == "__main__":
# Run the agent worker
cli.run_app(
WorkerOptions(
entrypoint_fnc=entrypoint,
)
)