Skip to content

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.

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 Agent
from langcrew_tools import WebSearchTool, FileWriteTool
# Agent with multiple tool capabilities
agent = Agent(
role="Research Assistant",
tools=[WebSearchTool(), FileWriteTool()],
goal="Research topics and create reports"
)

langcrew supports multiple tool ecosystems:

Pre-built tools optimized for agent workflows:

from langcrew.tools import ToolRegistry
# Access CrewAI tools via registry
search_tool = ToolRegistry.get_tool("crewai:search_the_internet_with_serper")
file_tool = ToolRegistry.get_tool("crewai:read_a_files_content")

Extensive ecosystem of community tools:

# LangChain community tools
calculator = ToolRegistry.get_tool("langchain:calculator")
wikipedia = ToolRegistry.get_tool("langchain:wikipedia")

Application-specific tools you create:

from langcrew.tools.converter import tool
@tool
def custom_database_query(query: str) -> str:
"""Query the company database."""
# Your custom logic here
return f"Database results for: {query}"

External services via standardized protocol:

agent = Agent(
role="System Admin",
mcp_servers={
"filesystem": {
"transport": "stdio",
"command": "python",
"args": ["mcp_filesystem.py"]
}
}
)

langcrew provides automatic tool discovery:

from langcrew.tools import ToolRegistry
# List all available tools
tools = ToolRegistry.list_tools()
# Search for specific tools
search_tools = ToolRegistry.search_tools("search")
file_tools = ToolRegistry.search_tools("file")

Tools assigned to specific agents:

researcher = Agent(
role="Researcher",
tools=[WebSearchTool(), WebFetchTool()],
goal="Gather comprehensive information"
)

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"
)

Tools can be passed between agents in a crew:

# Researcher uses search tools
researcher = Agent(tools=[search_tools])
# Writer inherits context but uses different tools
writer = Agent(tools=[writing_tools])

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"]
)
)

Restrict which tools agents can access:

# Only allow safe tools
safe_tools = ToolRegistry.get_tools_by_safety_level("safe")
agent = Agent(tools=safe_tools)

Tools support asynchronous execution:

@tool
async def async_api_call(endpoint: str) -> str:
"""Make async API call."""
# Async implementation
return await make_request(endpoint)

Automatic result caching for expensive operations:

@tool(cache=True, cache_ttl=3600) # Cache for 1 hour
def expensive_calculation(data: str) -> str:
"""Perform expensive calculation."""
# Heavy computation
return result

Choose tools that match agent capabilities:

# Good: Specialized tools for specialized agents
data_scientist = Agent(
role="Data Scientist",
tools=[pandas_tool, matplotlib_tool, statistics_tool]
)
# Avoid: Unrelated tools
# data_scientist = Agent(tools=[email_tool, calendar_tool]) # ❌

Tools should handle errors gracefully:

@tool
def 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}"

Provide clear tool descriptions for agent understanding:

@tool
def 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) * 100

Tools integrate seamlessly with all langcrew components:

  • Agents: Primary tool users and executors
  • Tasks: Tasks define which tools are needed
  • Crews: Coordinate tool usage across multiple agents
  • Memory: Remember tool usage patterns and results
  • HITL: Control tool execution with human oversight