Hi all, I'm trying to get the basic voice agent wo...
# agents
l
Hi all, I'm trying to get the basic voice agent working with a self hosted livekit server running locally but am unable to get the agent to connect to the server:
Copy code
uv run python src/agent.py dev
2025-08-14 13:20:02,364 - DEBUG asyncio - Using selector: EpollSelector 
2025-08-14 13:20:02,365 - DEV  livekit.agents - Watching /home/dsun/ai-panel-demo/backend/agent-starter-python/src 
2025-08-14 13:20:03,173 - DEBUG asyncio - Using selector: EpollSelector 
2025-08-14 13:20:03,176 - INFO livekit.agents - starting worker {"version": "1.2.5", "rtc-version": "1.0.12"}
2025-08-14 13:20:03,176 - INFO livekit.agents - preloading plugins {"packages": ["livekit.plugins.openai", "av"]}
2025-08-14 13:20:03,372 - WARNING livekit.agents - failed to connect to livekit, retrying in 0s 
Traceback (most recent call last):
  File "/home/dsun/ai-panel-demo/backend/agent-starter-python/.venv/lib/python3.12/site-packages/livekit/agents/worker.py", line 648, in _connection_task
    ws = await self._http_session.ws_connect(
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/dsun/ai-panel-demo/backend/agent-starter-python/.venv/lib/python3.12/site-packages/aiohttp/client.py", line 1084, in _ws_connect
    raise WSServerHandshakeError(
aiohttp.client_exceptions.WSServerHandshakeError: 400, message='Invalid response status', url='ws://localhost:7880/agent'
Additionally, my locally hosted instance of the agent playground is able to connect to the livekit server with no problem. Has anyone faced a similar issue before?
r
This is probably better asked in #self-hosting You're experiencing a WebSocket handshake error when trying to connect your LiveKit Python agent to your self-hosted LiveKit server at
ws://localhost:7880/agent
. fThe Connection Issue The error occurs in the agent's connection process where it attempts to establish a WebSocket connection to your LiveKit server. worker.py:646-652 The agent constructs the WebSocket URL by parsing your
LIVEKIT_URL
and appending
/agent
to create the agent endpoint. worker.py:634-640 Possible Causes and Solutions 1. Agent Endpoint Configuration Your self-hosted LiveKit server may not have the agent endpoint properly configured or enabled. The agent tries to connect to
/agent
endpoint specifically, which is different from the regular WebRTC endpoints that your playground uses. worker.py:639-640 2. Environment Variables Ensure your environment variables are correctly set. The agent needs: •
LIVEKIT_URL
(should be
ws://localhost:7880
or
http://localhost:7880
) •
LIVEKIT_API_KEY
•
LIVEKIT_API_SECRET
README.md:32-37 3. Server Configuration Since your agent playground can connect but the Python agent cannot, this suggests your LiveKit server may not have agent support enabled or properly configured. The agent requires specific server-side support for the
/agent
WebSocket endpoint. 4. Authentication Issues The agent creates a JWT token with agent grants for authentication. worker.py:626-632 If your server's API key/secret configuration doesn't match what the agent is using, you'll get authentication failures. Debugging Steps 1. Verify your LiveKit server supports agents - Check your server configuration and ensure agent endpoints are enabled 2. Test with LiveKit Cloud first - Try connecting to LiveKit Cloud to isolate whether it's a server configuration issue 3. Check server logs - Look at your self-hosted server logs when the agent attempts to connect 4. Verify environment variables - Double-check your
.env.local
file matches your server configuration The fact that your playground works suggests the basic server is running, but the agent-specific endpoint may not be properly configured on your self-hosted instance.
❤️ 1