does update_tools remove the previous tool-calls f...
# ask-ai
c
does update_tools remove the previous tool-calls from the chat_ctx
t
Thanks for reaching out, dexter. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks for your question! The
update_tools
method doesn’t directly remove previous tool calls from the chat context, but its behavior varies depending on the type of LLM you’re working with: • Standard LLMs: When you call
update_tools
, it updates the tool list and triggers a context update. If
exclude_invalid_function_calls=True
(which is the default), any tool calls referring to tools no longer active are automatically excluded. This helps keep things tidy! • Realtime LLMs: Here, the server takes care of managing the session state and validating tools. While
update_tools
ensures only valid tools remain on your side, removing outdated tool calls from the chat history usually happens server-side or during context synchronization. If you want to have explicit control over the chat context and clear out old tool call entries, you can use
update_chat_ctx()
with
exclude_invalid_function_calls=True
. This gives you a bit more hands-on management. Sources: examples/voice_agents/restaurant_agent.py | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki
c
i want to keep the previous tool-calls, for example lets say i have tool-call called, update_name, and then we update_tools and update_name isn't avalaible anymore. i want chat_ctx to still have the tool-call we made to update_name
t
I understand you'd like to keep previous tool calls in the chat context after using
update_tools
. No worries—there are a few ways you can manage this smoothly: • Manual Chat Context Management: Before you call
update_tools
, try copying the current chat context. Then, after updating your tools, you can bring back those previous tool calls by using
update_chat_ctx()
with
exclude_invalid_function_calls=False
. This helps keep things consistent. • Using `exclude_invalid_function_calls=False`: When updating the chat context, setting
exclude_invalid_function_calls=False
allows you to retain function calls even for tools that might no longer be available. It’s a handy way to preserve history. • Agent Handoff Pattern: Another approach is to copy and merge chat contexts carefully, ensuring that function calls from earlier tools stick around without creating duplicates. These options should help you maintain your chat history with previous tool calls, even if some tools aren’t active anymore. If you'd like, I’m happy to walk you through the details of any of these methods—just let me know! Sources: examples/voice_agents/restaurant_agent.py
c
what happens if the llm hallucinates and calls a tool-call that doesn't exist anymore?
t
I completely understand how tricky it can be when the LLM hallucinates and tries to call a tool that no longer exists. Don’t worry—our system is designed to handle this smoothly and keep things running without a hitch. Here’s how it works: • It logs an "unknown AI function" message and simply skips over the invalid tool call. • The function call returns
None
, so it won’t interfere with your workflow. • If the hallucinated tool call produces output without a matching function, it’s gently flagged with a warning and ignored to keep your data consistent. This way, any invalid tool calls won’t disrupt your agent’s operation. If you’d like, I’m here to help you set up monitoring for logs or alerts to catch these events early. Just let me know! Sources: livekit-agents/livekit/agents/llm/mcp.py | agents/src/voice/generation.ts | Docs::Agents
c
how do i override the update_tools so that when it update_chat_ctx it uses the exclude
t
Thanks for reaching out! I understand you're looking to manage the
exclude_invalid_function_calls
parameter, which isn't directly adjustable through the
update_tools
method. But no worries, you can achieve what you need by following these steps: 1. First, use
update_tools
to update your tools as usual. 2. Then, manually update the chat context with
update_chat_ctx
, setting
exclude_invalid_function_calls=False
. This way, you’ll keep function calls even for tools that are no longer available. Currently, there isn’t a built-in option to override
update_tools
to disable excluding invalid function calls directly. If you’d like, I’m here to help you implement this approach step-by-step—just let me know! Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki