Hello everyone, Can anyone provide me the proper w...
# ask-ai
d
Hello everyone, Can anyone provide me the proper workflow on how to connect the deployed ai agent on LiveKit cloud with a customise frontend and backend to use the dynamic prompts for agents. I am currently working on a 6 agent system which is working fine on my system but I clearly don't know and can't figure out through documentation on how to execute the same in the production environment.
t
Thanks for reaching out, Vaibhav. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
d
How much would you take?
t
I'd love to help you set up the best workflow for connecting your deployed AI agent on LiveKit Cloud with your custom frontend and backend for dynamic prompts. To make sure I guide you accurately, could you please share a bit more about your setup? • Are you working with a realtime model (like OpenAI Realtime) or using a standard STT-LLM-TTS pipeline? • Would you like prompts to update based on user input, external data, or manual triggers? • Do you want to personalize prompts per user, or are they more context-based? Knowing this will really help me tailor the best solution just for you. Looking forward to your response! Sources: Client SDKs | livekit/livekit_composite | DeepWiki | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | complex-agents/nova-sonic/README.md | README.md | Deploying to custom environments | LiveKit Docs
d
1 - I am using standard STT-LLM-TTS pipeline 2 - I want the prompts to be updated upon arrival in the room. 3 - Yes, Prompts are personalised per user. It is just details about the user who is going to connect with the agent.
t
I'm here to help you connect your deployed AI agent on LiveKit Cloud with a custom frontend and backend for personalized prompts in a standard STT-LLM-TTS pipeline. Let’s walk through the steps together: 1. Set Up Agent Session: Start by using the
AgentSession
to include a
userData
object. This is a great way to keep track of user-specific data, so you can tailor prompts based on each user’s details. 2. Implement Lifecycle Hooks: Next, use the
onEnter()
lifecycle hook in your agent. This lets you update prompts dynamically whenever a user joins the room. For example: `class IntroAgent extends voice.Agent { async onEnter() { this.session.generateReply({ instructions:
Greet the user and personalize based on their details.
}); } }` 3. Personalize Prompts: Then, create a follow-up agent that uses the user data you’ve gathered to adjust its instructions dynamically. Here’s how you might do it: `class StoryAgent extends voice.Agent { static create(name, location) { return new StoryAgent({ instructions:
You are a storyteller. The user’s name is ${name}, from ${location}.
}); } }` 4. Frontend Integration: On the frontend side, you can use RPC calls to send user details to your backend smoothly. For example:
Copy code
// Frontend
await room.localParticipant?.rpc('updatePrompt', { name: 'John', location: 'New York' });
`// Backend @agent.on("rpc") async def on_rpc(ctx, method, payload): if method == "updatePrompt": await activity.update_instructions(
User is ${payload['name']} from ${payload['location']}
);` 5. Monitor and Optimize: Finally, keep an eye on how your agent is performing using the LiveKit Cloud dashboard. This will help you fine-tune and improve your implementation over time. This approach will help ensure that your prompts feel personal and relevant to each user as they join the room. If you have any questions or need a hand with any step, please don’t hesitate to reach out—I’m here to support you! Sources: Pipeline nodes and hooks | LiveKit Docs | Models | LiveKit Docs | README.md | Live Conversations with AI using ChatGPT and WebRTC
d
and how would I connect my customised frontend to deployed agent?
t
I'd be happy to guide you through connecting your custom frontend to a deployed AI agent on LiveKit Cloud. Here's a step-by-step approach to make it easier: 1. Use LiveKit SDKs: Start by integrating LiveKit's SDKs (like JavaScript, React, or Swift) into your frontend. These SDKs help manage real-time communication, letting you publish user media (audio/video) and subscribe to the agent’s media streams seamlessly. 2. Authenticate: Next, configure your frontend with the LiveKit server URL, API key, and secret to generate tokens for room access. For example, in a React app, you can use environment variables such as
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
. This step ensures secure and smooth connections. 3. Connect to a Room: Then, use components like
LiveKitRoom
to connect your frontend to the same room as your AI agent. Here's a quick example:
<LiveKitRoom serverUrl="{serverUrl}" token="{token}" />
4. Enable RPC Communication: To exchange data between your frontend and the agent, Remote Procedure Calls (RPC) are very helpful. For instance, you can send user details from the frontend like this:
Copy code
// Frontend
await room.localParticipant?.rpc('updatePrompt', { name: 'John', location: 'New York' });
`// Backend @agent.on("rpc") async def on_rpc(ctx, method, payload): if method == "updatePrompt": await activity.update_instructions(
User is ${payload['name']} from ${payload['location']}
);` 5. Use Starter Templates: To speed things up, LiveKit offers starter templates such as
agent-starter-react
. You can deploy locally with:
Copy code
lk app create --template agent-starter-react
pnpm install && pnpm dev
6. Deploy and Test: Finally, make sure your frontend connects to the same LiveKit project and room as your deployed agent. Keep an eye on the connection and manage agent lifecycle events like connection status to ensure everything runs smoothly. If any part feels tricky or you’d like me to walk you through a specific step, just let me know—I’m here to help! Sources: Web and mobile frontends | LiveKit Docs | complex-agents/note-taking-assistant/note-taker-frontend/README.md | OpenAI and LiveKit partner to turn Advanced Voice into an API | External data and RAG | LiveKit Docs | TEMPLATE.md