Tools
Tools are the action capabilities that enable agents to interact with the world beyond text generation. They transform agents from conversational entities into practical actors that can read files, search the web, perform calculations, and integrate with external systems.
What are Tools?
Section titled “What are Tools?”In langcrew, tools are functions or services that agents can invoke to:
- Gather information - Search engines, databases, APIs
- Process data - Calculators, parsers, analyzers
- Take actions - File operations, email sending, API calls
- Interact with users - Input collection, approval workflows
from langcrew import Agentfrom langcrew_tools import WebSearchTool, FileWriteTool
# Agent with multiple tool capabilitiesagent = Agent( role="Research Assistant", tools=[WebSearchTool(), FileWriteTool()], goal="Research topics and create reports")Tool Architecture
Section titled “Tool Architecture”Tool Types
Section titled “Tool Types”langcrew supports multiple tool ecosystems:
1. CrewAI Tools (crewai_tools)
Section titled “1. CrewAI Tools (crewai_tools)”Pre-built tools optimized for agent workflows:
from langcrew.tools import ToolRegistry
# Access CrewAI tools via registrysearch_tool = ToolRegistry.get_tool("crewai:search_the_internet_with_serper")file_tool = ToolRegistry.get_tool("crewai:read_a_files_content")2. LangChain Tools (langchain_community)
Section titled “2. LangChain Tools (langchain_community)”Extensive ecosystem of community tools:
# LangChain community toolscalculator = ToolRegistry.get_tool("langchain:calculator")wikipedia = ToolRegistry.get_tool("langchain:wikipedia")3. Custom Tools
Section titled “3. Custom Tools”Application-specific tools you create:
from langcrew.tools.converter import tool
@tooldef custom_database_query(query: str) -> str: """Query the company database.""" # Your custom logic here return f"Database results for: {query}"4. MCP Tools (Model Context Protocol)
Section titled “4. MCP Tools (Model Context Protocol)”External services via standardized protocol:
agent = Agent( role="System Admin", mcp_servers={ "filesystem": { "transport": "stdio", "command": "python", "args": ["mcp_filesystem.py"] } })Tool Discovery
Section titled “Tool Discovery”langcrew provides automatic tool discovery:
from langcrew.tools import ToolRegistry
# List all available toolstools = ToolRegistry.list_tools()
# Search for specific toolssearch_tools = ToolRegistry.search_tools("search")file_tools = ToolRegistry.search_tools("file")Tool Integration Patterns
Section titled “Tool Integration Patterns”1. Agent-Level Tools
Section titled “1. Agent-Level Tools”Tools assigned to specific agents:
researcher = Agent( role="Researcher", tools=[WebSearchTool(), WebFetchTool()], goal="Gather comprehensive information")2. Dynamic Tool Selection
Section titled “2. Dynamic Tool Selection”Agents choose tools based on task requirements:
multi_tool_agent = Agent( role="General Assistant", tools=ToolRegistry.get_tools_by_category("productivity"), goal="Handle various productivity tasks")3. Tool Handoffs
Section titled “3. Tool Handoffs”Tools can be passed between agents in a crew:
# Researcher uses search toolsresearcher = Agent(tools=[search_tools])
# Writer inherits context but uses different toolswriter = Agent(tools=[writing_tools])Tool Security and Control
Section titled “Tool Security and Control”Human-in-the-Loop (HITL)
Section titled “Human-in-the-Loop (HITL)”Control tool execution with human oversight:
from langcrew.hitl import HITLConfig
agent = Agent( role="File Manager", tools=[FileWriteTool(), FileDeleteTool()], hitl=HITLConfig( interrupt_before_tools=["file_write", "file_delete"] ))Tool Filtering
Section titled “Tool Filtering”Restrict which tools agents can access:
# Only allow safe toolssafe_tools = ToolRegistry.get_tools_by_safety_level("safe")agent = Agent(tools=safe_tools)Tool Performance
Section titled “Tool Performance”Async Support
Section titled “Async Support”Tools support asynchronous execution:
@toolasync def async_api_call(endpoint: str) -> str: """Make async API call.""" # Async implementation return await make_request(endpoint)Caching
Section titled “Caching”Automatic result caching for expensive operations:
@tool(cache=True, cache_ttl=3600) # Cache for 1 hourdef expensive_calculation(data: str) -> str: """Perform expensive calculation.""" # Heavy computation return resultBest Practices
Section titled “Best Practices”1. Tool Selection
Section titled “1. Tool Selection”Choose tools that match agent capabilities:
# Good: Specialized tools for specialized agentsdata_scientist = Agent( role="Data Scientist", tools=[pandas_tool, matplotlib_tool, statistics_tool])
# Avoid: Unrelated tools# data_scientist = Agent(tools=[email_tool, calendar_tool]) # ❌2. Error Handling
Section titled “2. Error Handling”Tools should handle errors gracefully:
@tooldef robust_file_reader(filepath: str) -> str: """Read file with error handling.""" try: with open(filepath, 'r') as f: return f.read() except FileNotFoundError: return f"Error: File {filepath} not found" except PermissionError: return f"Error: Permission denied for {filepath}"3. Clear Descriptions
Section titled “3. Clear Descriptions”Provide clear tool descriptions for agent understanding:
@tooldef calculate_roi(investment: float, return_amount: float) -> float: """Calculate Return on Investment (ROI) percentage.
Args: investment: Initial investment amount in dollars return_amount: Final return amount in dollars
Returns: ROI percentage (e.g., 25.5 for 25.5% ROI) """ return ((return_amount - investment) / investment) * 100Integration with Other Components
Section titled “Integration with Other Components”Tools integrate seamlessly with all langcrew components: