Is it possible to update a dynamic function tool f...
# ask-ai
e
Is it possible to update a dynamic function tool from another function tool. And after it get's called we could remove it. I know the onle way to do it is to pass it to the constructor. Or calling the agent and updating it but am inside another function tool
t
Thanks for reaching out, Brian. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Absolutely, you can update a dynamic function tool from another function tool and even remove it once it has been called. This is made possible with the
update_tools()
method, which lets you modify an agent's available tools while it’s running. For instance, if you want to remove a specific tool, you can filter it out from the tool list and then use
update_tools()
like this:
Copy code
# Remove a tool named "temporary_tool" after another function has been called
remaining_tools = [tool for tool in agent.tools if get_function_info(tool).name != "temporary_tool"]
await agent.update_tools(remaining_tools)
This approach replaces the entire set of tools, so you have the flexibility to add or remove tools dynamically. You can do this during agent initialization or even at runtime, including from within other function tools. If you have any questions or need a hand with the implementation, please feel free to ask—I’m here to help! Sources: tool_calling/update_tools.py | livekit-plugins/livekit-plugins-ultravox/livekit/plugins/ultravox/realtime/... | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee... | Tool definition and use | LiveKit docs
e
But where does "agent" come from do we import it?
t
Hi there! The
agent
object is actually an instance of the
Agent
class in the LiveKit Python SDK. It represents your AI agent and gets initialized when you set up your agent in your application. You won’t need to import it directly because it’s created as part of that setup process. For example, when you’re initializing an agent, it might look something like this:
Copy code
from livekit.agents.voice.agent import Agent

agent = Agent(
    instructions="Your agent instructions",
    tools=[tool_a, tool_b],
    chat_ctx=chat_context,
    stt=stt_model,
    tts=tts_model,
    llm=llm_model
)
Once your agent is up and running, you can easily use methods like
update_tools()
to adjust its tools dynamically while your application is running. If anything feels unclear or if you’d like me to walk you through it more, just let me know—I’m here to help! Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee... | Tool definition and use | LiveKit docs
e
can we use this? since we are create a custom agent like ConciergeAgent?
t
The
update_tools()
method is designed to work smoothly with any agent that inherits from the base
Agent
class in LiveKit. Could you please confirm if your
ConciergeAgent
is a custom class you’ve created? If it is, I’d love to understand a bit more: • Does it extend
livekit.agents.Agent
or one of its subclasses? • Are you working with a Realtime LLM (like OpenAI Realtime) or a standard LLM integration? Knowing this will really help us figure out compatibility and the best next steps for you. I’m here to help! Sources: Tool definition and use | LiveKit docs | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee... | livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real...
e
Sorry can we use self? since i have an agent like class Assistant(Agent): can I call it and use self.update_tools since its an instance of agent?
t
Absolutely! Since your
Assistant
class inherits from
Agent
, you’re all set to use
self.update_tools()
right within your custom agent class. This works because
update_tools()
is a method of the
Agent
class, so your
Assistant
class naturally has access to it through inheritance. Here’s a little example of how you might call it inside your custom agent:
Copy code
class Assistant(Agent):
    async def some_method(self):
        # Update tools dynamically
        await self.update_tools(new_tools)
This way, you can dynamically update the tools your
Assistant
instance uses. If you have any more questions or need a hand with anything else, just let me know—I’m here to help!
e
Can we do this or we do not need to, update tools can do that under the hood
Copy code
# Get current tools
                current_tools = list(self.tools)

                # Remove any existing handler tool (dynamic send_template_data)
                current_tools = [t for t in current_tools if getattr(t, '__name__', None) != "handler"]

                # Add the new dynamic tool
                current_tools.append(template_tool)

                # Update the agent's tools
                await self.update_tools(current_tools)
t
Hey there! You actually don’t need to manually manage the current tools like in your code snippet. The
update_tools()
method in LiveKit takes care of replacing the entire tool set with the new list you provide. It makes sure everything stays in sync with the backend, validates the tools, and keeps only the valid ones. For instance, if you want to add or remove tools, you can simply do this:
Copy code
# Add a new tool
await self.update_tools(self.tools + [new_tool])

# Remove a tool
await self.update_tools([t for t in self.tools if t != tool_to_remove])
This way, you don’t have to worry about manually filtering or appending tools because
update_tools()
handles all that for you behind the scenes. If you want me to explain anything further, just let me know—I’m happy to help! Sources: livekit-plugins/livekit-plugins-openai/livekit/plugins/openai/realtime/real... | Tool definition and use | LiveKit docs | Agent Session Management & Turn Detection | livekit/livekit_composite | Dee...