Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Cohere ai Cohere python ToolV2Function Model

From Leeroopedia
Revision as of 12:18, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Cohere_ai_Cohere_python_ToolV2Function_Model.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Knowledge Sources
Domains SDK, Tool Use, Function Calling, Pydantic Models
Last Updated 2026-02-15 14:00 GMT

Overview

Pydantic model representing the function specification within a V2 tool definition, including name, description, and JSON Schema parameters.

Description

ToolV2Function defines the function metadata for a V2 tool. It contains a required name field identifying the function, an optional description field explaining what the function does, and a required parameters field that holds a JSON Schema dictionary describing the function's input parameters. This model is referenced by ToolV2 (which wraps it under the function field with type="function") and is the primary way to declare tool capabilities when calling V2Client.chat() or V2Client.chat_stream(). The class extends UncheckedBaseModel with extra="allow" for forward compatibility.

Usage

Use ToolV2Function when building tool definitions for the Cohere V2 chat API. Each tool passed to the tools parameter of client.chat() should be a ToolV2 instance containing a ToolV2Function that describes the callable function's name, purpose, and parameter schema. The parameters field follows standard JSON Schema conventions (with "type", "properties", and "required" keys).

Code Reference

Source Location

Signature

class ToolV2Function(UncheckedBaseModel):
    """The function to be executed."""

    name: str = pydantic.Field()
    description: typing.Optional[str] = pydantic.Field(default=None)
    parameters: typing.Dict[str, typing.Any] = pydantic.Field()

Import

from cohere import ToolV2Function

I/O Contract

Fields

Field Type Required Default Description
name str Yes (none) The name of the function.
description Optional[str] No None The description of the function.
parameters Dict[str, Any] Yes (none) The parameters of the function as a JSON schema.

Configuration

Setting Value Description
extra "allow" Permits additional fields not defined in the schema, ensuring forward compatibility.
smart_union True Pydantic V1 only: enables smart union type resolution.

Usage Examples

from cohere import ToolV2, ToolV2Function

# Define a tool with a ToolV2Function specification
tools = [
    ToolV2(
        function=ToolV2Function(
            name="get_weather",
            description="Get the current weather for 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"],
                        "description": "Temperature unit",
                    },
                },
                "required": ["location"],
            },
        )
    ),
]

# Pass tools to V2 chat
response = client.chat(
    model="command-a-03-2025",
    messages=[{"role": "user", "content": "What is the weather in Boston?"}],
    tools=tools,
)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment