creamy-tiger-14805
08/29/2025, 2:52 PMtall-airline-16756
08/29/2025, 2:52 PMtall-airline-16756
08/29/2025, 2:52 PMcreamy-tiger-14805
08/29/2025, 2:53 PMtall-airline-16756
08/29/2025, 2:54 PMentrypoint function if their logic or responsibilities are different. Think of the entrypoint as the starting line for the agent’s logic—it kicks things off by initializing state, setting up event listeners, and running the main functionality.
For instance, if one agent is handling audio while another is focused on text responses, they’d each need their own entrypoint tailored to what they do best. On the other hand, if several agents are doing the same kind of work, they can happily share the same entrypoint.
If you want, I’m here to help with more details or examples on how to set this up—just let me know!creamy-tiger-14805
08/29/2025, 2:56 PMtall-airline-16756
08/29/2025, 2:56 PMentrypoint function—especially if the main way you handle voice interactions is the same. The trick is to pass in the agent-specific details, like their unique LLM prompts, through environment variables, metadata, or a config file.
Here’s a simple way to think about it:
• Create one entrypoint function that manages the voice agent logic for everyone.
• Load the right LLM prompt for each agent at runtime using metadata or environment variables tailored to each one.
• Inside the entrypoint, grab the prompt based on the agent’s ID or config, and plug it into the LLM logic.
This way, you keep your entrypoint neat and avoid repeating code, while still letting each agent have its own unique behavior through their prompts. If you want, I’d be happy to share an example or help you set it up—just let me know!creamy-tiger-14805
08/30/2025, 5:09 AMtall-airline-16756
08/30/2025, 5:10 AMentrypoint function for multiple voice agents, each with their own unique LLM prompts:
import os
from livekit.agents import JobContext
# Define the entrypoint function
async def entrypoint(ctx: JobContext):
# Grab the agent-specific LLM prompt from environment variables or metadata
agent_id = ctx.metadata.get("agent_id") # For example: agent_id passed via metadata
llm_prompt = os.getenv(f"PROMPT_{agent_id}") # Like PROMPT_AGENT1, PROMPT_AGENT2, etc.
if not llm_prompt:
raise ValueError(f"No LLM prompt found for agent: {agent_id}")
# Connect the agent to the room
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
# Here’s an example: process audio and use the LLM prompt
@ctx.room.on("track_subscribed")
async def on_track_subscribed(track, *_):
if track.kind == "audio":
response = await process_audio_with_llm(track, llm_prompt)
await ctx.room.local_participant.send_text(response)
# Keep the agent running
await ctx.room.wait_until_disconnected()
# Example function to process audio with the LLM
async def process_audio_with_llm(audio_track, prompt):
# Simulate processing audio and generating a response using the LLM
return f"Processed audio with prompt: {prompt}"
To break it down:
• The agent_id comes through metadata, and then we pull the matching LLM prompt from environment variables.
• The entrypoint function manages the shared logic for all your agents, while each agent’s LLM prompt adds its own special touch.
• Just set environment variables like PROMPT_AGENT1, PROMPT_AGENT2, and so on for each agent when you deploy.
If anything’s unclear or you’d like me to walk through more examples, just let me know—I’m here to help!creamy-tiger-14805
08/30/2025, 5:32 AMtall-airline-16756
08/30/2025, 5:32 AMentrypoint function. Just like with the LLM prompts, you can pass the TTS model configuration as agent-specific metadata or environment variables.
Here’s a friendly example to show you how to extend the previous setup to include TTS models:
import os
from livekit.agents import JobContext
# Define the entrypoint function
async def entrypoint(ctx: JobContext):
# Grab the agent-specific LLM prompt and TTS model from metadata or environment variables
agent_id = ctx.metadata.get("agent_id") # For example: agent_id passed via metadata
llm_prompt = os.getenv(f"PROMPT_{agent_id}") # Like PROMPT_AGENT1, PROMPT_AGENT2, etc.
tts_model = os.getenv(f"TTS_MODEL_{agent_id}") # Like TTS_MODEL_AGENT1, TTS_MODEL_AGENT2, etc.
if not llm_prompt or not tts_model:
raise ValueError(f"Oops! Missing configuration for agent: {agent_id}")
# Connect the agent to the room
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
# Here’s an example: Process audio and use the LLM prompt and TTS model
@ctx.room.on("track_subscribed")
async def on_track_subscribed(track, *_):
if track.kind == "audio":
response = await process_audio_with_llm(track, llm_prompt)
tts_audio = await generate_tts_audio(response, tts_model)
await ctx.room.local_participant.publish_audio(tts_audio)
# Keep the agent running
await ctx.room.wait_until_disconnected()
# Example function to process audio with the LLM
async def process_audio_with_llm(audio_track, prompt):
# Simulate processing audio and generating a response using the LLM
return f"Processed audio with prompt: {prompt}"
# Example function to generate TTS audio
async def generate_tts_audio(text, tts_model):
# Simulate generating TTS audio using the specified model
return f"Audio generated with model: {tts_model}"
So, in this example:
• We pull the tts_model for each agent based on their unique ID.
• The generate_tts_audio function creates audio output using the TTS model you specify.
• You can set environment variables like TTS_MODEL_AGENT1, TTS_MODEL_AGENT2, and so on for each agent when you deploy.
This way, each agent can have its own TTS model while sharing the same core logic. If you want, I’m here to help with anything else you need!