Crowe Basetool

Crowe BaseTool

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.

    • convert_schema_between_providers() → Cross-provider schema translation.

  • Execution

    • execute_tool() → Run tool with input validation.

    • dynamic_run() → Auto-detect input type and execute.

    • execute_tool_from_text() → Run tools from JSON strings.

  • Validation & Inspection

    • check_func_if_have_docs() → Ensure functions are documented.

    • check_func_if_have_type_hints() → Verify type hints.

    • validate_function_schema() → Confirm schema compliance.

  • Automation

    • execute_function_calls_from_api_response() → Parse and run API function calls.

    • detect_api_response_format() → Identify API provider response type.

BaseTool — Method Highlights


func_to_dict

Convert any Python function into an OpenAI function calling schema. Useful for exposing local functions directly to an AI model.


load_params_from_func_for_pybasemodel

Automatically generate Pydantic model parameters from a function for type-safe input validation.


base_model_to_dict

Convert a Pydantic BaseModel to an AI-callable schema.


multi_base_models_to_dict

Merge multiple Pydantic models into a single schema.


dict_to_openai_schema_str

Convert a schema dictionary into a string for OpenAI function calling.


multi_dict_to_openai_schema_str

Combine multiple schema dictionaries into one string.


execute_tool

Execute a tool based on a JSON response string (name + parameters).


detect_tool_input_type

Detect the input category to choose the right processing path: "Pydantic" | "Dictionary" | "Function" | "Unknown".


dynamic_run

Auto-detect the input type (Pydantic class, dict schema, or function) and do the right thing (e.g., return schema string or execute).


execute_tool_by_name

Find a registered tool by name and execute it with JSON parameters.


execute_tool_from_text

Parse a JSON tool-call string ({"name": "...","parameters": {...}}) and execute it.


check_str_for_functions_valid

Validate if a string is JSON and the function name exists in the function map.


convert_funcs_into_tools

Convert all functions in tools into internal OpenAI-style tool format, populating function_map.


convert_tool_into_openai_schema

Export all registered tools as a combined OpenAI function-calling schema.


check_func_if_have_docs

Ensure a function has a docstring. (Implementations may return True or raise a specific error if missing.)


check_func_if_have_type_hints

Ensure a function has proper type hints. (Implementations may return True or raise a specific error if missing.)


find_function_name

Find a function by name in the registered tool set.


function_to_dict

Convert a function into a dictionary representation (name, docstring, params).


multiple_functions_to_dict

Convert a list of functions into a list of dict representations.

execute_function_with_dict

Execute a function using a dictionary of parameters. Useful when arguments are produced by a model or parsed from JSON.


execute_multiple_functions_with_dict

Execute multiple functions from a list of parameter dictionaries (optionally specify names if auto-detection isn’t used).


validate_function_schema

Validate a function schema for a target provider ("openai", "anthropic", "generic", or "auto").


get_schema_provider_format

Detect the provider format of a given schema dict.


convert_schema_between_providers

Convert a function schema between providers (e.g., OpenAI → Anthropic).


execute_function_calls_from_api_response

Auto-detect and execute function calls embedded in OpenAI/Anthropic responses. Can run sequentially or in parallel.


detect_api_response_format

Detect whether a response looks like OpenAI, Anthropic, generic, or unknown.


Exception Classes

Custom exceptions for precise error handling:

  • BaseToolError — Base class for all BaseTool-related errors

  • ToolValidationError — Schema/tool validation failed

  • ToolExecutionError — Tool execution failed

  • ToolNotFoundError — Requested tool not found

  • FunctionSchemaError — Failed during schema conversion

  • ToolDocumentationError — Missing/invalid function docstring

  • ToolTypeHintError — Missing/invalid type hints

Example handling:


Usage Tips

  • Provide docstrings and type hints for every function to enable clean schemas and validation.

  • Use verbose=True during development to surface detailed logs.

  • Pre-fill function_map for direct name-based execution.

  • Validate schemas before sending them to different providers.

  • Use parallel execution for high-throughput batches.

  • Catch specific BaseTool exceptions for robust error handling.

Last updated