creamy-judge-56458
07/24/2025, 2:40 PMtall-airline-16756
07/24/2025, 2:40 PMtall-airline-16756
07/24/2025, 2:41 PMBaseAgent class during initialization, you can use one of the following methods:
1. Override Tools in the ConstructorYou can filter out unwanted tools by overriding the tools parameter in your agent's constructor:
from livekit.agents import Agent, function_tool
from livekit.agents.llm import find_function_tools
class BaseAgent(Agent):
def __init__(self, **kwargs):
all_tools = find_function_tools(self)
disabled_tool_names = {"unwanted_tool", "another_disabled_tool"}
filtered_tools = [
tool for tool in all_tools
if getattr(tool, '__name__', '') not in disabled_tool_names
]
super().__init__(tools=filtered_tools, **kwargs)
@function_tool()
async def useful_tool(self, context, param: str):
return "result"
@function_tool()
async def unwanted_tool(self, context, param: str):
return "disabled"
2. Conditional Tool RegistrationYou can register tools conditionally based on configuration:
class BaseAgent(Agent):
def __init__(self, disabled_tools=None, **kwargs):
disabled_tools = disabled_tools or set()
tools = []
if "weather_tool" not in disabled_tools:
tools.append(self.weather_tool)
if "calendar_tool" not in disabled_tools:
tools.append(self.calendar_tool)
super().__init__(tools=tools, **kwargs)
@function_tool()
async def weather_tool(self, context, location: str):
return {"weather": "sunny"}
@function_tool()
async def calendar_tool(self, context, date: str):
return {"events": []}
3. Use update_tools After InitializationYou can modify the tool set dynamically after the agent is created:
# Create agent normally
agent = BaseAgent()
# Filter out unwanted tools
current_tools = agent.tools
disabled_tool_names = {"unwanted_tool"}
filtered_tools = [
tool for tool in current_tools
if getattr(tool, '__name__', '') not in disabled_tool_names
]
# Update agent with filtered tools
await agent.update_tools(filtered_tools)
4. Tool Name FilteringFor more advanced filtering, you can check tool names dynamically:
from livekit.agents.llm import is_function_tool, get_function_info
class BaseAgent(Agent):
def __init__(self, disabled_tools=None, **kwargs):
disabled_tools = disabled_tools or set()
all_tools = find_function_tools(self)
filtered_tools = [
tool for tool in all_tools
if get_function_info(tool).name not in disabled_tools
]
super().__init__(tools=filtered_tools, **kwargs)
Choose the method that best fits your use case. Constructor filtering is ideal for permanent disabling, while update_tools allows runtime control.
Sources: Tool definition and use | LiveKit Docs | livekit-agents/livekit/agents/llm/tool_context.pyfew-photographer-2299
09/09/2025, 2:07 PMtall-airline-16756
09/09/2025, 2:07 PMfind_function_tools might not be available in your current LiveKit setup. This function is usually used to automatically discover tools in an agent class. If it’s missing, no worries—you can manually define the tools instead of relying on auto-discovery. Here’s a simple example to guide you:
from livekit.agents import Agent, function_tool
class BaseAgent(Agent):
def __init__(self, **kwargs):
# Manually list the tools you want to include
tools = [
self.useful_tool,
# Add other tools here
]
super().__init__(tools=tools, **kwargs)
@function_tool()
async def useful_tool(self, context, param: str):
return "result"
If auto-discovery is something you really want to use, it might help to check if your LiveKit version supports it or if there are any updates available. Please feel free to reach out if you’d like more help—I’m here to support you!