HOW can i create agent dynamically like retellai
# ask-ai
c
HOW can i create agent dynamically like retellai
t
Thanks for reaching out, Arun. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To create a dynamic agent in LiveKit, there are a few wonderful approaches you can explore: • Dynamic Avatar Creation: You can generate and display a visual avatar in real-time based on a description, making the experience more engaging. • Dynamic Tool Creation: It’s possible to add or update tools on the fly during runtime, which helps extend your agent’s capabilities smoothly. • Multi-Agent Workflows: This allows for seamless transitions between specialized agents depending on the conversation context, keeping interactions natural and efficient. • Dynamic Configuration: You can switch between plugins and models (like STT, LLM, TTS) dynamically, tailoring the agent to your needs. • Real-time Adaptability: Modify your agent’s behavior using dynamic instructions, context variables, and background tasks to keep things flexible and responsive. For instance, you might load tools dynamically based on user context or external data, or create agents that adapt their instructions and capabilities in real-time. If you’d like, I’m here to help with detailed implementation steps for any of these features—just let me know! Sources: Tool definition and use | LiveKit docs | docs/index.yaml | livekit-agents/README.md | Workflows | LiveKit docs | examples/src/multi_agent.ts
c
can we run muiple ahgent in one port
t
Yes, you absolutely can have multiple agents running on a single port in LiveKit! For instance, several agent clients can connect to the same server port and register as workers, each handling different job types or namespaces at the same time. Plus, each worker can manage multiple jobs simultaneously in isolated processes, which helps keep everything stable and running smoothly. If you'd like, I’m here to walk you through more details or share some examples to help you set this up. Just let me know! Sources: pkg/service/agentservice.go | Worker lifecycle | LiveKit Docs
c
give me from livekit.agents import Agent, JobContext, WorkerOptions, cli from livekit.agents.voice import AgentSession from livekit.plugins import silero, deepgram, groq, cartesia from dotenv import load_dotenv load_dotenv() class SupportAgent(Agent): def __init__(self): super().__init__( instructions="You are a helpful support agent. start saying your name is tom, you need start conversation", stt=deepgram.STT(), llm=groq.LLM(model="llama-3.1-8b-instant"), tts=cartesia.TTS(model="sonic-3", voice="e3087ad8-7018-4154-9a87-11577f916cd4"), vad=silero.VAD.load(), ) async def entrypoint(ctx: JobContext): await AgentSession().start(agent=SupportAgent(), room=ctx.room) def run(): cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint, agent_name="support", port=8081)) if name == "__main__": run()from dotenv import load_dotenv from livekit import agents from livekit.agents import AgentSession, Agent, RoomInputOptions from livekit.plugins import silero, deepgram, groq, cartesia load_dotenv() class BillingAgent(Agent): def __init__(self) -> None: super().__init__( instructions=""" You are Tom, a helpful and friendly AI voice assistant for Dhofar Insurance Company S.A.O.G. 🎯 Your Purpose: - Greet customers warmly and introduce yourself as a Dhofar Insurance representative. - Assist customers with insurance-related inquiries such as products, contact info, and locations. - Always respond clearly, concisely, and in a friendly, professional tone. - Avoid using emojis, asterisks, or complex formatting. 🏢 Company Overview: Dhofar Insurance Company S.A.O.G is one of Oman’s leading insurers, headquartered in Ruwi, Muscat. It provides comprehensive insurance coverage for individuals and businesses. 📍 Head Office: - Address: P.O. Box 1002, Postal Code 112, Ruwi, Sultanate of Oman. - Phone: (+968) 24 705 305 - Fax: (+968) 24 782 801 - Email: dhofar@dhofarinsurance.com - Toll-Free Helpline: 8000 77 77 - Website: www.dhofarinsurance.com 🌐 Branch Network: Dhofar Insurance operates nationwide across Oman, including Salalah and other major regions. 💼 Insurance Products: - Motor Insurance - Life Insurance - Medical Insurance - Travel Insurance - Home Contents Insurance - Property Insurance - Liability Insurance - Marine Insurance - Energy Insurance - Industrial Insurance - Engineering Insurance - Borrowers Life Insurance - Oil & Petroleum Insurance - Personal Accident Insurance - Workmen’s Compensation Insurance 🧾 Customer Services: - Feedback & Complaints - Make a Claim - Request a Quote - Buy Online - Customer Support available through WhatsApp and toll-free helpline. 🗣️ Behavior Guidelines: - you should never answer to any question that is not related to Dhofar Insurance. - Always introduce yourself as "Tom from Dhofar Insurance". - Keep responses under 3 sentences unless clarification is needed. - If you don’t know something, say: "I’m not sure about that, but I can connect you with our customer care team." Start by greeting the user and offering assistance. """, ) async def entrypoint(ctx: agents.JobContext): session = AgentSession( stt=deepgram.STT(), llm=groq.LLM(model="llama-3.1-8b-instant"), tts=cartesia.TTS(model="sonic-3", voice="e3087ad8-7018-4154-9a87-11577f916cd4"), vad=silero.VAD.load(), ) await session.start( room=ctx.room, agent=BillingAgent(), room_input_options=RoomInputOptions(), ) await session.generate_reply( instructions="Hello, this is Tom from Dhofar Insurance. How may I assist you today?, and explain what all u can do, finally ask caller name?" ) if name == "__main__": agents.cli.run_app( agents.WorkerOptions( entrypoint_fnc=entrypoint, agent_name="billing", port=8082 ) ) how to run this agent sin one port
t
To run multiple agents on one port in LiveKit, you can use the agent worker framework, which is a great way to let a single worker process manage multiple agent jobs at the same time. Each agent job runs in its own isolated process, so you can have several agents working together smoothly on the same port. Here’s a simple way to get started: • Set up multiple agent clients that connect to the LiveKit server using the same port. • Each agent can register for different job types or namespaces based on what you need. • The agent worker framework takes care of balancing the load and managing these concurrent jobs for you. • For instance, you can send multiple agents to a room using the
RoomAgentDispatch
configuration or participant tokens. This approach helps you use your resources efficiently and scale up easily. If you’d like, I’m here to help you with the implementation or answer any questions you have! Sources: README.md | README.md
c
each agent shouwl not ahve conenctions
t
In LiveKit, I understand it might seem tricky, but multiple agents can't share a single WebSocket connection to the server. Each agent process needs to establish its own connection for communication and signaling. That said, there’s a great way to use your resources efficiently by having a single "Agent Worker" process manage multiple concurrent agent jobs on the same port. Here’s a friendly breakdown of how this works: • Single Worker, Multiple Jobs: You start one Agent Worker process that registers on a specific port (like 8080). This worker can handle multiple jobs internally, which keeps things neat and organized. • Process Pooling: The worker uses an internal process pool to manage job execution, launching isolated processes for each job to keep everything running smoothly. • Job Dispatch: The LiveKit server assigns jobs to the worker, and the worker efficiently manages them without needing separate connections for each agent. This approach really helps with scalability and stability while keeping the number of external connections to a minimum. If you’d like, I’m here to help clarify anything or assist you with the implementation—just let me know! Sources: Job lifecycle | LiveKit Docs | pkg/service/agentservice.go | Worker lifecycle | LiveKit Docs | agents/src/worker.ts | livekit-agents/livekit/agents/worker.py
c
• Single Worker, Multiple Jobs: You start one Agent Worker process that registers on a specific port (like 8080). This worker can handle multiple jobs internally, which keeps things neat and organized. simep exmaple
t
Here’s a simple example of running a single Agent Worker process that handles multiple jobs in LiveKit:
Copy code
from livekit import agents

