calute.types.tool_calls#
Tool and function call type definitions for Calute.
This module defines the core data structures for representing tools and function calls in the Calute framework. It provides: - Function definitions with JSON Schema parameters - Tool wrappers for functions - Tool choice options for controlling tool selection - Function call representations for LLM outputs - Tool call structures with unique identifiers
The types are designed to be compatible with OpenAI’s function calling API format while providing additional validation and type safety through Pydantic models.
Example
>>> from calute.types.tool_calls import Tool, Function, ToolCall, FunctionCall
>>> tool = Tool(
... function=Function(
... name="get_weather",
... description="Get weather for a location",
... parameters={"type": "object", "properties": {"location": {"type": "string"}}}
... )
... )
>>> tool_call = ToolCall(
... id="call_123",
... function=FunctionCall(name="get_weather", arguments='{"location": "NYC"}')
... )
- class calute.types.tool_calls.Function(*, name: str, description: str = '', parameters: dict[str, Any])[source]#
Bases:
CaluteBaseFunction definition for tools.
- name#
The name of the function.
- Type
str
- description#
A description of what the function does.
- Type
str
- parameters#
The parameters the functions accepts, described as a JSON Schema object.
- Type
dict[str, Any]
Examples
>>> function = Function( ... name="get_current_weather", ... description="Get the current weather in a given location", ... parameters={ ... "type": "object", ... "properties": { ... "location": { ... "type": "string", ... "description": "The city and state, e.g. San Francisco, CA", ... }, ... "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, ... }, ... "required": ["location"], ... }, ... )
- description: str#
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True, 'validate_default': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str#
- parameters: dict[str, Any]#
- class calute.types.tool_calls.FunctionCall(*, name: str, arguments: str)[source]#
Bases:
CaluteBaseFunction call.
- name#
The name of the function to call.
- Type
str
- arguments#
The arguments to pass to the function.
- Type
str
Examples
>>> function_call = FunctionCall( ... name="get_current_weather", ... arguments={"location": "San Francisco, CA", "unit": "celsius"}, ... )
- arguments: str#
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True, 'validate_default': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- name: str#
- class calute.types.tool_calls.Tool(*, type: ToolTypes = ToolTypes.function, function: Function)[source]#
Bases:
CaluteBaseTool definition.
- type#
The type of the tool.
- function#
The function definition.
Examples
>>> tool = Tool( ... function=Function( ... name="get_current_weather", ... description="Get the current weather in a given location", ... parameters={ ... "type": "object", ... "properties": { ... "location": { ... "type": "string", ... "description": "The city and state, e.g. San Francisco, CA", ... }, ... "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]}, ... }, ... "required": ["location"], ... }, ... ), ... )
- classmethod from_openai(openai_tool: dict[str, Any]) Tool[source]#
Create a Tool instance from an OpenAI-formatted dictionary.
- Parameters
openai_tool – Dictionary in OpenAI tool format.
- Returns
A new Tool instance.
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True, 'validate_default': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class calute.types.tool_calls.ToolCall(*, id: str = 'null', type: ToolTypes = ToolTypes.function, function: FunctionCall)[source]#
Bases:
CaluteBaseTool call.
- id#
The ID of the tool call. Required for V3+ tokenization
- Type
str
- type#
The type of the tool call.
- function#
The function call.
Examples
>>> tool_call = ToolCall( ... id="call_abc123", ... function=FunctionCall( ... name="get_current_weather", ... arguments={"location": "San Francisco, CA", "unit": "celsius"}, ... ), ... )
- classmethod from_openai(tool_call: dict[str, Any]) ToolCall[source]#
Create a ToolCall instance from an OpenAI-formatted dictionary.
- Parameters
tool_call – Dictionary in OpenAI tool call format.
- Returns
A new ToolCall instance.
- function: FunctionCall#
- id: str#
- model_config: ClassVar[ConfigDict] = {'extra': 'forbid', 'use_enum_values': True, 'validate_default': True}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- class calute.types.tool_calls.ToolChoice(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]#
Bases:
StrEnumEnum of tool choice types.
- auto#
Automatically choose the tool.
- none#
Do not use any tools.
- any#
Use any tool.
Examples
>>> tool_choice = ToolChoice.auto
- any = 'any'#
- auto = 'auto'#
- none = 'none'#