Can we runs the agents parallel like one agent is ...
# ask-ai
w
Can we runs the agents parallel like one agent is getting data another agent is calling api?
t
Thanks for reaching out, Chiranjeevi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Yes, LiveKit supports running multiple agents in parallel where one agent can handle data while another agent calls an API. The framework is designed to support multi-agent workflows, allowing each agent to be configured with specific tasks and functionalities. This enables coordinated work between agents, such as parallel data processing and API integration, to build complex and flexible workflows. If you need details on how to set this up in your project, please let me know your use case or any specific requirements. Sources: README.md | Realtime media | LiveKit Docs
w
Parallel Execution Agent Pattern?
t
Hey there! šŸ‘‹ Let me break down the Parallel Execution Agent Pattern in LiveKit in a way that's super easy to understand. Think of this as a cool way to make your software work smarter, not harder. Imagine you've got a bunch of tasks that need to run at the same time - this pattern is like having a super-efficient team that can juggle multiple jobs without breaking a sweat. šŸ˜Ž Here's what makes it awesome: • Parallel Data Handling: The
ParallelExec
function is like a task manager that splits up work across different CPU cores. It's basically spreading the workload so nothing gets overwhelmed. • Concurrent Job Execution: These agents can run multiple jobs separately, kind of like having different rooms where work happens without anyone bumping into each other. • LLM Parallel Tool Calls: This means you can do multiple things at once - like transcribing audio, generating responses, and making API calls all simultaneously. Talk about multitasking! šŸš€ • Process Isolation: Each agent runs in its own little workspace, which keeps everything neat and prevents any unwanted interactions. • Event-Driven Architecture: Components like
LLMStream
let you run background tasks smoothly and efficiently. • Pipeline Architecture: For voice agents, different processing steps (speech-to-text, language processing, text-to-speech) can all happen at the same time, creating super smooth real-time interactions. This pattern is a total game-changer for scenarios where you need to handle complex workflows with tons of moving parts.Curious about how to actually implement this? Just let me know what you're working on, and I'd be happy to help you dive deeper! 😊Go, TypeScript, and JavaScript code snippets are ready to show you the magic.All of this comes straight from analyzing LiveKit's official code and docs. Let me know if you want to geek out more! šŸ¤“ Sources: utils/parallel_test.go | agents/src/pipeline/pipeline_agent.ts | .github/next-release/changeset-5292c7c6.md | An open source stack for real-time multimodal AI | LLMStream | LiveKit Agents | LLMStream | LiveKit Agents
w
Yes, can you give me a example code where I can call 2 Agents parallel in python
t
Here is an example of how to run two LiveKit agents in parallel using Python by launching them as separate worker processes. Let me walk you through this – it's actually pretty straightforward! šŸ¤–agent1.py:
Copy code
from dotenv import load_dotenv
from livekit.agents import Agent, AgentSession, JobContext, WorkerOptions, cli
from livekit.plugins import deepgram, openai, silero

load_dotenv()

class Agent1(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions="You are Agent 1",
            stt=deepgram.STT(),
            llm=openai.LLM(model="gpt-4o"),
            tts=openai.TTS(voice="nova"),
            vad=silero.VAD.load()
        )

async def entrypoint(ctx: JobContext):
    await ctx.connect()
    session = AgentSession()
    await session.start(
        agent=Agent1(),
        room=ctx.room
    )

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
agent2.py:
Copy code
from dotenv import load_dotenv
from livekit.agents import Agent, AgentSession, JobContext, WorkerOptions, cli
from livekit.plugins import deepgram, openai, silero

load_dotenv()

class Agent2(Agent):
    def __init__(self) -> None:
        super().__init__(
            instructions="You are Agent 2",
            stt=deepgram.STT(),
            llm=openai.LLM(model="gpt-4o"),
            tts=openai.TTS(voice="echo"),
            vad=silero.VAD.load()
        )

async def entrypoint(ctx: JobContext):
    await ctx.connect()
    session = AgentSession()
    await session.start(
        agent=Agent2(),
        room=ctx.room
    )

if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
Run each agent in separate terminal windows:
Copy code
python agent1.py start
python agent2.py start
Then dispatch the agents to their rooms:
Copy code
lk dispatch create --agent-name agent1 --room room1
lk dispatch create --agent-name agent2 --room room2
This setup runs both agents independently and in parallel. Pretty cool, right? šŸš€I'm here if you want to chat more about integration or need help with specific deployment details. Don't hesitate to reach out! Sources: complex-agents/medical_office_triage/triage.py
w
I am talking about agent not agent sessions
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!
hi @witty-yak-62929. could you give us a bit more details on what you are trying to accomplish? what the agent showed here is right if you are trying to run 2 agents at the same time. but, are you looking to add 2 agents in the same room?
w
Hi @tall-belgium-91876 I need to do 2 things same time, like I need to detect the language and same time I need to query RAG. So before answering I have context and answer in detected language. Help me if we can do this by asking multiple agents in same room
t
how are you detecting the language? are you using the STT for that? or something else?
w
Right now am adding a tool and prompting to give language based on question
t
ah ok. so you ask the user to say their language preference and then you get the result back and set it.
and when does the RAG come in? is that in the next step when they ask their question?
it sounds like you are describing a workflow. if so, you can split this into multiple agents. from the language tool you can hand off to the "support agent". there are good examples here: https://docs.livekit.io/agents/build/workflows/
w
No, @tall-belgium-91876 if user ask question I am asking to call tool in which language the question is asked.
t
ok. i'm sorry but i'm pretty confused. could you write out the steps and/or what is supposed to happen?