I’m using LiveKit’s multi-agentic architecture, an...
# ask-ai
s
I’m using LiveKit’s multi-agentic architecture, and I’m running into a problem where both agents output the same conversation line before and after a tool call. For example: Model (before tool call): “Great, let’s do that.” Model (tool call):
abc()
But in practice I end up with “Great, let’s do that” being spoken twice — once before and once after the tool call.
t
Thanks for reaching out, Abdullah. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Could you help me understand how you're handling the state and synchronization between the agents in your multi-agent setup? For instance, are you using any particular methods to keep track of or prevent repeated outputs?
s
we are using chat context and chat history. and we are not preventing any repeated output through code
t
Hey there! To help you tackle those repeated outputs in your multi-agent setup, here are a few friendly tips: • Keep and pass along the chat context: Make sure the
chat_ctx
is passed explicitly when switching between agents. This helps keep the conversation flowing smoothly and avoids repeating replies. • Watch out for duplicate messages: Before adding new messages to the chat context, double-check they’re not already there. Using
update_chat_ctx
with care can really help prevent repeats. • Trim down chat history: Try using the
truncate()
method to keep only the latest messages. This way, you won’t keep processing old context that might cause repeats. • Manage interruptions thoughtfully: Make sure that if a message gets interrupted, it doesn’t get generated again or repeated afterward. Keeping an eye on interruption flags in your code can do the trick. • Use a read-only chat context: While your agents are running, wrap the active
chat_ctx
in a read-only wrapper. This stops accidental changes. If you need to update it, go through
.copy()
and
.update_chat_ctx()
. Following these steps should help reduce those pesky repeated outputs. If you’re still seeing duplicates, could you let me know if they happen during agent handoffs or if messages are being added manually without checking for duplicates? I’m here to help! Sources: Workflows | LiveKit Docs | examples/voice_agents/realtime_load_chat_history.py | OpenAI Realtime API integration guide | LiveKit Docs | Azure OpenAI Realtime API and LiveKit | LiveKit Docs
s
in my example both main_agent and booking agent are saying same stuff 2025-09-04 143836,633 - INFO modular-callflow - TRANSCRIPTION: {'agent': 'main_agent', 'role': 'assistant', 'transcription': "Perfect, let's do that."} {"pid": 542886, "job_id": "AJ_LXGm6YYBzQMA"} 2025-09-04 143842,796 - INFO modular-callflow - TRANSCRIPTION: {'agent': 'virtual_booking_agent', 'role': 'assistant', 'transcription': "Perfect, let's do that. I'll help you book a call with our strategist now."} {"pid": 542886, "job_id": "AJ_LXGm6YYBzQMA"}
t
Hey there! To help tackle the issue of duplicate outputs from multiple agents, here are a few friendly tips you can try out: • Signal deduplication: LiveKit has a handy signal deduper that can skip over duplicate signal messages. Make sure this is turned on in your setup. • Message validation: Double-check that you’re only getting one message generation when you expect it. If you see multiple messages popping up, it’s a good idea to log that and handle it to keep things tidy. • Agent task validation: Try to ensure only one agent task is running at a time. If more than one shows up, log an error and sort out the conflict. • Duplicate protection: LiveKit also offers built-in protection against duplicate subscriptions, which helps avoid overlapping responses. These steps should really help cut down or even stop those duplicate outputs. If you’re still running into trouble, could you let me know if both agents are creating their responses separately, or if there’s some shared logic that might be causing the overlap? I’m here to help! Sources: CHANGELOG.md | livekit-agents/livekit/agents/voice/agent_activity.py
s
can you share the example for it?
t
Here’s a handy example to help you prevent duplicate outputs when working with multiple agents: 1. Signal Deduplication: Try using a deduplication method to filter out repeated signals. For example, you can keep a set of recent messages and check new ones against it before processing:
Copy code
recent_messages = set()
def process_message(agent, message):
    if message in recent_messages:
        return  # Skip duplicate
    recent_messages.add(message)
    # Process the message
    print(f"{agent}: {message}")
1. Message Validation: Make sure only one message gets processed when there are multiple. Like this:
Copy code
if len(messages) > 1:
    logger.warning("Multiple messages received, processing the first one.")
message = messages[0]
process_message(agent, message)
1. Agent Task Validation: Avoid having multiple agents working on overlapping tasks by checking their task states:
Copy code
if agent_task_1.is_active() and agent_task_2.is_active():
    logger.error("Multiple active tasks detected. Resolving conflict.")
    resolve_conflict(agent_task_1, agent_task_2)
These examples should give you a good starting point for handling deduplication and validation to keep your outputs clean. If you want me to walk you through any part or share more examples, just let me know—I’m here to help!