Improve tooling docs

This commit is contained in:
Brandon Hancock
2024-10-28 09:40:56 -05:00
parent f29f4abdd7
commit 04bcfa6e2d
5 changed files with 36 additions and 1 deletions

View File

@@ -20,14 +20,21 @@ pip install 'crewai[tools]'
### Subclassing `BaseTool` ### Subclassing `BaseTool`
To create a personalized tool, inherit from `BaseTool` and define the necessary attributes and the `_run` method. To create a personalized tool, inherit from `BaseTool` and define the necessary attributes, including the `args_schema` for input validation, and the `_run` method.
```python Code ```python Code
from typing import Type
from crewai_tools import BaseTool 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): class MyCustomTool(BaseTool):
name: str = "Name of my tool" name: str = "Name of my tool"
description: str = "What this tool does. It's vital for effective utilization." description: str = "What this tool does. It's vital for effective utilization."
args_schema: Type[BaseModel] = MyToolInput
def _run(self, argument: str) -> str: def _run(self, argument: str) -> str:
# Your tool's logic here # Your tool's logic here

View File

@@ -1,11 +1,17 @@
from typing import Type
from crewai_tools import BaseTool from crewai_tools import BaseTool
from pydantic import BaseModel, Field
class MyCustomToolInput(BaseModel):
"""Input schema for MyCustomTool."""
argument: str = Field(..., description="Description of the argument.")
class MyCustomTool(BaseTool): class MyCustomTool(BaseTool):
name: str = "Name of my tool" name: str = "Name of my tool"
description: str = ( description: str = (
"Clear description for what this tool is useful for, you agent will need this information to use it." "Clear description for what this tool is useful for, you agent will need this information to use it."
) )
args_schema: Type[BaseModel] = MyCustomToolInput
def _run(self, argument: str) -> str: def _run(self, argument: str) -> str:
# Implementation goes here # Implementation goes here

View File

@@ -1,4 +1,13 @@
from typing import Type
from crewai_tools import BaseTool from crewai_tools import BaseTool
from pydantic import BaseModel, Field
class MyCustomToolInput(BaseModel):
"""Input schema for MyCustomTool."""
argument: str = Field(..., description="Description of the argument.")
class MyCustomTool(BaseTool): class MyCustomTool(BaseTool):
@@ -6,6 +15,7 @@ class MyCustomTool(BaseTool):
description: str = ( description: str = (
"Clear description for what this tool is useful for, you agent will need this information to use it." "Clear description for what this tool is useful for, you agent will need this information to use it."
) )
args_schema: Type[BaseModel] = MyCustomToolInput
def _run(self, argument: str) -> str: def _run(self, argument: str) -> str:
# Implementation goes here # Implementation goes here

View File

@@ -1,11 +1,17 @@
from typing import Type
from crewai_tools import BaseTool from crewai_tools import BaseTool
from pydantic import BaseModel, Field
class MyCustomToolInput(BaseModel):
"""Input schema for MyCustomTool."""
argument: str = Field(..., description="Description of the argument.")
class MyCustomTool(BaseTool): class MyCustomTool(BaseTool):
name: str = "Name of my tool" name: str = "Name of my tool"
description: str = ( description: str = (
"Clear description for what this tool is useful for, you agent will need this information to use it." "Clear description for what this tool is useful for, you agent will need this information to use it."
) )
args_schema: Type[BaseModel] = MyCustomToolInput
def _run(self, argument: str) -> str: def _run(self, argument: str) -> str:
# Implementation goes here # Implementation goes here

View File

@@ -1,11 +1,17 @@
from typing import Type
from crewai_tools import BaseTool from crewai_tools import BaseTool
from pydantic import BaseModel, Field
class MyCustomToolInput(BaseModel):
"""Input schema for MyCustomTool."""
argument: str = Field(..., description="Description of the argument.")
class MyCustomTool(BaseTool): class MyCustomTool(BaseTool):
name: str = "Name of my tool" name: str = "Name of my tool"
description: str = ( description: str = (
"Clear description for what this tool is useful for, you agent will need this information to use it." "Clear description for what this tool is useful for, you agent will need this information to use it."
) )
args_schema: Type[BaseModel] = MyCustomToolInput
def _run(self, argument: str) -> str: def _run(self, argument: str) -> str:
# Implementation goes here # Implementation goes here