Overview
Crowe BaseTool is a unified tool execution and schema management framework designed for AI-powered workflows.
It streamlines function calling, schema conversion, and tool execution across providers like OpenAI and Anthropic, with built-in validation, caching, and error handling.
Key Capabilities
Function → AI Schema
Instantly convert Python functions to standardized function-calling schemas.
Multi-Provider Schema Support
Validate and convert between OpenAI, Anthropic, and other AI provider formats.
Execution Engine
Run tools sequentially or in parallel with robust error handling and automatic retries.
Pydantic Integration
Manage, validate, and serialize Pydantic models with ease.
Auto Execution
Detect and execute tools directly from API responses.
Performance-Ready
Caching system for repeated calls to boost speed and reduce cost.
Initialization Parameters
Parameter
Type
Default
Description
verbose
bool
None
Enable detailed logs.
base_models
List[BaseModel]
None
Pydantic models to manage.
autocheck
bool
None
Enable schema and type validation.
auto_execute_tool
bool
None
Auto-run tools from responses.
tools
List[Callable]
None
Functions to register as tools.
tool_system_prompt
str
None
Custom system prompt for tools.
function_map
Dict[str, Callable]
None
Map of function names to callables.
list_of_dicts
List[Dict]
None
Pre-defined schema dictionaries.
Core Methods
Schema Conversion
func_to_dict() → Convert Python functions into AI tool schemas.
base_model_to_dict() / multi_base_models_to_dict() → Pydantic → AI schema.
from swarms.tools.base_tool import BaseTool
def greet(name: str) -> str:
"""Greet a person by name."""
return f"Hello, {name}!"
tool = BaseTool(tools=[greet])
response = '{"name": "greet", "parameters": {"name": "Alice"}}'
result = tool.execute_tool(response)
print(result) # "Hello, Alice!"
from swarms.tools.base_tool import BaseTool
from pydantic import BaseModel
class MyModel(BaseModel):
value: int
def my_function():
return "ok"
tool = BaseTool()
print(tool.detect_tool_input_type(MyModel)) # "Pydantic"
print(tool.detect_tool_input_type(my_function)) # "Function"
print(tool.detect_tool_input_type({"k": "v"})) # "Dictionary"
print(tool.detect_tool_input_type(42)) # "Unknown"
from swarms.tools.base_tool import BaseTool
def multiply(x: int, y: int) -> int:
"""Multiply two numbers."""
return x * y
tool = BaseTool(auto_execute_tool=False)
schema_or_result = tool.dynamic_run(multiply)
print(type(schema_or_result), schema_or_result) # typically a schema string
from swarms.tools.base_tool import BaseTool
def calculate_sum(a: int, b: int) -> int:
"""Calculate sum of two numbers."""
return a + b
tool = BaseTool(function_map={"calculate_sum": calculate_sum})
result = tool.execute_tool_by_name("calculate_sum", '{"a": 5, "b": 3}')
print(result) # 8
from swarms.tools.base_tool import BaseTool
def divide(x: float, y: float) -> float:
"""Divide x by y."""
return x / y
tool = BaseTool(function_map={"divide": divide})
text = '{"name": "divide", "parameters": {"x": 10, "y": 2}}'
print(tool.execute_tool_from_text(text)) # 5.0
from swarms.tools.base_tool import BaseTool
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
def subtract(a: int, b: int) -> int:
"""Subtract b from a."""
return a - b
tool = BaseTool(tools=[add, subtract])
schema = tool.convert_tool_into_openai_schema()
print(schema) # dict with 'type': 'function' entries for add/subtract
from swarms.tools.base_tool import BaseTool
def documented_func():
"""This function has documentation."""
return "ok"
def undocumented_func():
return "nope"
tool = BaseTool()
print(tool.check_func_if_have_docs(documented_func)) # True
# Depending on implementation, the next line may raise ToolDocumentationError:
# tool.check_func_if_have_docs(undocumented_func)
from swarms.tools.base_tool import BaseTool
def power(base: int, exponent: int) -> int:
"""Calculate base to the power of exponent."""
return base ** exponent
tool = BaseTool(tools=[power])
# Provide params as a dict; specify the function by name
result = tool.execute_function_with_dict({"base": 2, "exponent": 3}, "power")
print(result) # 8
from swarms.tools.base_tool import BaseTool
def add(a: int, b: int) -> int:
"""Add two numbers."""
return a + b
def multiply(a: int, b: int) -> int:
"""Multiply two numbers."""
return a * b
tool = BaseTool(tools=[add, multiply])
results = tool.execute_multiple_functions_with_dict(
[{"a": 1, "b": 2}, {"a": 3, "b": 4}],
["add", "multiply"]
)
print(results) # [3, 12]