silly-dusk-24995
09/04/2025, 9:55 AMabc()
But in practice I end up with “Great, let’s do that” being spoken twice — once before and once after the tool call.tall-airline-16756
09/04/2025, 9:55 AMtall-airline-16756
09/04/2025, 9:56 AMsilly-dusk-24995
09/04/2025, 9:59 AMtall-airline-16756
09/04/2025, 9:59 AMchat_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 Docssilly-dusk-24995
09/04/2025, 10:04 AMtall-airline-16756
09/04/2025, 10:05 AMsilly-dusk-24995
09/04/2025, 10:07 AMtall-airline-16756
09/04/2025, 10:08 AMrecent_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:
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:
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!