class MyAgent:
    @classmethod
    async def create(cls, ctx: agents.JobContext):
        agent = MyAgent(ctx)
        await agent.start()

    def __init__(self, ctx: agents.JobContext):
        self.ctx = ctx

    async def start(self):
        # Example: Log when the agent starts
        print(f"Agent started for room: {self.ctx.room}")

if __name__ == "__main__":
    async def job_request_cb(job_request: agents.JobRequest):
        await job_request.accept(
            MyAgent.create,
            identity="my-agent",
            name="My Agent",
        )

    # Create and run the worker
    worker = agents.Worker(request_handler=job_request_cb)
    agents.run_app(worker)
### Steps: 1. Define your agent logic in the
MyAgent
class. 2. Use the
job_request_cb
callback to accept job requests and assign them to the agent. 3. Start the worker process, which will handle multiple jobs concurrently. If you have any questions or would like me to walk you through any part of this, please don’t hesitate to ask. I’m here to help! Sources: server/agent.py | Log collection | LiveKit Docs | livekit-agents/livekit/agents/cli/proto.py | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | Job lifecycle | LiveKit Docs
c
i want mupleit agent in singel procees agents hsoune not ahve context of each
t
Running multiple agents in a single process without sharing context isn’t something LiveKit’s architecture supports directly. Usually, each agent runs in its own separate process to keep their contexts and resources nicely separated. But don’t worry—you can still achieve similar functionality by: • Using one worker process to handle multiple jobs, where each job acts as an agent with its own isolated context. • Setting up distinct namespaces or job types for each agent to keep things logically separated. • Using the
JobContext
object to maintain isolated state for each agent, even within the same worker process. If you’d like, I’m here to help guide you through setting this up—just let me know! Sources: Building Multi-Agent Architectures with LiveKit Agents | Job lifecycle | LiveKit Docs | livekit-agents/livekit/agents/job.py | Node.js Agents Architecture | livekit/livekit_composite | DeepWiki | test/agent_test.go
c
• code for above iwht 2 agents with 2 anmes
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!
c
• code for above with 2 agents with 2 names
hy