connecting <agent-starter-react> (running locally ...
# ask-ai
a
connecting agent-starter-react (running locally for now) with my agent-starter-python running on liveKit cloud
t
Thanks for reaching out, Nico. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Let's walk through how to connect
agent-starter-react
running on your local machine with
agent-starter-python
on LiveKit Cloud. Here’s a simple step-by-step guide to help you get everything up and running smoothly: 1. Set Up the React Frontend Locally: Start by cloning the React app and running it locally. You’ll want to install all the dependencies using
pnpm install
, then launch the app with
pnpm dev
. Make sure it’s accessible at
http://localhost:3000
. 2. Configure Environment Variables: Next, create a
.env.local
file inside your React app directory. Here, you’ll add your LiveKit credentials (
LIVEKIT_API_KEY
,
LIVEKIT_API_SECRET
, and
LIVEKIT_URL
) so everything can communicate properly. 3. Run the Python Agent: Now, clone the Python agent repo. Set up a
.env
file there with the same LiveKit credentials you used before. When you’re ready, start the agent in development mode by running
python myagent.py dev
. 4. Connect Both Components: The React app will create a room and connect to LiveKit. Your Python agent will then detect this room and join automatically, allowing both parts to interact seamlessly. Just a quick reminder: make sure both the React app and the Python agent are using the exact same LiveKit credentials. If you run into any hiccups, double-check your environment variables, take a peek at the logs, and ensure there aren’t any network restrictions blocking WebSocket connections. I’m here if you need any more help or clarification—don’t hesitate to reach out! Sources: TEMPLATE.md | templates.yaml | README.md | Voice AI quickstart | LiveKit Docs
a
I understand that in your described setup, the backend agent runs locally. However, I want to deploy my frontend to production. How do I configure the deployed frontend to connect to an agent running on LiveKit Cloud instead of my local agent? What configuration changes are needed to switch between local and cloud agent endpoints? is my question clear?
t
Let's walk through how you can configure your deployed frontend to connect to an agent running on LiveKit Cloud instead of a local agent. Here’s a simple step-by-step guide to help you out: 1. Update Environment Variables: In your frontend's environment file (like
.env.local
), please set these values: ◦
LIVEKIT_URL=wss://your-project-subdomain.livekit.cloud
◦
LIVEKIT_API_KEY=your_livekit_api_key
◦
LIVEKIT_API_SECRET=your_livekit_api_secret
1. Deploy the Frontend: Make sure these updated environment variables are included when you deploy. If you're using platforms like Vercel, you can add these variables directly in your project settings. 2. Verify Agent Deployment: Double-check that your agent is running on LiveKit Cloud with the same credentials as your frontend. You can use the LiveKit CLI to see the agent’s status and logs by running:
Copy code
lk agent status
lk agent logs --follow
It’s important that your frontend and agent share the exact same LiveKit credentials. If you run into any issues, try checking the WebSocket connections in your browser’s developer tools and make sure the
LIVEKIT_URL
is correct. Please don’t hesitate to reach out if you need any more help—I’m here for you! Sources: README.md | complex-agents/nova-sonic/nova-sonic-form-agent/README.md | Web and mobile frontends | LiveKit Docs | Deploying to production | LiveKit Docs | README.md
a
so the only requirement for this to work right off the bat is the exact same credentials between frontend and backend (provided I use the vanilla agent starter code provided for both) in the respective deployments? note: if I run the frontend locally I was expecting it to connect to the liveKit cloud deployed backend, but maybe I was wrong in this assumption for many reasons. can you confirm?
t
Just to make sure I understand you correctly—are you asking if a frontend running locally can connect to a LiveKit Cloud backend using the same credentials? Or are you wondering if there are any extra configurations needed for this setup? I want to make sure I’m on the same page so I can give you the best guidance possible.
a
let's tackle this one by one. first I am asking this: """ are you asking if a frontend running locally can connect to a LiveKit Cloud backend using the same credentials? ""
t
Absolutely! A frontend running locally can connect to a LiveKit Cloud backend using the same credentials (
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
). This is actually a common and convenient setup for local development and testing while still taking advantage of the LiveKit Cloud infrastructure. Just make sure that both your local frontend and the LiveKit Cloud backend have the exact same credentials set in their environment files. If anything feels unclear or you want me to walk you through it step-by-step, please don’t hesitate to ask—I’m here to help! Sources: web/.env.sample | .env.example | complex-agents/nova-sonic/README.md
a
ok then somethign is off. I am doing exactly this, and I can run frontend on localhost perfectly fine, but It seems nobody is there to reply to me. maybe the agent has not even entered the room? I have triple checked and the livekit credentials are exactly the same for backend agent deployed in livekit cloud and for the frontend...
is there an easier way for me to test the deployed backend in isolation? so that I see if that one is working fine at least?
t
Hey there! If your frontend is running locally and the agent deployed on LiveKit Cloud isn't joining the room, don't worry—let's walk through some troubleshooting steps together to get this sorted out: 1. Verify Agent Dispatch: First, make sure the agent is properly dispatched to the room. You can do this either when generating the token or by using the Agent Dispatch Service API. If you're using token-based dispatch, double-check that the token includes the agent configuration. 2. Monitor Agent Connection Events: On your frontend, keep an eye out for
ParticipantConnected
events where
participant.kind === ParticipantKind.AGENT
. If you don’t see this event, it might mean the agent isn’t joining the room. 3. Check Agent Service Logs: It’s helpful to look at the agent’s status and logs using the LiveKit CLI:
Copy code
lk agent status --id <agent-id>
lk agent logs --id <agent-id> --log-type=deploy
4. Validate Agent Token: Make sure the agent token is valid and includes the right grants, like
agent: true
and
room_join: true
. 5. Double-Check Credentials: Lastly, confirm that both your frontend and backend are using the exact same
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
. If you hit any bumps or need a hand with any of these steps, just let me know—I’m here to help! Sources: Example Applications | livekit/livekit_composite | DeepWiki | Community & Support | livekit/livekit_composite | DeepWiki | Getting Help & Troubleshooting | livekit/livekit_composite | DeepWiki | livekit-plugins/livekit-plugins-anam/livekit/plugins/anam/avatar.py | README.md
Just to make sure I understand you correctly, are you hoping to test the deployed backend agent on its own, without using the frontend? For example, by using a tool or API to check if it’s working properly? Knowing this will really help me guide you in the best way possible.
a
is there an easier way for me to test the deployed backend in isolation without a dedicated frontend? so that I see if that one is working fine at least?
t
To help you test your deployed backend agent on its own, without needing a dedicated frontend, here are some friendly options you can try out: 1. Use the LiveKit Agents Playground: This is a handy web-based tool where you can interactively test your agent without having to build a custom UI. Just head over to the LiveKit Agents Playground (replace with your LiveKit environment URL) and connect to a room. If your agent is running with the same LiveKit credentials, it will join automatically. 2. Run the Agent in Console Mode: You can also start your agent locally in
console
mode to test how it works right in your terminal. Just run: `python myagent.py console`This mode is great because it uses your local microphone and speakers, so you get real-time interaction. 3. Agent-to-Agent Testing: Another neat approach is to use a second agent as a simulated user to test your deployed agent programmatically. This way, you can have automated and repeatable interaction tests. 4. Programmatic Testing: If you’re comfortable with Python, you can take advantage of the built-in test framework to write behavioral tests for your agent. This is perfect for automated testing, especially if you’re integrating with CI/CD pipelines. 5. Load Testing: To see how your agent performs under pressure, you can use the LiveKit CLI for load testing. It lets you dispatch your agent to multiple rooms and simulate user interactions. For example:
lk perf agent-load-test --rooms 5 --agent-name test-agent --duration 5m
These options should give you a good way to validate your backend agent’s functionality on its own. If you’d like, I’m here to help you set up any of these methods—just let me know! Sources: README.md | Testing and evaluation | LiveKit Docs | README.md | Agent Testing & CI/CD | livekit/livekit_composite | DeepWiki | SIP & Telephony Applications | livekit/livekit_composite | DeepWiki
a
"*Use the LiveKit Agents Playground:* This is a handy web-based tool where you can interactively test your agent without having to build a custom UI. Just head over to the LiveKit Agents Playground (replace with your LiveKit environment URL) and connect to a room. If your agent is running with the same LiveKit credentials, it will join automatically." this does not work, it throws me a frontend error...
t
I'm sorry to hear you're running into a frontend error with the LiveKit Agents Playground. Let's work through some troubleshooting steps together to get this sorted out: 1. Check Agent Connection: First, please make sure your agent is up and running, and connected to the same room as the Playground. Double-check that the
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
are consistent between your agent and the Playground environment. 2. Verify Media Tracks: The Playground expects the agent to publish both audio and video tracks. Could you confirm that your agent is set up to publish these tracks after joining the room? For instance, in Python, you’d use
room.local_participant.publish_video(track)
. 3. Monitor Agent Logs: It’s helpful to look at the agent's status and logs using the LiveKit CLI to spot any errors when joining the room or publishing media tracks:
Copy code
lk agent status --id <agent-id>
lk agent logs --id <agent-id> --log-type=deploy
4. Browser Permissions: If your error seems related to media permissions, please check that the Playground has permission to access your microphone and camera. You can verify and update these in your browser settings if needed. 5. Hosted vs. Local Playground: If you’re running a local Playground setup, please ensure your environment variables are correctly set in the
.env.local
file, including
NEXT_PUBLIC_LIVEKIT_URL
. If you can share the exact error message you’re seeing, I’d be happy to help you troubleshoot further and find a solution that works for you! Sources: README.md | README.md | Troubleshooting Latency and Timeout Errors with Turn Detection on AWS | quickstart/src/userfriendlyerror.js | README.md
a
what I do not understand is the following. assume I have both the same agent deployed in livekit cloud, and running locally. I have the frontend running locally. all share the exact same credentials. how does the frontend know who to talk to?
t
I completely understand how this can feel a bit confusing! Just to clarify, the frontend itself doesn’t directly decide which agent to connect to when multiple agents share the same credentials. Instead, LiveKit’s server-side system takes care of assigning agents. When an agent connects to LiveKit, it registers as a worker ready to handle specific jobs, like managing a room or participants. LiveKit then uses a smart load balancing system to make sure each job is assigned to only one agent at a time. So, if you happen to have both a local and a cloud-deployed agent running with the same credentials, LiveKit will choose which one to assign the job to based on factors like load balancing or geographic proximity. Please feel free to reach out if you’d like me to explain this in more detail or if there’s anything else you’re curious about—I’m here to help! Sources: LiveKit Docs | Deploying to custom environments | LiveKit Docs
a
ok now if I run both the agent and the frontend locally they work perfectly fine together. But I still do not understand how to make the livekit cloud deployed agent work with my frontend... maybe my frontend needs to be deployed as well first?
t
Great news! Your frontend doesn’t actually need to be deployed to work with a LiveKit Cloud agent—it can run right on your local machine and still connect seamlessly to the cloud-deployed agent. The key is making sure your frontend and agent are using the same LiveKit credentials (
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
), so they can communicate smoothly. If you’re finding that the local frontend isn’t connecting properly with the cloud agent, there might be a little hiccup with the agent’s deployment or configuration. No worries though—you can easily check the agent’s status using the LiveKit CLI with these commands:
Copy code
lk agent status --id <agent-id>
lk agent logs --id <agent-id> --log-type=deploy
Please feel free to reach out if you’d like a hand troubleshooting this further—I’m here to help! Sources: README.md | Deploying to production | LiveKit Docs | TEMPLATE.md | README.md | README.md
a
If I run my frontend locally, I get an error that the agent did not join the room after some time. in livekit cloud I can see my agent up and running. credentials (
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
) are exactly the same between frontend and livekit cloud deployed agent. how can I fix?
t
If your LiveKit Cloud agent isn’t joining the room even though the credentials match with your local frontend, don’t worry! Let’s walk through some helpful steps together to get this sorted out: 1. Verify Agent Dispatch: Make sure the agent is explicitly dispatched to the room using the
CreateAgentDispatchRequest
. It’s important that the room name and agent name match exactly. 2. Check Agent Token: Double-check that the agent is authenticating with a valid JWT token containing
kind: "agent"
and the correct room grants. For example:
Copy code
livekit_token = (
    api.AccessToken(api_key, api_secret)
    .with_kind("agent")
    .with_grants(api.VideoGrants(room_join=True, room=room_name))
    .to_jwt()
)
3. Monitor Agent Logs: You can use the LiveKit CLI to peek at the agent’s status and logs. This can reveal any errors during room entry or media track publication:
Copy code
lk agent status --id <agent-id>
lk agent logs --id <agent-id> --log-type=deploy
4. Validate Environment Variables: It’s a good idea to double-check that both your frontend and agent are using the same
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
. Sometimes a tiny typo can cause issues! 5. Ensure Room and Agent Are Running Concurrently: Confirm that the agent process is actively running when your frontend connects and that the room is up and available. 6. Test with Known Examples: If you want, try out example apps like
agent-starter-react
or
realtime-playground
to validate your setup and credentials. They can be really helpful for pinpointing issues. If you’re still running into trouble, please share any specific error messages or logs you’re seeing. I’m here to help and we’ll figure this out together! Sources: room.go | Getting Help & Troubleshooting | livekit/livekit_composite | DeepWiki | README.md | pkg/loadtester/agentloadtester.go | Accepting inbound calls | LiveKit Docs