Can a Python class object be used for a custom tool?


I’m working on a class object that interacts with Google’s Places API, allowing my agents to retrieve up-to-date information for their tasks. However, there’s currently no documentation for this setup. Would it be better to break down the functions into separate tools ?

@Jorge_Rocha Actually, one of the two ways of setting your custom tool is by subclassing the BaseTool class. See the docs.

Here’s an example from the docs:

from typing import Type
from crewai.tools import BaseTool
from pydantic import BaseModel, Field

class MyToolInput(BaseModel):
    """Input schema for MyCustomTool."""
    argument: str = Field(..., description="Description of the argument.")

class MyCustomTool(BaseTool):
    name: str = "Name of my tool"
    description: str = "What this tool does. It's vital for effective utilization."
    args_schema: Type[BaseModel] = MyToolInput

    def _run(self, argument: str) -> str:
        # Your tool's logic here
        return "Tool's result"