wide-elephant-63050
09/27/2025, 10:56 PMtall-airline-16756
09/27/2025, 10:56 PMtall-airline-16756
09/27/2025, 10:57 PMchat method with a ChatContext that includes your message. The LLM will send back a stream of ChatChunk objects, which you can iterate over to get the response step-by-step.
For example, if you’re using the OpenAI plugin, it would look like this:
from livekit.agents import ChatContext
from livekit.plugins import openai
llm = openai.LLM(model="gpt-4o-mini")
chat_ctx = ChatContext()
chat_ctx.add_message(role="user", content="Hello, this is a test message!")
async with llm.chat(chat_ctx=chat_ctx) as stream:
async for chunk in stream:
print("Received chunk:", chunk.delta)
Just make sure you have the right plugin installed for your provider (for example, pip install "livekit-agents[openai]~=1.2") and that your API keys are set up as environment variables. If you have any questions or want me to walk you through any part of this, please don’t hesitate to ask—I’m here to help!
Sources: Large language model (LLM) integrations | LiveKit Docs | Docs::Agents | Groq LLM integration guide | LiveKit Docs | Baseten LLM integration guide | LiveKit Docs | tests/test_llm.pywide-elephant-63050
09/27/2025, 11:11 PMtall-airline-16756
09/27/2025, 11:12 PMinstructions parameter when creating the LLM instance or agent. For example:
from livekit.plugins import openai
llm = openai.LLM(model="gpt-4o-mini", instructions="You are a helpful assistant.")
• Dynamic Updates: If you need to adjust instructions during an active session, you can use the update_instructions method. This is great for adapting behavior based on the context:
async def on_enter(self):
self.update_instructions("You are a helpful agent speaking on the phone.")
self.session.generate_reply()
• Manual Updates: For more advanced scenarios, like integrating external data, you can directly modify the system message in the chat context:
chat_ctx.items.insert(0, llm.ChatMessage(role="system", content=["New instructions"]))
If anything isn’t clear or if you’d like a hand with the implementation, please don’t hesitate to ask. I’m here to help!
Sources: web/src/components/instructions.tsx | basics/change_agent_instructions.py | examples/voice_agents/llamaindex-rag/retrieval.py | Adjusting Model Parameters | LiveKit Docs | Docs::Agents