how can i pass functions of class as tool manually...
# ask-ai
v
how can i pass functions of class as tool manually to the llm without using @function_tool decorator
t
Thanks for reaching out, Ravi. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'd love to help you pass functions of a class as tools manually to the LLM without using the
@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:
Copy code
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:
Copy code
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