mirascope.core.base.tool
Module tool
This module defines the base class for tools used in LLM calls.
Usage
Class ToolConfig
A base class for tool configurations.
Bases:
TypedDictClass GenerateJsonSchemaNoTitles
Bases:
GenerateJsonSchemaFunction generate
Parameters
| Name | Type | Description |
|---|---|---|
| self | Any | - |
| schema | CoreSchema | - |
| mode= 'validation' | JsonSchemaMode | - |
Returns
| Type | Description |
|---|---|
| JsonSchemaValue | - |
Class BaseTool
A class for defining tools for LLM calls.
Example:
from mirascope.core import BaseTool
from pydantic import Field
class FormatBook(BaseTool):
"""Returns a nicely formatted book recommendation."""
title: str = Field(..., description="The title of the book.")
author: str = Field(..., description="The author of the book.")
def call(self) -> str:
return f"{self.title} by {self.author}"Bases: BaseModel, ABC
Attributes
| Name | Type | Description |
|---|---|---|
| tool_config | ToolConfig | - |
| model_config | ConfigDict(arbitrary_types_allowed=True) | - |
| delta | SkipJsonSchema[str | None] | - |
| args | dict[str, Any] | The arguments of the tool as a dictionary. |
Function call
The method to call the tool.
Returns
| Type | Description |
|---|---|
| Any | - |
Function type_from_fn
Returns this tool type converted from a function.
Parameters
| Name | Type | Description |
|---|---|---|
| cls | type[_BaseToolT] | - |
| fn | Callable | The function to convert into this tool type. |
Returns
| Type | Description |
|---|---|
| type[_BaseToolT] | - |
Function type_from_base_model_type
Returns this tool type converted from a given base tool type.
Parameters
| Name | Type | Description |
|---|---|---|
| cls | type[_BaseToolT] | - |
| tool_type | type[BaseModel] | The tool type to convert into this tool type. This can be a custom `BaseTool` or `BaseModel` definition. |
Returns
| Type | Description |
|---|---|
| type[_BaseToolT] | - |
Function type_from_base_type
Returns this tool type converted from a base type.
Parameters
| Name | Type | Description |
|---|---|---|
| cls | type[_BaseToolT] | - |
| base_type | type[_utils.BaseType] | The base type (e.g. `int`) to convert into this tool type. |
Returns
| Type | Description |
|---|---|
| type[_BaseToolT] | - |
Function tool_schema
Parameters
| Name | Type | Description |
|---|---|---|
| cls | Any | - |
Returns
| Type | Description |
|---|---|
| Any | - |
Function model_json_schema
Returns the generated JSON schema for the class.
Parameters
Function warn_for_unsupported_configurations
Warns when a specific provider does not support provided config options.
Parameters
| Name | Type | Description |
|---|---|---|
| cls | Any | - |
Returns
| Type | Description |
|---|---|
| None | - |