Should every agent have their separate entry_point...
# ask-ai
c
Should every agent have their separate entry_point while deploying?
t
Thanks for reaching out, Subham. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! Just to make sure I’m on the right track, are you asking if each agent needs its own unique entry point function for their logic, or are you talking about deployment setups where agents have different entry points for various tasks? Getting this clear will help me give you the best answer possible. Sources: agent/requirements.txt | test/agents/requirements.txt | examples/avatar_agents/audio_wave/requirements.txt | Deployment and scaling | LiveKit Docs | cmd/lk/agent.go
c
I was talking about the first case
t
Each agent should have its own unique
entrypoint
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!
c
I want to have several agents who are going to have different llm prompts but they are all voice agents. What should the case be?
t
Hey! Since all your agents are voice agents but use different LLM prompts, you can totally use a shared
entrypoint
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!
c
Could you provide me with some example?
t
Here’s a friendly example to show you how you can set up a shared
entrypoint
function for multiple voice agents, each with their own unique LLM prompts:
Copy code
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!
c
Can they have different tts models for separate models?
t
Absolutely! You can totally set up different TTS (Text-to-Speech) models for each agent while still using a shared
entrypoint
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:
Copy code
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!