Using Tools
What are Tools?
Section titled “What are Tools?”Tools give your agents the ability to take real actions - like calculating numbers, reading files, scraping websites, or calling APIs. LangCrew’s tool system automatically finds and provides access to tools from multiple sources.
Quick example:
from langcrew.tools import ToolRegistry
# Get a tool and use itcalculator = ToolRegistry.get_tool("calculator")result = calculator.run("2 + 2") # "4"Getting Tools: Three Ways
Section titled “Getting Tools: Three Ways”1. Install Tool Packages (Recommended)
Section titled “1. Install Tool Packages (Recommended)”Best for: Most users - gets you hundreds of ready-to-use tools
pip install crewai_tools langchain_communityPopular tools you’ll get:
from langcrew.tools import ToolRegistry
# CrewAI tools (from crewai_tools package)file_read = ToolRegistry.get_tool("crewai:read_a_files_content")scraper = ToolRegistry.get_tool("crewai:read_website_content")search = ToolRegistry.get_tool("crewai:search_the_internet_with_serper")# ... many more CrewAI tools available
# LangChain Community tools (from langchain_community package)# Note: These require additional dependencieswikipedia = ToolRegistry.get_tool("langchain:wikipedia")calculator = ToolRegistry.get_tool("langchain:calculator")# ... many more LangChain tools availableImportant: Tool names use provider prefixes and snake_case format:
crewai:prefix for CrewAI tools (fromcrewai_tools) - use snake_case formatlangchain:prefix for LangChain community tools (fromlangchain_community.tools) - use snake_case formatlangcrew:prefix for LangCrew-specific tools (fromlangcrew_tools)- No prefix for custom tools in your project
Note: Always use snake_case format (lowercase with underscores) for tool names, even if the original tool uses descriptive names with spaces.
To see all available tools:
python -c "from langcrew.tools import ToolRegistry; print(ToolRegistry.list_tools())"Note: External tools are loaded on-demand (lazy loading) - they only load when first requested to avoid import errors from missing dependencies.
2. Create Custom Tools
Section titled “2. Create Custom Tools”Best for: Business-specific logic or unique workflows
Create a tools/ directory in your project:
from langchain_core.tools import BaseTool
class SalesReportTool(BaseTool): name = "sales_report" description = "Generate sales reports"
def _run(self, period: str = "monthly") -> str: # Your business logic here return f"Sales for {period}: $50,000"Use it immediately:
report_tool = ToolRegistry.get_tool("sales_report")result = report_tool.run("quarterly")3. Manual Registration
Section titled “3. Manual Registration”Best for: Advanced users who need to override existing tools
from langcrew.tools import ToolRegistry
# Register your own versionToolRegistry.register("calculator", MyEnhancedCalculator())
# Now your version is usedcalc = ToolRegistry.get_tool("calculator")Using Tools with Agents
Section titled “Using Tools with Agents”Here’s a complete example showing tools in action:
from langcrew import Agent, Crewfrom langcrew.tools import ToolRegistry
# Create an agent with toolsresearcher = Agent( role="Research Analyst", goal="Find information on any topic", backstory="Expert at finding reliable information", tools=[ ToolRegistry.get_tool("crewai:search_the_internet_with_serper"), ToolRegistry.get_tool("crewai:read_website_content"), ToolRegistry.get_tool("crewai:read_a_files_content") ])
# Use in a crewcrew = Crew(agents=[researcher])result = crew.kickoff(inputs={ "topic": "renewable energy trends"})Common Issues
Section titled “Common Issues””Tool not found” Error
Section titled “”Tool not found” Error”Step 1: Install the required tool packages
pip install crewai_tools langchain_communityStep 2: Use the correct provider prefix
from langcrew.tools import ToolRegistry
# External tools need provider prefixes (use snake_case)tool = ToolRegistry.get_tool("crewai:read_a_files_content") # ✅tool = ToolRegistry.get_tool("langchain:wikipedia") # ✅
# Custom tools don't need prefixestool = ToolRegistry.get_tool("sales_report") # ✅Step 3: Debug with list_tools() if needed
from langcrew.tools import ToolRegistry
# See all available tools (triggers lazy loading)available_tools = ToolRegistry.list_tools()print("Available tools:")for tool in available_tools: print(f' "{tool}"')
# Try accessing a specific tool to see error detailstry: tool = ToolRegistry.get_tool("crewai:read_website_content") print(f"Success: {tool.name}")except ValueError as e: print(f"Error: {e}")Missing Dependencies Error
Section titled “Missing Dependencies Error”Some LangChain tools need additional packages:
# For web search toolspip install duckduckgo-search
# For Wikipedia toolpip install wikipedia
# For calculatorpip install numexprCreating Custom Tools Not Working
Section titled “Creating Custom Tools Not Working”Make sure your tools directory structure is correct:
your_project/├── tools/│ ├── __init__.py # Can be empty│ └── my_tools.py # Your tool classes here└── main.pyYour tool class must:
- Inherit from
BaseTool - Have a
nameattribute - Implement the
_runmethod
Pro tip: Start with crewai_tools for common tasks, then create custom tools for your specific business needs.