able-jackal-19719
09/02/2025, 7:23 AMtall-airline-16756
09/02/2025, 7:23 AMtall-airline-16756
09/02/2025, 7:24 AMpip install "livekit-agents[openai]~=1.2"
2. Set Up Authentication: Make sure to set your OpenAI API key in the OPENAI_API_KEY environment variable so everything can talk smoothly.
3. Define Functions: Use the handy @function_tool decorator to create Python functions the agent can call. For example:
from livekit.agents.llm import function_tool
class Assistant(Agent):
@function_tool
async def add_numbers(self, context: RunContext, a: float, b: float):
"""Return the sum of two numbers."""
return str(a + b)
4. Initialize the Agent: Next, set up the RealtimeModel to enable real-time audio and function calling. Here’s a quick example:
from livekit.agents import MultimodalAgent
from livekit.plugins.openai.realtime import RealtimeModel
agent = MultimodalAgent(
model=RealtimeModel(
model="gpt-4o-realtime-preview",
voice="alloy",
temperature=0.8,
tool_choice="auto",
modalities=["text", "audio"],
instructions="You are a helpful assistant."
)
)
5. Connect and Start: Finally, define an entrypoint function to connect your agent to a room and kick things off:
async def entrypoint(ctx: JobContext):
await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
agent.start(ctx.room)
If you want to dive deeper or need more info, check out the LiveKit OpenAI Realtime API guide. Happy coding!
Sources: OpenAI Realtime API integration guide | LiveKit Docs | OpenAI and LiveKit partner to turn Advanced Voice into an API | plugins/openai/src/realtime/api_proto.ts | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/stt.py | solutions/openai_demo/README.mdable-jackal-19719
09/02/2025, 7:26 AMtall-airline-16756
09/02/2025, 7:26 AMgpt-4o-realtime-preview. It’s designed to be super quick for voice interactions and comes with built-in function calling features.
If you want to know more or need a hand with anything, just let me know—I’m here to help!
Sources: OpenAI and LiveKit partner to turn Advanced Voice into an API | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | plugins/openai/src/realtime/realtime_model.ts | Realtime model integrations | LiveKit Docsripe-arm-36009
09/02/2025, 7:28 AMtall-airline-16756
09/02/2025, 7:29 AM