can we speculate why the context between these two...
# ask-ai
f
can we speculate why the context between these two realtime models isn't working ? """" WORKING SWITCH - The simplest solution that actually works """ import os import asyncio from dotenv import load_dotenv load_dotenv(".env") from livekit import agents from livekit.agents import AgentSession, Agent from livekit.plugins import google, openai # Store context globally CONTEXT = None class GeminiAgent(Agent): def __init__(self): global CONTEXT super().__init__( llm=google.beta.realtime.RealtimeModel( model="gemini-2.5-flash-exp-native-audio-thinking-dialog", voice="Puck", api_key=os.getenv("GOOGLE_GEMINI_API_KEY"), ), instructions="You are using Gemini/Puck voice. Remember everything.", chat_ctx=CONTEXT ) async def on_enter(self): print("\n>>> GEMINI ACTIVE (Puck voice)") await asyncio.sleep(30) global CONTEXT CONTEXT = self.session.history.copy() if self.session.history else None self.session.update_agent(OpenAIAgent()) class OpenAIAgent(Agent): def __init__(self): global CONTEXT super().__init__( llm=openai.realtime.RealtimeModel( model="gpt-4o-realtime-preview", voice="shimmer", ), instructions="You are using OpenAI/Shimmer voice. Remember everything.", chat_ctx=CONTEXT ) async def on_enter(self): print("\n>>> OPENAI ACTIVE (Shimmer voice)") await asyncio.sleep(30) global CONTEXT CONTEXT = self.session.history.copy() if self.session.history else None self.session.update_agent(GeminiAgent()) async def entrypoint(ctx: agents.JobContext): print("\nSwitches every 30 seconds. Both should remember your conversation.\n") session = AgentSession() await session.start(room=ctx.room, agent=GeminiAgent()) if name == "__main__": agents.cli.run_app(agents.WorkerOptions(entrypoint_fnc=entrypoint))"
t
Thanks for reaching out, Doug. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! It looks like there could be a few reasons why context sharing between your two realtime models isn’t working quite right. Let’s walk through some possibilities together: • Agent-to-Agent Communication: By default, LiveKit agents don’t pick up speech from other agents in the same room. To get context sharing going, make sure
RoomInputOptions.participant_kinds
includes
rtc.ParticipantKind.PARTICIPANT_KIND_AGENT
. • Conversation History Loading: Sometimes, realtime models struggle to load conversation history properly, which can mess with context sharing. A handy workaround is to use a separate TTS plugin and stick to text-only responses. • Delayed Transcription and Context Updates: If transcription is delayed, context updates might arrive out of order, causing incomplete or outdated info to be shared between the models. • Turn Detection and VAD Limitations: Realtime models depend on turn detection to share context. If you’re using LiveKit’s turn detector model, double-check that you’ve added a separate STT plugin for interim transcripts. • Context Update Synchronization: Timing can be tricky! If context updates aren’t processed in the right sequence, models might get out of sync. Keeping updates in order is key. If you want, I’m here to help you dig deeper into any of these points or guide you through the setup. Just let me know!