clever-optician-10225
10/15/2025, 10:48 PMtall-airline-16756
10/15/2025, 10:48 PMtall-airline-16756
10/15/2025, 10:49 PMupdate_chat_ctx method a bit better! It can remove tool calls depending on how the exclude_invalid_function_calls parameter is set:
• If exclude_invalid_function_calls is set to True (which is the default), it will remove function calls and outputs when the tools are no longer available in the agent's tool set.
• But if you set it to False, it will keep all function calls and outputs, even if those tools aren’t present anymore.
This way, you have the flexibility to manage tool interactions in a way that best fits your needs. If you have any questions or want to explore this further, I’m here for you!
Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | plugins/google/src/beta/realtime/realtime_api.tsclever-optician-10225
10/15/2025, 10:50 PMtall-airline-16756
10/15/2025, 10:50 PMupdate_chat_ctx. Let me walk you through a simple example:
from livekit.agents import llm
# Create or modify a chat context
new_chat_ctx = llm.ChatContext()
new_chat_ctx.add_message(role="system", content="Updated system instructions")
new_chat_ctx.add_message(role="user", content="New user message")
# Update the agent's chat context
await agent.update_chat_ctx(new_chat_ctx)
# Or with custom options
await agent.update_chat_ctx(new_chat_ctx, exclude_invalid_function_calls=False)
This method takes the following parameters:
• chat_ctx: This is where you provide the new or updated chat context.
• exclude_invalid_function_calls (optional): This controls whether to exclude function calls for unavailable tools, and it defaults to True.
If anything feels unclear or if you'd like me to guide you through it step-by-step, just let me know—I'm here to help!
Sources: Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | Agents v0.x migration guide - Python | LiveKit Docs | livekit-agents/livekit/agents/voice/agent.pyclever-optician-10225
10/15/2025, 11:10 PMtall-airline-16756
10/15/2025, 11:10 PMagent.update_tools does remove function calls for tools that are no longer in the tool list within chat_ctx, but how this happens depends on the type of agent you’re working with:
• For standard LLMs: When you call agent.update_tools, it updates the tool list and also syncs the chat context by removing any function calls linked to tools that aren’t available anymore. This is done by using update_chat_ctx with exclude_invalid_function_calls=True.
• For RealtimeModel-based agents: The server takes care of keeping the tools consistent, so any invalid function calls are handled remotely, and there’s no need for local cleanup.
If anything isn’t clear or if you’d like me to walk you through this in more detail, just let me know—I’m here to help!
Sources: livekit-agents/livekit/agents/voice/agent_activity.py | Agent Session & Client Integration | livekit/livekit_composite | DeepWikiclever-optician-10225
10/15/2025, 11:12 PMtall-airline-16756
10/15/2025, 11:12 PMagent.update_tools method, but it can't be overridden to prevent the removal of tools in chat_ctx. This is actually a built-in feature designed to keep the agent's tool list and the chat context perfectly in sync.
That said, there's a friendly workaround you can try:
• First, get the current tools using agent.tools.
• Then, merge those with any new tools you want to add.
• Finally, call update_tools with this combined list to make sure nothing gets removed unintentionally.
Another neat option is to use the llm_node method, which lets you inject temporary tools just for a single inference cycle—without changing your persistent tool list or updating chat_ctx.
If you'd like, I'm here to help you step through these options or answer any questions you might have!
Sources: livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | Pipeline nodes and hooks | LiveKit Docs | Tool definition and use | LiveKit Docs | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki