echoing-lamp-18687
12/15/2025, 12:08 PMtall-airline-16756
12/15/2025, 12:08 PMtall-airline-16756
12/15/2025, 12:08 PM@function_tool() and put the tool's instructions in that method's docstring. The docstring should describe the tool's purpose, when to use it, details for each argument, constraints/valid values, and the expected return format. The LLM uses that docstring to decide when and how to call the tool.
Example:
from livekit.agents import Agent, function_tool
from livekit.agents.context import RunContext
class MyAgent(Agent):
def __init__(self):
super().__init__(instructions="You are a helpful assistant.")
@function_tool()
async def get_weather(self, context: RunContext, location: str) -> dict[str, Any]:
"""
Look up weather for a location.
Args:
location: city and country (e.g., "New York, US"). Must be non-empty.
Returns:
Dict with keys "weather" and "temperature_f".
"""
# implementation...
return {"weather": "sunny", "temperature_f": 70}
If you want, tell me what tool you’re building and I can help write a clear docstring (instructions) that will guide the agent.
Sources: Tool definition and use | LiveKit docs