mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-07 15:18:29 +00:00
* docs: Fix major memory system documentation issues - Remove misleading deprecation warnings, fix confusing comments, clearly separate three memory approaches, provide accurate examples that match implementation * fix: Correct broken image paths in README - Update crewai_logo.png and asset.png paths to point to docs/images/ directory instead of docs/ directly * docs: Add system prompt transparency and customization guide - Add 'Understanding Default System Instructions' section to address black-box concerns - Document what CrewAI automatically injects into prompts - Provide code examples to inspect complete system prompts - Show 3 methods to override default instructions - Include observability integration examples with Langfuse - Add best practices for production prompt management * docs: Fix implementation accuracy issues in memory documentation - Fix Ollama embedding URL parameter and remove unsupported Cohere input_type parameter * docs: Reference observability docs instead of showing specific tool examples * docs: Reorganize knowledge documentation for better developer experience - Move quickstart examples right after overview for immediate hands-on experience - Create logical learning progression: basics → configuration → advanced → troubleshooting - Add comprehensive agent vs crew knowledge guide with working examples - Consolidate debugging and troubleshooting in dedicated section - Organize best practices by topic in accordion format - Improve content flow from simple concepts to advanced features - Ensure all examples are grounded in actual codebase implementation * docs: enhance custom LLM documentation with comprehensive examples and accurate imports * docs: reorganize observability tools into dedicated section with comprehensive overview and improved navigation * docs: rename how-to section to learn and add comprehensive overview page * docs: finalize documentation reorganization and update navigation labels * docs: enhance README with comprehensive badges, navigation links, and getting started video
70 lines
2.6 KiB
Plaintext
70 lines
2.6 KiB
Plaintext
---
|
|
title: Create Custom Tools
|
|
description: Comprehensive guide on crafting, using, and managing custom tools within the CrewAI framework, including new functionalities and error handling.
|
|
icon: hammer
|
|
---
|
|
|
|
## Creating and Utilizing Tools in CrewAI
|
|
|
|
This guide provides detailed instructions on creating custom tools for the CrewAI framework and how to efficiently manage and utilize these tools,
|
|
incorporating the latest functionalities such as tool delegation, error handling, and dynamic tool calling. It also highlights the importance of collaboration tools,
|
|
enabling agents to perform a wide range of actions.
|
|
|
|
### Subclassing `BaseTool`
|
|
|
|
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
|
|
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"
|
|
```
|
|
|
|
### Using the `tool` Decorator
|
|
|
|
Alternatively, you can use the tool decorator `@tool`. This approach allows you to define the tool's attributes and functionality directly within a function,
|
|
offering a concise and efficient way to create specialized tools tailored to your needs.
|
|
|
|
```python Code
|
|
from crewai.tools import tool
|
|
|
|
@tool("Tool Name")
|
|
def my_simple_tool(question: str) -> str:
|
|
"""Tool description for clarity."""
|
|
# Tool logic here
|
|
return "Tool output"
|
|
```
|
|
|
|
### Defining a Cache Function for the Tool
|
|
|
|
To optimize tool performance with caching, define custom caching strategies using the `cache_function` attribute.
|
|
|
|
```python Code
|
|
@tool("Tool with Caching")
|
|
def cached_tool(argument: str) -> str:
|
|
"""Tool functionality description."""
|
|
return "Cacheable result"
|
|
|
|
def my_cache_strategy(arguments: dict, result: str) -> bool:
|
|
# Define custom caching logic
|
|
return True if some_condition else False
|
|
|
|
cached_tool.cache_function = my_cache_strategy
|
|
```
|
|
|
|
By adhering to these guidelines and incorporating new functionalities and collaboration tools into your tool creation and management processes,
|
|
you can leverage the full capabilities of the CrewAI framework, enhancing both the development experience and the efficiency of your AI agents.
|