# tools
## <ApiType type="Attribute" slug="f-o-r-m-a-t_-t-o-o-l_-n-a-m-e" symbolName="FORMAT_TOOL_NAME" /> FORMAT_TOOL_NAME
**Type:** <TypeLink type={{"type_str": "'__mirascope_formatted_output_tool__'", "description": null, "kind": "simple", "symbol_name": "'__mirascope_formatted_output_tool__'", "doc_url": null}} />
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.
## <ApiType type="Attribute" slug="any-tool-fn" symbolName="AnyToolFn" /> AnyToolFn
**Type:** <TypeLink type={{"type_str": "TypeAlias", "description": null, "kind": "simple", "symbol_name": "TypeAlias", "doc_url": null}} />
## <ApiType type="Attribute" slug="any-tool-schema" symbolName="AnyToolSchema" /> AnyToolSchema
**Type:** <TypeLink type={{"type_str": "TypeAlias", "description": null, "kind": "simple", "symbol_name": "TypeAlias", "doc_url": null}} />
## <ApiType type="Class" slug="async-context-tool" symbolName="AsyncContextTool" /> 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:**
<TypeLink type={{"type_str": "ToolSchema[AsyncContextToolFn[DepsT, AnyP, JsonableCovariantT]]", "description": null, "kind": "generic", "base_type": {"type_str": "ToolSchema", "description": null, "kind": "simple", "symbol_name": "ToolSchema", "doc_url": "/docs/api/llm/tools#tool-schema"}, "parameters": [{"type_str": "AsyncContextToolFn[DepsT, AnyP, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "AsyncContextToolFn", "description": null, "kind": "simple", "symbol_name": "AsyncContextToolFn", "doc_url": "/docs/api/llm/tools#async-context-tool-fn"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}, {"type_str": "AnyP", "description": null, "kind": "simple", "symbol_name": "AnyP", "doc_url": "/docs/api/llm/types#any-p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}], "doc_url": null}} />, <TypeLink type={{"type_str": "Generic[DepsT, JsonableCovariantT, AnyP]", "description": null, "kind": "generic", "base_type": {"type_str": "Generic", "description": null, "kind": "simple", "symbol_name": "Generic", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Generic"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}, {"type_str": "AnyP", "description": null, "kind": "simple", "symbol_name": "AnyP", "doc_url": "/docs/api/llm/types#any-p"}], "doc_url": null}} />
## <ApiType type="Function" slug="mirascope-llm-tools-tools--async-context-tool-from_function" symbolName="from_function" /> from_function
Create an `AsyncContextTool` by inspecting a function and its docstring.
<ParametersTable
parameters={[
{
"name": "cls",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "fn",
"type_info": {
"type_str": "AsyncContextToolFn[DepsT, AnyP, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "AsyncContextToolFn",
"description": null,
"kind": "simple",
"symbol_name": "AsyncContextToolFn",
"doc_url": "/docs/api/llm/tools#async-context-tool-fn"
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
},
{
"type_str": "AnyP",
"description": null,
"kind": "simple",
"symbol_name": "AnyP",
"doc_url": "/docs/api/llm/types#any-p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
"description": "The function to extract schema from"
},
{
"name": "strict",
"type_info": {
"type_str": "bool | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": "https://docs.python.org/3/library/functions.html#bool"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
],
"doc_url": null
},
"default": "None",
"description": "Whether the tool should use strict mode when supported.\nIf None, uses provider's default (usually as strict as possible)."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "AsyncContextTool[DepsT, JsonableCovariantT, AnyP]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "AsyncContextTool",
"description": null,
"kind": "simple",
"symbol_name": "AsyncContextTool",
"doc_url": "/docs/api/llm/tools#async-context-tool"
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
},
{
"type_str": "AnyP",
"description": null,
"kind": "simple",
"symbol_name": "AnyP",
"doc_url": "/docs/api/llm/types#any-p"
}
],
"doc_url": null
},
"description": "an `AsyncContextTool` representing the function"
}}
/>
## <ApiType type="Function" slug="mirascope-llm-tools-tools--async-context-tool-execute" symbolName="execute" /> execute
Execute the async context tool using an LLM-provided `ToolCall`.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "ctx",
"type_info": {
"type_str": "Context[DepsT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "Context",
"description": null,
"kind": "simple",
"symbol_name": "Context",
"doc_url": null
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
}
],
"doc_url": null
}
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
}
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolOutput[JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolOutput",
"description": null,
"kind": "simple",
"symbol_name": "ToolOutput",
"doc_url": "/docs/api/llm/content#tool-output"
},
"parameters": [
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
}
}}
/>
## <ApiType type="Class" slug="async-context-tool-fn" symbolName="AsyncContextToolFn" /> AsyncContextToolFn
Protocol for the async context tool function.
**Bases:**
<TypeLink type={{"type_str": "Protocol[DepsT, P, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "Protocol", "description": null, "kind": "simple", "symbol_name": "Protocol", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Protocol"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}, {"type_str": "P", "description": null, "kind": "simple", "symbol_name": "P", "doc_url": "/docs/api/llm/types#p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}} />
## <ApiType type="Class" slug="async-context-toolkit" symbolName="AsyncContextToolkit" /> AsyncContextToolkit
A collection of `AsyncContextTool`s, with helpers for getting and executing specific tools.
**Bases:**
<TypeLink type={{"type_str": "BaseToolkit[AsyncTool | AsyncContextTool[DepsT]]", "description": null, "kind": "generic", "base_type": {"type_str": "BaseToolkit", "description": null, "kind": "simple", "symbol_name": "BaseToolkit", "doc_url": "/docs/api/llm/tools#base-toolkit"}, "parameters": [{"type_str": "AsyncTool | AsyncContextTool[DepsT]", "description": null, "kind": "union", "base_type": {"type_str": "Union", "description": null, "kind": "simple", "symbol_name": "Union", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"}, "parameters": [{"type_str": "AsyncTool", "description": null, "kind": "simple", "symbol_name": "AsyncTool", "doc_url": "/docs/api/llm/tools#async-tool"}, {"type_str": "AsyncContextTool[DepsT]", "description": null, "kind": "generic", "base_type": {"type_str": "AsyncContextTool", "description": null, "kind": "simple", "symbol_name": "AsyncContextTool", "doc_url": "/docs/api/llm/tools#async-context-tool"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}], "doc_url": null}], "doc_url": null}], "doc_url": null}} />, <TypeLink type={{"type_str": "Generic[DepsT]", "description": null, "kind": "generic", "base_type": {"type_str": "Generic", "description": null, "kind": "simple", "symbol_name": "Generic", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Generic"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}], "doc_url": null}} />
## <ApiType type="Function" slug="mirascope-llm-tools-toolkit--async-context-toolkit-execute" symbolName="execute" /> execute
Execute an `AsyncContextTool` using the provided tool call.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "ctx",
"type_info": {
"type_str": "Context[DepsT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "Context",
"description": null,
"kind": "simple",
"symbol_name": "Context",
"doc_url": null
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
}
],
"doc_url": null
},
"description": "The context containing dependencies that match the tool."
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
},
"description": "The tool call to execute."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolOutput[Jsonable]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolOutput",
"description": null,
"kind": "simple",
"symbol_name": "ToolOutput",
"doc_url": "/docs/api/llm/content#tool-output"
},
"parameters": [
{
"type_str": "Jsonable",
"description": null,
"kind": "simple",
"symbol_name": "Jsonable",
"doc_url": "/docs/api/llm/types#jsonable"
}
],
"doc_url": null
},
"description": "The output from executing the `AsyncContextTool`."
}}
/>
## <ApiType type="Class" slug="async-tool" symbolName="AsyncTool" /> 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:**
<TypeLink type={{"type_str": "ToolSchema[AsyncToolFn[AnyP, JsonableCovariantT]]", "description": null, "kind": "generic", "base_type": {"type_str": "ToolSchema", "description": null, "kind": "simple", "symbol_name": "ToolSchema", "doc_url": "/docs/api/llm/tools#tool-schema"}, "parameters": [{"type_str": "AsyncToolFn[AnyP, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "AsyncToolFn", "description": null, "kind": "simple", "symbol_name": "AsyncToolFn", "doc_url": "/docs/api/llm/tools#async-tool-fn"}, "parameters": [{"type_str": "AnyP", "description": null, "kind": "simple", "symbol_name": "AnyP", "doc_url": "/docs/api/llm/types#any-p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}], "doc_url": null}} />, <TypeLink type={{"type_str": "Generic[AnyP, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "Generic", "description": null, "kind": "simple", "symbol_name": "Generic", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Generic"}, "parameters": [{"type_str": "AnyP", "description": null, "kind": "simple", "symbol_name": "AnyP", "doc_url": "/docs/api/llm/types#any-p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}} />
## <ApiType type="Function" slug="mirascope-llm-tools-tools--async-tool-from_function" symbolName="from_function" /> from_function
Create an `AsyncTool` by inspecting a function and its docstring.
<ParametersTable
parameters={[
{
"name": "cls",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "fn",
"type_info": {
"type_str": "AsyncToolFn[AnyP, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "AsyncToolFn",
"description": null,
"kind": "simple",
"symbol_name": "AsyncToolFn",
"doc_url": "/docs/api/llm/tools#async-tool-fn"
},
"parameters": [
{
"type_str": "AnyP",
"description": null,
"kind": "simple",
"symbol_name": "AnyP",
"doc_url": "/docs/api/llm/types#any-p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
"description": "The function to extract schema from"
},
{
"name": "strict",
"type_info": {
"type_str": "bool | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": "https://docs.python.org/3/library/functions.html#bool"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
],
"doc_url": null
},
"default": "None",
"description": "Whether the tool should use strict mode when supported.\nIf None, uses provider's default (usually as strict as possible)."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "AsyncTool[AnyP, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "AsyncTool",
"description": null,
"kind": "simple",
"symbol_name": "AsyncTool",
"doc_url": "/docs/api/llm/tools#async-tool"
},
"parameters": [
{
"type_str": "AnyP",
"description": null,
"kind": "simple",
"symbol_name": "AnyP",
"doc_url": "/docs/api/llm/types#any-p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
"description": "an `AsyncTool` representing the function"
}}
/>
## <ApiType type="Function" slug="mirascope-llm-tools-tools--async-tool-execute" symbolName="execute" /> execute
Execute the async tool using an LLM-provided `ToolCall`.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
}
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolOutput[JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolOutput",
"description": null,
"kind": "simple",
"symbol_name": "ToolOutput",
"doc_url": "/docs/api/llm/content#tool-output"
},
"parameters": [
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
}
}}
/>
## <ApiType type="Class" slug="async-tool-fn" symbolName="AsyncToolFn" /> AsyncToolFn
Protocol for the async tool function.
**Bases:**
<TypeLink type={{"type_str": "Protocol[P, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "Protocol", "description": null, "kind": "simple", "symbol_name": "Protocol", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Protocol"}, "parameters": [{"type_str": "P", "description": null, "kind": "simple", "symbol_name": "P", "doc_url": "/docs/api/llm/types#p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}} />
## <ApiType type="Class" slug="async-toolkit" symbolName="AsyncToolkit" /> AsyncToolkit
A collection of `AsyncTool`s, with helpers for getting and executing specific tools.
**Bases:**
<TypeLink type={{"type_str": "BaseToolkit[AsyncTool]", "description": null, "kind": "generic", "base_type": {"type_str": "BaseToolkit", "description": null, "kind": "simple", "symbol_name": "BaseToolkit", "doc_url": "/docs/api/llm/tools#base-toolkit"}, "parameters": [{"type_str": "AsyncTool", "description": null, "kind": "simple", "symbol_name": "AsyncTool", "doc_url": "/docs/api/llm/tools#async-tool"}], "doc_url": null}} />
## <ApiType type="Function" slug="mirascope-llm-tools-toolkit--async-toolkit-execute" symbolName="execute" /> execute
Execute an `AsyncTool` using the provided tool call.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
},
"description": "The tool call to execute."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolOutput[Jsonable]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolOutput",
"description": null,
"kind": "simple",
"symbol_name": "ToolOutput",
"doc_url": "/docs/api/llm/content#tool-output"
},
"parameters": [
{
"type_str": "Jsonable",
"description": null,
"kind": "simple",
"symbol_name": "Jsonable",
"doc_url": "/docs/api/llm/types#jsonable"
}
],
"doc_url": null
},
"description": "The output from executing the `AsyncTool`."
}}
/>
## <ApiType type="Class" slug="base-toolkit" symbolName="BaseToolkit" /> BaseToolkit
Base class for tool collections.
Provides common functionality for managing collections of tools,
including name validation and tool lookup.
**Bases:**
<TypeLink type={{"type_str": "Generic[ToolSchemaT]", "description": null, "kind": "generic", "base_type": {"type_str": "Generic", "description": null, "kind": "simple", "symbol_name": "Generic", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Generic"}, "parameters": [{"type_str": "ToolSchemaT", "description": null, "kind": "simple", "symbol_name": "ToolSchemaT", "doc_url": "/docs/api/llm/tools#tool-schema-t"}], "doc_url": null}} />
<AttributesTable
attributes={[
{
"name": "tools",
"type_info": {
"type_str": "Sequence[ToolSchemaT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "Sequence",
"description": null,
"kind": "simple",
"symbol_name": "Sequence",
"doc_url": null
},
"parameters": [
{
"type_str": "ToolSchemaT",
"description": null,
"kind": "simple",
"symbol_name": "ToolSchemaT",
"doc_url": null
}
],
"doc_url": null
},
"description": "The tools included in the toolkit."
},
{
"name": "tools_dict",
"type_info": {
"type_str": "dict[str, ToolSchemaT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "dict",
"description": null,
"kind": "simple",
"symbol_name": "dict",
"doc_url": null
},
"parameters": [
{
"type_str": "str",
"description": null,
"kind": "simple",
"symbol_name": "str",
"doc_url": null
},
{
"type_str": "ToolSchemaT",
"description": null,
"kind": "simple",
"symbol_name": "ToolSchemaT",
"doc_url": null
}
],
"doc_url": null
},
"description": "A mapping from tool names to tools in the toolkit."
}
]}
/>
## <ApiType type="Function" slug="mirascope-llm-tools-toolkit--base-toolkit-get" symbolName="get" /> get
Get a tool that can execute a specific tool call.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
},
"description": "The tool call containing the tool name to lookup."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolSchemaT",
"description": null,
"kind": "simple",
"symbol_name": "ToolSchemaT",
"doc_url": "/docs/api/llm/tools#tool-schema-t"
},
"description": "The tool whose name matches the tool call."
}}
/>
## <ApiType type="Class" slug="context-tool" symbolName="ContextTool" /> 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:**
<TypeLink type={{"type_str": "ToolSchema[ContextToolFn[DepsT, AnyP, JsonableCovariantT]]", "description": null, "kind": "generic", "base_type": {"type_str": "ToolSchema", "description": null, "kind": "simple", "symbol_name": "ToolSchema", "doc_url": "/docs/api/llm/tools#tool-schema"}, "parameters": [{"type_str": "ContextToolFn[DepsT, AnyP, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "ContextToolFn", "description": null, "kind": "simple", "symbol_name": "ContextToolFn", "doc_url": "/docs/api/llm/tools#context-tool-fn"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}, {"type_str": "AnyP", "description": null, "kind": "simple", "symbol_name": "AnyP", "doc_url": "/docs/api/llm/types#any-p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}], "doc_url": null}} />, <TypeLink type={{"type_str": "Generic[DepsT, JsonableCovariantT, AnyP]", "description": null, "kind": "generic", "base_type": {"type_str": "Generic", "description": null, "kind": "simple", "symbol_name": "Generic", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Generic"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}, {"type_str": "AnyP", "description": null, "kind": "simple", "symbol_name": "AnyP", "doc_url": "/docs/api/llm/types#any-p"}], "doc_url": null}} />
## <ApiType type="Function" slug="mirascope-llm-tools-tools--context-tool-from_function" symbolName="from_function" /> from_function
Create a `ContextTool` by inspecting a function and its docstring.
<ParametersTable
parameters={[
{
"name": "cls",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "fn",
"type_info": {
"type_str": "ContextToolFn[DepsT, AnyP, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ContextToolFn",
"description": null,
"kind": "simple",
"symbol_name": "ContextToolFn",
"doc_url": "/docs/api/llm/tools#context-tool-fn"
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
},
{
"type_str": "AnyP",
"description": null,
"kind": "simple",
"symbol_name": "AnyP",
"doc_url": "/docs/api/llm/types#any-p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
"description": "The function to extract schema from"
},
{
"name": "strict",
"type_info": {
"type_str": "bool | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": "https://docs.python.org/3/library/functions.html#bool"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
],
"doc_url": null
},
"default": "None",
"description": "Whether the tool should use strict mode when supported.\nIf None, uses provider's default (usually as strict as possible)."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ContextTool[DepsT, JsonableCovariantT, AnyP]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ContextTool",
"description": null,
"kind": "simple",
"symbol_name": "ContextTool",
"doc_url": "/docs/api/llm/tools#context-tool"
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
},
{
"type_str": "AnyP",
"description": null,
"kind": "simple",
"symbol_name": "AnyP",
"doc_url": "/docs/api/llm/types#any-p"
}
],
"doc_url": null
},
"description": "a `ContextTool` representing the function"
}}
/>
## <ApiType type="Function" slug="mirascope-llm-tools-tools--context-tool-execute" symbolName="execute" /> execute
Execute the context tool using an LLM-provided `ToolCall`.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "ctx",
"type_info": {
"type_str": "Context[DepsT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "Context",
"description": null,
"kind": "simple",
"symbol_name": "Context",
"doc_url": null
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
}
],
"doc_url": null
}
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
}
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolOutput[JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolOutput",
"description": null,
"kind": "simple",
"symbol_name": "ToolOutput",
"doc_url": "/docs/api/llm/content#tool-output"
},
"parameters": [
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
}
}}
/>
## <ApiType type="Class" slug="context-tool-fn" symbolName="ContextToolFn" /> ContextToolFn
Protocol for the context tool function.
**Bases:**
<TypeLink type={{"type_str": "Protocol[DepsT, P, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "Protocol", "description": null, "kind": "simple", "symbol_name": "Protocol", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Protocol"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}, {"type_str": "P", "description": null, "kind": "simple", "symbol_name": "P", "doc_url": "/docs/api/llm/types#p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}} />
## <ApiType type="Class" slug="context-toolkit" symbolName="ContextToolkit" /> ContextToolkit
A collection of `ContextTool`s, with helpers for getting and executing specific tools.
**Bases:**
<TypeLink type={{"type_str": "BaseToolkit[Tool | ContextTool[DepsT]]", "description": null, "kind": "generic", "base_type": {"type_str": "BaseToolkit", "description": null, "kind": "simple", "symbol_name": "BaseToolkit", "doc_url": "/docs/api/llm/tools#base-toolkit"}, "parameters": [{"type_str": "Tool | ContextTool[DepsT]", "description": null, "kind": "union", "base_type": {"type_str": "Union", "description": null, "kind": "simple", "symbol_name": "Union", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"}, "parameters": [{"type_str": "Tool", "description": null, "kind": "simple", "symbol_name": "Tool", "doc_url": "/docs/api/llm/tools#tool"}, {"type_str": "ContextTool[DepsT]", "description": null, "kind": "generic", "base_type": {"type_str": "ContextTool", "description": null, "kind": "simple", "symbol_name": "ContextTool", "doc_url": "/docs/api/llm/tools#context-tool"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}], "doc_url": null}], "doc_url": null}], "doc_url": null}} />, <TypeLink type={{"type_str": "Generic[DepsT]", "description": null, "kind": "generic", "base_type": {"type_str": "Generic", "description": null, "kind": "simple", "symbol_name": "Generic", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Generic"}, "parameters": [{"type_str": "DepsT", "description": null, "kind": "simple", "symbol_name": "DepsT", "doc_url": null}], "doc_url": null}} />
## <ApiType type="Function" slug="mirascope-llm-tools-toolkit--context-toolkit-execute" symbolName="execute" /> execute
Execute a `ContextTool` using the provided tool call.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "ctx",
"type_info": {
"type_str": "Context[DepsT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "Context",
"description": null,
"kind": "simple",
"symbol_name": "Context",
"doc_url": null
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
}
],
"doc_url": null
},
"description": "The context containing dependencies that match the tool."
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
},
"description": "The tool call to execute."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolOutput[Jsonable]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolOutput",
"description": null,
"kind": "simple",
"symbol_name": "ToolOutput",
"doc_url": "/docs/api/llm/content#tool-output"
},
"parameters": [
{
"type_str": "Jsonable",
"description": null,
"kind": "simple",
"symbol_name": "Jsonable",
"doc_url": "/docs/api/llm/types#jsonable"
}
],
"doc_url": null
},
"description": "The output from executing the `ContextTool`."
}}
/>
## <ApiType type="Class" slug="tool" symbolName="Tool" /> 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:**
<TypeLink type={{"type_str": "ToolSchema[ToolFn[AnyP, JsonableCovariantT]]", "description": null, "kind": "generic", "base_type": {"type_str": "ToolSchema", "description": null, "kind": "simple", "symbol_name": "ToolSchema", "doc_url": "/docs/api/llm/tools#tool-schema"}, "parameters": [{"type_str": "ToolFn[AnyP, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "ToolFn", "description": null, "kind": "simple", "symbol_name": "ToolFn", "doc_url": "/docs/api/llm/tools#tool-fn"}, "parameters": [{"type_str": "AnyP", "description": null, "kind": "simple", "symbol_name": "AnyP", "doc_url": "/docs/api/llm/types#any-p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}], "doc_url": null}} />, <TypeLink type={{"type_str": "Generic[AnyP, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "Generic", "description": null, "kind": "simple", "symbol_name": "Generic", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Generic"}, "parameters": [{"type_str": "AnyP", "description": null, "kind": "simple", "symbol_name": "AnyP", "doc_url": "/docs/api/llm/types#any-p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}} />
## <ApiType type="Function" slug="mirascope-llm-tools-tools--tool-from_function" symbolName="from_function" /> from_function
Create a `Tool` by inspecting a function and its docstring.
<ParametersTable
parameters={[
{
"name": "cls",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "fn",
"type_info": {
"type_str": "ToolFn[AnyP, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolFn",
"description": null,
"kind": "simple",
"symbol_name": "ToolFn",
"doc_url": "/docs/api/llm/tools#tool-fn"
},
"parameters": [
{
"type_str": "AnyP",
"description": null,
"kind": "simple",
"symbol_name": "AnyP",
"doc_url": "/docs/api/llm/types#any-p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
"description": "The function to extract schema from"
},
{
"name": "strict",
"type_info": {
"type_str": "bool | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": "https://docs.python.org/3/library/functions.html#bool"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
],
"doc_url": null
},
"default": "None",
"description": "Whether the tool should use strict mode when supported.\nIf None, uses provider's default (usually as strict as possible)."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "Tool[AnyP, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "Tool",
"description": null,
"kind": "simple",
"symbol_name": "Tool",
"doc_url": "/docs/api/llm/tools#tool"
},
"parameters": [
{
"type_str": "AnyP",
"description": null,
"kind": "simple",
"symbol_name": "AnyP",
"doc_url": "/docs/api/llm/types#any-p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
"description": "a `Tool` representing the function"
}}
/>
## <ApiType type="Function" slug="mirascope-llm-tools-tools--tool-execute" symbolName="execute" /> execute
Execute the tool using an LLM-provided `ToolCall`.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
}
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolOutput[JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolOutput",
"description": null,
"kind": "simple",
"symbol_name": "ToolOutput",
"doc_url": "/docs/api/llm/content#tool-output"
},
"parameters": [
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
}
}}
/>
## <ApiType type="Class" slug="tool-decorator" symbolName="ToolDecorator" /> ToolDecorator
Protocol for the tool decorator.
<AttributesTable
attributes={[
{
"name": "strict",
"type_info": {
"type_str": "bool | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": null
},
"parameters": [
{
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": null
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": null
}
],
"doc_url": null
},
"description": "Whether to use strict tool calling, if supported by the provider.\n\nIf set to None, then it will use the provider's default setting (usually the \nstrictest possible)."
}
]}
/>
## <ApiType type="Class" slug="tool-fn" symbolName="ToolFn" /> ToolFn
Protocol for the tool function.
**Bases:**
<TypeLink type={{"type_str": "Protocol[P, JsonableCovariantT]", "description": null, "kind": "generic", "base_type": {"type_str": "Protocol", "description": null, "kind": "simple", "symbol_name": "Protocol", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Protocol"}, "parameters": [{"type_str": "P", "description": null, "kind": "simple", "symbol_name": "P", "doc_url": "/docs/api/llm/types#p"}, {"type_str": "JsonableCovariantT", "description": null, "kind": "simple", "symbol_name": "JsonableCovariantT", "doc_url": "/docs/api/llm/types#jsonable-covariant-t"}], "doc_url": null}} />
## <ApiType type="Class" slug="tool-parameter-schema" symbolName="ToolParameterSchema" /> 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:**
<TypeLink type={{"type_str": "BaseModel", "description": null, "kind": "simple", "symbol_name": "BaseModel", "doc_url": null}} />
<AttributesTable
attributes={[
{
"name": "properties",
"type_info": {
"type_str": "dict[str, dict[str, Any]]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "dict",
"description": null,
"kind": "simple",
"symbol_name": "dict",
"doc_url": null
},
"parameters": [
{
"type_str": "str",
"description": null,
"kind": "simple",
"symbol_name": "str",
"doc_url": null
},
{
"type_str": "dict[str, Any]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "dict",
"description": null,
"kind": "simple",
"symbol_name": "dict",
"doc_url": null
},
"parameters": [
{
"type_str": "str",
"description": null,
"kind": "simple",
"symbol_name": "str",
"doc_url": null
},
{
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": "Any",
"doc_url": null
}
],
"doc_url": null
}
],
"doc_url": null
},
"description": "Dictionary mapping parameter names to their JSON Schema definitions."
},
{
"name": "required",
"type_info": {
"type_str": "list[str]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "list",
"description": null,
"kind": "simple",
"symbol_name": "list",
"doc_url": null
},
"parameters": [
{
"type_str": "str",
"description": null,
"kind": "simple",
"symbol_name": "str",
"doc_url": null
}
],
"doc_url": null
},
"description": "List of required parameter names."
},
{
"name": "additionalProperties",
"type_info": {
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": null
},
"description": "Whether additional properties beyond those defined are allowed."
},
{
"name": "defs",
"type_info": {
"type_str": "dict[str, dict[str, Any]] | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": null
},
"parameters": [
{
"type_str": "dict[str, dict[str, Any]]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "dict",
"description": null,
"kind": "simple",
"symbol_name": "dict",
"doc_url": null
},
"parameters": [
{
"type_str": "str",
"description": null,
"kind": "simple",
"symbol_name": "str",
"doc_url": null
},
{
"type_str": "dict[str, Any]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "dict",
"description": null,
"kind": "simple",
"symbol_name": "dict",
"doc_url": null
},
"parameters": [
{
"type_str": "str",
"description": null,
"kind": "simple",
"symbol_name": "str",
"doc_url": null
},
{
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": "Any",
"doc_url": null
}
],
"doc_url": null
}
],
"doc_url": null
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": null
}
],
"doc_url": null
},
"description": "JSON Schema definitions for complex types referenced via $ref."
}
]}
/>
## <ApiType type="Class" slug="tool-schema" symbolName="ToolSchema" /> 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:**
<TypeLink type={{"type_str": "Generic[ToolFnT]", "description": null, "kind": "generic", "base_type": {"type_str": "Generic", "description": null, "kind": "simple", "symbol_name": "Generic", "doc_url": "https://docs.python.org/3/library/typing.html#typing.Generic"}, "parameters": [{"type_str": "ToolFnT", "description": null, "kind": "simple", "symbol_name": "ToolFnT", "doc_url": null}], "doc_url": null}} />
<AttributesTable
attributes={[
{
"name": "fn",
"type_info": {
"type_str": "ToolFnT",
"description": null,
"kind": "simple",
"symbol_name": "ToolFnT",
"doc_url": null
},
"description": "The function that implements the tool's functionality."
},
{
"name": "name",
"type_info": {
"type_str": "str",
"description": null,
"kind": "simple",
"symbol_name": "str",
"doc_url": null
},
"description": "The name of the tool, used by the LLM to identify which tool to call."
},
{
"name": "description",
"type_info": {
"type_str": "str",
"description": null,
"kind": "simple",
"symbol_name": "str",
"doc_url": null
},
"description": "Description of what the tool does, extracted from the function's docstring."
},
{
"name": "parameters",
"type_info": {
"type_str": "ToolParameterSchema",
"description": null,
"kind": "simple",
"symbol_name": "ToolParameterSchema",
"doc_url": null
},
"description": "JSON Schema describing the parameters accepted by the tool.\n\nThe serialized parameters table is cached for efficient hash lookups (e.g. when\ncaching provider-encoded tool representations in a LRU cache). Therefore,\nit should **not be modified** after the ToolSchema is created."
},
{
"name": "strict",
"type_info": {
"type_str": "bool | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": null
},
"parameters": [
{
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": null
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": null
}
],
"doc_url": null
},
"description": "Whether the tool should use strict mode when supported by the model.\n\nIf set to None, will use the provider's default setting (usually as strict as \npossible)."
}
]}
/>
## <ApiType type="Function" slug="mirascope-llm-tools-tool_schema--tool-schema-from_function" symbolName="from_function" /> from_function
Create a `ToolSchema` by inspecting a function and its docstring.
Uses Pydantic's create_model to dynamically build a model from the function
signature, then extracts the JSON schema from it. This leverages Pydantic's
robust type conversion and union handling.
<ParametersTable
parameters={[
{
"name": "cls",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "fn",
"type_info": {
"type_str": "AnyToolFn",
"description": null,
"kind": "simple",
"symbol_name": "AnyToolFn",
"doc_url": "/docs/api/llm/tools#any-tool-fn"
},
"description": "The function to extract schema from"
},
{
"name": "strict",
"type_info": {
"type_str": "bool | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": "https://docs.python.org/3/library/functions.html#bool"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
],
"doc_url": null
},
"default": "None",
"description": "Whether the tool should use strict mode when supported.\nIf None, uses provider's default (usually as strict as possible)."
},
{
"name": "is_context_tool",
"type_info": {
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": "https://docs.python.org/3/library/functions.html#bool"
},
"default": "False",
"description": "Whether this is a context tool (skips the context parameter)"
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolSchema[AnyToolFn]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolSchema",
"description": null,
"kind": "simple",
"symbol_name": "ToolSchema",
"doc_url": "/docs/api/llm/tools#tool-schema"
},
"parameters": [
{
"type_str": "AnyToolFn",
"description": null,
"kind": "simple",
"symbol_name": "AnyToolFn",
"doc_url": "/docs/api/llm/tools#any-tool-fn"
}
],
"doc_url": null
},
"description": "a `ToolSchema` representing the function"
}}
/>
## <ApiType type="Function" slug="mirascope-llm-tools-tool_schema--tool-schema-can_execute" symbolName="can_execute" /> 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.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
}
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": "https://docs.python.org/3/library/functions.html#bool"
}
}}
/>
## <ApiType type="Attribute" slug="tool-schema-t" symbolName="ToolSchemaT" /> ToolSchemaT
**Type:** <TypeLink type={{"type_str": "TypeVar('ToolSchemaT', bound=AnyToolSchema, covariant=True)", "description": null, "kind": "simple", "symbol_name": null, "doc_url": null}} />
## <ApiType type="Attribute" slug="tool-t" symbolName="ToolT" /> ToolT
**Type:** <TypeLink type={{"type_str": "TypeVar('ToolT', bound='Tool | AsyncTool | ContextTool[Any] | AsyncContextTool[Any]', covariant=True)", "description": null, "kind": "simple", "symbol_name": null, "doc_url": null}} />
## <ApiType type="Class" slug="toolkit" symbolName="Toolkit" /> Toolkit
A collection of `Tool`s, with helpers for getting and executing specific tools.
**Bases:**
<TypeLink type={{"type_str": "BaseToolkit[Tool]", "description": null, "kind": "generic", "base_type": {"type_str": "BaseToolkit", "description": null, "kind": "simple", "symbol_name": "BaseToolkit", "doc_url": "/docs/api/llm/tools#base-toolkit"}, "parameters": [{"type_str": "Tool", "description": null, "kind": "simple", "symbol_name": "Tool", "doc_url": "/docs/api/llm/tools#tool"}], "doc_url": null}} />
## <ApiType type="Function" slug="mirascope-llm-tools-toolkit--toolkit-execute" symbolName="execute" /> execute
Execute a `Tool` using the provided tool call.
<ParametersTable
parameters={[
{
"name": "self",
"type_info": {
"type_str": "Any",
"description": null,
"kind": "simple",
"symbol_name": null,
"doc_url": null
}
},
{
"name": "tool_call",
"type_info": {
"type_str": "ToolCall",
"description": null,
"kind": "simple",
"symbol_name": "ToolCall",
"doc_url": "/docs/api/llm/content#tool-call"
},
"description": "The tool call to execute."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ToolOutput[Jsonable]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolOutput",
"description": null,
"kind": "simple",
"symbol_name": "ToolOutput",
"doc_url": "/docs/api/llm/content#tool-output"
},
"parameters": [
{
"type_str": "Jsonable",
"description": null,
"kind": "simple",
"symbol_name": "Jsonable",
"doc_url": "/docs/api/llm/types#jsonable"
}
],
"doc_url": null
},
"description": "The output from executing the `Tool`."
}}
/>
## <ApiType type="Attribute" slug="toolkit-t" symbolName="ToolkitT" /> ToolkitT
**Type:** <TypeLink type={{"type_str": "TypeVar('ToolkitT', bound='Toolkit | AsyncToolkit | ContextToolkit[Any] | AsyncContextToolkit[Any]', covariant=True)", "description": null, "kind": "simple", "symbol_name": null, "doc_url": null}} />
## <ApiType type="Function" slug="tool_fn" symbolName="tool" /> 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:
```python
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:
```python
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.books
```
<ParametersTable
parameters={[
{
"name": "__fn",
"type_info": {
"type_str": "ContextToolFn[DepsT, P, JsonableCovariantT] | AsyncContextToolFn[DepsT, P, JsonableCovariantT] | ToolFn[P, JsonableCovariantT] | AsyncToolFn[P, JsonableCovariantT] | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "ContextToolFn[DepsT, P, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ContextToolFn",
"description": null,
"kind": "simple",
"symbol_name": "ContextToolFn",
"doc_url": "/docs/api/llm/tools#context-tool-fn"
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
},
{
"type_str": "P",
"description": null,
"kind": "simple",
"symbol_name": "P",
"doc_url": "/docs/api/llm/types#p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
{
"type_str": "AsyncContextToolFn[DepsT, P, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "AsyncContextToolFn",
"description": null,
"kind": "simple",
"symbol_name": "AsyncContextToolFn",
"doc_url": "/docs/api/llm/tools#async-context-tool-fn"
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
},
{
"type_str": "P",
"description": null,
"kind": "simple",
"symbol_name": "P",
"doc_url": "/docs/api/llm/types#p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
{
"type_str": "ToolFn[P, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ToolFn",
"description": null,
"kind": "simple",
"symbol_name": "ToolFn",
"doc_url": "/docs/api/llm/tools#tool-fn"
},
"parameters": [
{
"type_str": "P",
"description": null,
"kind": "simple",
"symbol_name": "P",
"doc_url": "/docs/api/llm/types#p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
{
"type_str": "AsyncToolFn[P, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "AsyncToolFn",
"description": null,
"kind": "simple",
"symbol_name": "AsyncToolFn",
"doc_url": "/docs/api/llm/tools#async-tool-fn"
},
"parameters": [
{
"type_str": "P",
"description": null,
"kind": "simple",
"symbol_name": "P",
"doc_url": "/docs/api/llm/types#p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
],
"doc_url": null
},
"default": "None"
},
{
"name": "strict",
"type_info": {
"type_str": "bool | None",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "bool",
"description": null,
"kind": "simple",
"symbol_name": "bool",
"doc_url": "https://docs.python.org/3/library/functions.html#bool"
},
{
"type_str": "None",
"description": null,
"kind": "simple",
"symbol_name": "None",
"doc_url": "https://docs.python.org/3/library/constants.html#None"
}
],
"doc_url": null
},
"default": "None",
"description": "Whether the tool should use strict mode when supported by the model.\nIf None, uses provider's default (usually as strict as possible)."
}
]}
/>
<ReturnTable
returnType={{
"type_info": {
"type_str": "ContextTool[DepsT, JsonableCovariantT, P] | AsyncContextTool[DepsT, JsonableCovariantT, P] | Tool[P, JsonableCovariantT] | AsyncTool[P, JsonableCovariantT] | ToolDecorator",
"description": null,
"kind": "union",
"base_type": {
"type_str": "Union",
"description": null,
"kind": "simple",
"symbol_name": "Union",
"doc_url": "https://docs.python.org/3/library/typing.html#typing.Union"
},
"parameters": [
{
"type_str": "ContextTool[DepsT, JsonableCovariantT, P]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "ContextTool",
"description": null,
"kind": "simple",
"symbol_name": "ContextTool",
"doc_url": "/docs/api/llm/tools#context-tool"
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
},
{
"type_str": "P",
"description": null,
"kind": "simple",
"symbol_name": "P",
"doc_url": "/docs/api/llm/types#p"
}
],
"doc_url": null
},
{
"type_str": "AsyncContextTool[DepsT, JsonableCovariantT, P]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "AsyncContextTool",
"description": null,
"kind": "simple",
"symbol_name": "AsyncContextTool",
"doc_url": "/docs/api/llm/tools#async-context-tool"
},
"parameters": [
{
"type_str": "DepsT",
"description": null,
"kind": "simple",
"symbol_name": "DepsT",
"doc_url": null
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
},
{
"type_str": "P",
"description": null,
"kind": "simple",
"symbol_name": "P",
"doc_url": "/docs/api/llm/types#p"
}
],
"doc_url": null
},
{
"type_str": "Tool[P, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "Tool",
"description": null,
"kind": "simple",
"symbol_name": "Tool",
"doc_url": "/docs/api/llm/tools#tool"
},
"parameters": [
{
"type_str": "P",
"description": null,
"kind": "simple",
"symbol_name": "P",
"doc_url": "/docs/api/llm/types#p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
{
"type_str": "AsyncTool[P, JsonableCovariantT]",
"description": null,
"kind": "generic",
"base_type": {
"type_str": "AsyncTool",
"description": null,
"kind": "simple",
"symbol_name": "AsyncTool",
"doc_url": "/docs/api/llm/tools#async-tool"
},
"parameters": [
{
"type_str": "P",
"description": null,
"kind": "simple",
"symbol_name": "P",
"doc_url": "/docs/api/llm/types#p"
},
{
"type_str": "JsonableCovariantT",
"description": null,
"kind": "simple",
"symbol_name": "JsonableCovariantT",
"doc_url": "/docs/api/llm/types#jsonable-covariant-t"
}
],
"doc_url": null
},
{
"type_str": "ToolDecorator",
"description": null,
"kind": "simple",
"symbol_name": "ToolDecorator",
"doc_url": "/docs/api/llm/tools#tool-decorator"
}
],
"doc_url": null
},
"description": "A decorator function that converts the function into a Tool or ContextTool."
}}
/>