mirascope.core.base.tool | Mirascope
MirascopeLilypad

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:

TypedDict

Class GenerateJsonSchemaNoTitles

Bases:

GenerateJsonSchema

Function generate

Parameters

NameTypeDescription
selfAny-
schemaCoreSchema-
mode= 'validation'JsonSchemaMode-

Returns

TypeDescription
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

NameTypeDescription
tool_configToolConfig-
model_configConfigDict(arbitrary_types_allowed=True)-
deltaSkipJsonSchema[str | None]-
argsdict[str, Any]The arguments of the tool as a dictionary.

Function call

The method to call the tool.

Parameters

NameTypeDescription
selfAny-
args= ()Any-
kwargs= {}Any-

Returns

TypeDescription
Any-

Function type_from_fn

Returns this tool type converted from a function.

Parameters

NameTypeDescription
clstype[_BaseToolT]-
fnCallableThe function to convert into this tool type.

Returns

TypeDescription
type[_BaseToolT]-

Function type_from_base_model_type

Returns this tool type converted from a given base tool type.

Parameters

NameTypeDescription
clstype[_BaseToolT]-
tool_typetype[BaseModel]The tool type to convert into this tool type. This can be a custom `BaseTool` or `BaseModel` definition.

Returns

TypeDescription
type[_BaseToolT]-

Function type_from_base_type

Returns this tool type converted from a base type.

Parameters

NameTypeDescription
clstype[_BaseToolT]-
base_typetype[_utils.BaseType]The base type (e.g. `int`) to convert into this tool type.

Returns

TypeDescription
type[_BaseToolT]-

Function tool_schema

Parameters

NameTypeDescription
clsAny-

Returns

TypeDescription
Any-

Function model_json_schema

Returns the generated JSON schema for the class.

Parameters

NameTypeDescription
clsAny-
by_alias= Truebool-
ref_template= DEFAULT_REF_TEMPLATEstr-
schema_generator= GenerateJsonSchemaNoTitlestype[GenerateJsonSchema]-
mode= 'validation'JsonSchemaMode-

Returns

TypeDescription
dict[str, Any]-

Function warn_for_unsupported_configurations

Warns when a specific provider does not support provided config options.

Parameters

NameTypeDescription
clsAny-

Returns

TypeDescription
None-