fast-egg-39595
08/21/2025, 3:02 AMtall-airline-16756
08/21/2025, 3:02 AMtall-airline-16756
08/21/2025, 3:04 AMconst model = new openai.realtime.RealtimeModel({
instructions: 'You are a helpful assistant.',
});
2. Create and Start the Agent: Next, create the agent using the MultimodalAgent class, passing in your model and an optional function context.
const agent = new multimodal.MultimodalAgent({ model, fncCtx });
const session = await agent.start(ctx.room, participant);
3. Add a Message to the Conversation: To prompt the LLM, add a message using session.conversation.item.create().
session.conversation.item.create(
llm.ChatMessage.create({
role: llm.ChatRole.ASSISTANT,
text: 'How can I help you today?',
})
);
4. Trigger Response Generation: Finally, call session.response.create() to ask the OpenAI Realtime model for a new response.
session.response.create();
This way, the LLM will generate a response based on everything you’ve shared so far. If anything’s unclear or you want to dive deeper, just let me know—I’m here to help!
Sources: ResponseCreateEvent | LiveKit Agents | livekit-agents/livekit/agents/voice/agent_activity.py | Realtime model integrations | LiveKit Docs | plugins/openai/src/realtime/realtime_model.ts | Working with the MultimodalAgent class | LiveKit Docsfast-egg-39595
08/21/2025, 4:59 PMtall-airline-16756
08/21/2025, 5:00 PMfrom livekit.plugins import openai
model = openai.realtime.RealtimeModel(
voice="alloy",
temperature=0.8
)
2. Create and Start the Agent Session: Next, use the AgentSession class to get your session up and running.
from livekit.agents import AgentSession, Agent
session = AgentSession(llm=model)
await session.start(
room=ctx.room,
agent=Agent(instructions="You are a helpful voice AI assistant.")
)
3. Generate a Response: Finally, call the generate_reply() method to create your response.
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
And that’s it! This way, you can generate responses in real-time using the OpenAI Realtime model. If you want me to walk you through any part or share more examples, just let me know—I’m here to help!
Sources: examples/voice_agents/realtime_with_tts.py | complex-agents/nutrition-assistant/agent.py | OpenAI Realtime API integration guide | LiveKit Docs | Realtime model integrations | LiveKit Docs