handsome-easter-5670
07/07/2025, 5:20 PMtall-airline-16756
07/07/2025, 5:20 PMtall-airline-16756
07/07/2025, 5:21 PM@function_tool
decorator in your agent class. This allows the LLM to access these tools automatically. For example:
from livekit.agents import function_tool, Agent, RunContext
class MyAgent(Agent):
@function_tool()
async def lookup_weather(self, context: RunContext, location: str) -> dict[str, Any]:
"""Look up weather information for a given location.
Args:
location: The location to look up weather information for.
"""
return {"weather": "sunny", "temperature_f": 70}
You can also dynamically create or update tools for an agent. For instance:
1. *Create tools when the agent is created:*`agent = MyAgent(
instructions="You are a helpful assistant...",
tools=[
function_tool(
_get_course_info,
name="get_course_info",
description="Get information about a course",
)
],
)`
2. *Update tools after the agent is created:*`await agent.update_tools(
agent.tools + [function_tool(_random_number, name="random_number", description="Get a random number")]
)`
The update_tools()
method ensures that tools are updated even during an ongoing realtime session.
Sources: Tool definition and use | LiveKit Docs | GitHub::livekit::agents | livekit-agents/livekit/agents/voice/agent.py