victorious-monitor-50234
10/16/2025, 7:08 AMtall-airline-16756
10/16/2025, 7:08 AMtall-airline-16756
10/16/2025, 7:09 AMgenerate_reply, you can simply initialize the session with a predefined chat context using the chat_ctx parameter in the Agent or AgentTask constructor. This way, the session starts off with the context you want already loaded, making things smoother for you.
Here’s a friendly example to guide you:
chat_ctx = llm.ChatContext.empty()
chat_ctx.add_message(role="system", content="You are a helpful assistant.")
chat_ctx.add_message(role="user", content="I need help planning a trip.")
agent = Agent(
llm=openai.realtime.RealtimeModel(),
chat_ctx=chat_ctx # Preloads full history
)
This approach helps you avoid triggering speech or response generation right away and directly injects the context into the session. If you’d like, I’m here to help with any further questions or to provide more examples—just let me know!
Sources: Workflows | LiveKit Docs | examples/voice_agents/multi_agent.py | pipeline-llm/large_context.py | Real-time AI Models & Streaming | livekit/livekit_composite | DeepWiki | Agent speech and audio | LiveKit Docsvictorious-monitor-50234
10/16/2025, 7:10 AMtall-airline-16756
10/16/2025, 7:11 AMparticipant_connected event. This helps you detect the start of the call and immediately set up the session with the context or response you want.
Here’s a simple example to guide you:
@ctx.room.on("participant_connected")
def on_participant_connected(participant):
if "sip_" in participant.identity:
agent.chat_ctx.add_message(role="system", content="Welcome to our service. How can I assist you today?")
agent.start(ctx.room, participant)
session.generate_reply() # Trigger immediate response
This way, the LLM is all set and ready to respond as soon as the call connects. If you’d like me to walk you through it more or provide some extra examples, just let me know—I’m here to help!
Sources: Real-time AI Models & Streaming | livekit/livekit_composite | DeepWiki | External data and RAG | LiveKit Docs | sip-refer/README.mdoc | examples/voice_agents/realtime_load_chat_history.py | SIP Integration & Telephony | livekit/livekit_composite | DeepWiki