victorious-monitor-50234
10/13/2025, 4:01 PMtall-airline-16756
10/13/2025, 4:01 PMtall-airline-16756
10/13/2025, 4:02 PM@function_tool decorator. You can achieve this easily by using the function_tool() function directly. Here’s a friendly step-by-step guide for you:
1. Define the class method: Start by creating an async method in your class that holds the logic you want to turn into a tool. For example: class MyAgent(Agent):
async def my_class_method(self, param: str) -> str:
"""This method does something useful."""
return f"Processed: {param}"
2. Wrap the method using `function_tool()`: Next, wrap your method with function_tool(), giving it a clear name and description: tool = function_tool(
func=my_instance.my_class_method,
name="my_tool_name",
description="A description of what this tool does."
)
3. Pass the tool to the agent: When you create your agent, just include this tool in the tools list like so: agent = MyAgent(tools=[tool])
4. Update tools dynamically (optional): If you ever need to add tools on the fly, you can do that with `agent.update_tools()`: await agent.update_tools([tool])
Just a quick tip: make sure your method is bound to an instance when wrapping instance methods. For class-level methods, you can use @classmethod or create an instance of the class as needed. If anything feels unclear or you’d like some more examples, please don’t hesitate to ask—I’m here to help!
Sources: Tool definition and use | LiveKit Docs | basics/tool_calling.py | livekit-agents/livekit/agents/voice/generation.py | mcp_client/agent_tools.py