tools
Attribute FORMAT_TOOL_NAME
Type: '__mirascope_formatted_output_tool__'
Reserved name of the formatted output tool.
Any call to a tool with this name is NOT considered a regular tool call, but will instead be converted into textual output containing the arguments to the tool call.
Class AsyncContextTool
Protocol defining an async tool that can be used by LLMs with context.
An AsyncContextTool represents an async function that can be called by an LLM during a call.
It includes metadata like name, description, and parameter schema.
This class is not instantiated directly but created by the @tool() decorator.
Bases: ToolSchema[AsyncContextToolFn[DepsT, AnyP, JsonableCovariantT]], Generic[DepsT, JsonableCovariantT, AnyP]
Function execute
Execute the async context tool using an LLM-provided ToolCall.
Returns
| Type | Description |
|---|---|
| ToolOutput[JsonableCovariantT] | - |
Class AsyncContextToolkit
A collection of AsyncContextTools, with helpers for getting and executing specific tools.
Bases: BaseToolkit[AsyncTool | AsyncContextTool[DepsT]], Generic[DepsT]
Function execute
Execute an AsyncContextTool using the provided tool call.
Parameters
Returns
| Type | Description |
|---|---|
| ToolOutput[Jsonable] | The output from executing the `AsyncContextTool`. |
Class AsyncTool
An async tool that can be used by LLMs.
An AsyncTool represents an async function that can be called by an LLM during a call.
It includes metadata like name, description, and parameter schema.
This class is not instantiated directly but created by the @tool() decorator.
Bases: ToolSchema[AsyncToolFn[AnyP, JsonableCovariantT]], Generic[AnyP, JsonableCovariantT]
Function execute
Execute the async tool using an LLM-provided ToolCall.
Parameters
| Name | Type | Description |
|---|---|---|
| self | Any | - |
| tool_call | ToolCall | - |
Returns
| Type | Description |
|---|---|
| ToolOutput[JsonableCovariantT] | - |
Class AsyncToolkit
A collection of AsyncTools, with helpers for getting and executing specific tools.
Bases:
BaseToolkit[AsyncTool]Function execute
Execute an AsyncTool using the provided tool call.
Parameters
| Name | Type | Description |
|---|---|---|
| self | Any | - |
| tool_call | ToolCall | The tool call to execute. |
Returns
| Type | Description |
|---|---|
| ToolOutput[Jsonable] | The output from executing the `AsyncTool`. |
Class BaseToolkit
Base class for tool collections.
Provides common functionality for managing collections of tools, including name validation and tool lookup.
Bases:
Generic[ToolSchemaT]Attributes
| Name | Type | Description |
|---|---|---|
| tools | Sequence[ToolSchemaT] | The tools included in the toolkit. |
| tools_dict | dict[str, ToolSchemaT] | A mapping from tool names to tools in the toolkit. |
Function get
Get a tool that can execute a specific tool call.
Parameters
| Name | Type | Description |
|---|---|---|
| self | Any | - |
| tool_call | ToolCall | The tool call containing the tool name to lookup. |
Returns
| Type | Description |
|---|---|
| ToolSchemaT | The tool whose name matches the tool call. |
Class ContextTool
Protocol defining a tool that can be used by LLMs.
A ContextTool represents a function that can be called by an LLM during a call.
It includes metadata like name, description, and parameter schema.
This class is not instantiated directly but created by the @tool() decorator.
Bases: ToolSchema[ContextToolFn[DepsT, AnyP, JsonableCovariantT]], Generic[DepsT, JsonableCovariantT, AnyP]
Function execute
Execute the context tool using an LLM-provided ToolCall.
Returns
| Type | Description |
|---|---|
| ToolOutput[JsonableCovariantT] | - |
Class ContextToolkit
A collection of ContextTools, with helpers for getting and executing specific tools.
Bases: BaseToolkit[Tool | ContextTool[DepsT]], Generic[DepsT]
Function execute
Execute a ContextTool using the provided tool call.
Parameters
Returns
| Type | Description |
|---|---|
| ToolOutput[Jsonable] | The output from executing the `ContextTool`. |
Class Tool
A tool that can be used by LLMs.
A Tool represents a function that can be called by an LLM during a call.
It includes metadata like name, description, and parameter schema.
This class is not instantiated directly but created by the @tool() decorator.
Bases: ToolSchema[ToolFn[AnyP, JsonableCovariantT]], Generic[AnyP, JsonableCovariantT]
Function execute
Execute the tool using an LLM-provided ToolCall.
Parameters
| Name | Type | Description |
|---|---|---|
| self | Any | - |
| tool_call | ToolCall | - |
Returns
| Type | Description |
|---|---|
| ToolOutput[JsonableCovariantT] | - |
Class ToolDecorator
Protocol for the tool decorator.
Attributes
| Name | Type | Description |
|---|---|---|
| strict | bool | Whether to use strict tool calling, if supported by the provider. |
Class ToolParameterSchema
JSON Schema for tool parameters (always an object with properties).
This contains real JSON Schema as generated by Pydantic, with full support for complex schemas like anyOf, nested objects, validation constraints, etc. Including $defs for complex type references.
Bases:
BaseModelAttributes
| Name | Type | Description |
|---|---|---|
| properties | dict[str, dict[str, Any]] | Dictionary mapping parameter names to their JSON Schema definitions. |
| required | list[str] | List of required parameter names. |
| additionalProperties | bool | Whether additional properties beyond those defined are allowed. |
| defs | dict[str, dict[str, Any]] | None | JSON Schema definitions for complex types referenced via $ref. |
Class ToolSchema
Underlying schema defining a tool that can be used by LLMs.
A ToolSchema represents a function that can be called by an LLM during a call. It includes metadata like name, description, and parameter schema.
This class is not instantiated directly but created by the @tool() decorator.
Bases:
Generic[ToolFnT]Attributes
| Name | Type | Description |
|---|---|---|
| fn | ToolFnT | The function that implements the tool's functionality. |
| name | str | The name of the tool, used by the LLM to identify which tool to call. |
| description | str | Description of what the tool does, extracted from the function's docstring. |
| parameters | ToolParameterSchema | JSON Schema describing the parameters accepted by the tool. The serialized parameters table is cached for efficient hash lookups (e.g. when caching provider-encoded tool representations in a LRU cache). Therefore, it should **not be modified** after the ToolSchema is created. |
| strict | bool | Whether the tool should use strict mode when supported by the model. |
Function can_execute
Check if a ToolCall can be executed by tools with this ToolSchema.
This method is a convenient way to determine if a ToolCall is likely intended
to be executed by a tool with this ToolSchema. It does so by checking
whether the name on the call matches the name on the schema. No other validation
is performed.
Parameters
| Name | Type | Description |
|---|---|---|
| self | Any | - |
| tool_call | ToolCall | - |
Returns
| Type | Description |
|---|---|
| bool | - |
Attribute ToolSchemaT
Type: TypeVar('ToolSchemaT', bound='ToolSchema')
Attribute ToolT
Type: TypeVar('ToolT', bound='Tool | AsyncTool | ContextTool[Any] | AsyncContextTool[Any]', covariant=True)
Class Toolkit
A collection of Tools, with helpers for getting and executing specific tools.
Bases:
BaseToolkit[Tool]Function execute
Execute a Tool using the provided tool call.
Parameters
| Name | Type | Description |
|---|---|---|
| self | Any | - |
| tool_call | ToolCall | The tool call to execute. |
Returns
| Type | Description |
|---|---|
| ToolOutput[Jsonable] | The output from executing the `Tool`. |
Attribute ToolkitT
Type: TypeVar('ToolkitT', bound='Toolkit | AsyncToolkit | ContextToolkit[Any] | AsyncContextToolkit[Any]', covariant=True)
Module protocols
Function tool
Decorator that turns a function into a tool definition.
This decorator creates a Tool or ContextTool that can be used with llm.call.
The function's name, docstring, and type hints are used to generate the
tool's metadata.
If the first parameter is named 'ctx' or typed as llm.Context[T], it creates
a ContextTool. Otherwise, it creates a regular Tool.
Examples:
Regular tool:
from mirascope import llm
@llm.tool
def available_books() -> list[str]:
"""Returns the list of available books."""
return ["The Name of the Wind"]Context tool:
from dataclasses import dataclass
from mirascope import llm
@dataclass
class Library:
books: list[str]
library = Library(books=["Mistborn", "Gödel, Escher, Bach", "Dune"])
@llm.tool
def available_books(ctx: llm.Context[Library]) -> list[str]:
"""Returns the list of available books."""
return ctx.deps.booksParameters
| Name | Type | Description |
|---|---|---|
| __fn= None | ContextToolFn[DepsT, P, JsonableCovariantT] | AsyncContextToolFn[DepsT, P, JsonableCovariantT] | ToolFn[P, JsonableCovariantT] | AsyncToolFn[P, JsonableCovariantT] | None | - |
| strict= False | bool | Whether the tool should use strict mode when supported by the model. |
Returns
| Type | Description |
|---|---|
| ContextTool[DepsT, JsonableCovariantT, P] | AsyncContextTool[DepsT, JsonableCovariantT, P] | Tool[P, JsonableCovariantT] | AsyncTool[P, JsonableCovariantT] | ToolDecorator | A decorator function that converts the function into a Tool or ContextTool. |