creamy-match-85520
08/25/2025, 4:32 AMtall-airline-16756
08/25/2025, 4:32 AMtall-airline-16756
08/25/2025, 4:32 AM@function_tool decorator: You can define functions right inside an Agent class and simply decorate them with @function_tool. These functions then become automatically available for the LLM to call when it makes sense.
• Using llm.FunctionContext with `@llm.ai_callable`: Another way is to create a class that inherits from llm.FunctionContext, and mark its methods with @llm.ai_callable(). This helps you set up well-structured functions with clear, typed, and described parameters.
Using these methods gives you more reliability, better type safety, and smoother integration compared to trying to squeeze function logic or triggers directly into the prompt. Hope this helps!
Sources: examples/drive-thru/test_agent.py | Function calling with Voice Agents | LiveKit Docs | Function calling with Voice Agents | LiveKit Docscreamy-match-85520
08/25/2025, 4:33 AMtall-airline-16756
08/25/2025, 4:34 AM@function_tool or @llm.ai_callable decorators, giving each function clear names and descriptions really helps the LLM get what each one does. That way, it can choose the right function to match what you want.
Sometimes, more than one function might seem like a good fit. In those cases, the LLM uses its understanding of your input to pick the best one. So, taking a little extra time to define and describe your functions well makes everything run smoother and more accurately.creamy-match-85520
08/25/2025, 4:34 AMtall-airline-16756
08/25/2025, 4:34 AM@function_tool
async def get_weather(self, location: str) -> str:
"""
Called when the user asks about the weather.
Args:
location: The location to get the weather for
"""
return f"The weather in {location} is sunny today."
• Specifying the description directly: You can also pass a description parameter right in the @function_tool decorator. Like this:
@function_tool(description="Retrieves weather information for a specified location")
async def get_weather(self, location: str) -> str:
return f"The weather in {location} is sunny today."
And if you want even more control, you can use raw_schema to manually define the function schema — including the name, description, and parameters.
Adding clear, detailed descriptions really helps the LLM understand what your function does and pick it at the right time based on what the user needs.
Sources: Agents 0.x migration guide | LiveKit Docs | Agents v0.x migration guide | LiveKit Docs | Tool definition and use | LiveKit Docs | Tool definition and use | LiveKit Docs | livekit-plugins/livekit-plugins-google/livekit/plugins/google/utils.py