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 ToolV2 Definition

From Leeroopedia
Revision as of 12:18, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/Cohere_ai_Cohere_python_ToolV2_Definition.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Property Value
Type Implementation
Domain Tool Use, Function Calling, Pydantic Models
Source Cohere Python SDK
Last Updated 2026-02-15
Implements Principle:Cohere_ai_Cohere_python_Tool_Schema_Definition

Overview

Concrete Pydantic models for defining tool function schemas in the Cohere V2 API.

Description

ToolV2 has type (always "function") and function (ToolV2Function). ToolV2Function has name, description, and parameters (Dict representing JSON Schema). These are passed as the tools parameter to V2Client.chat() or chat_stream().

Code Reference

  • src/cohere/types/tool_v2.py Lines L1-24 (ToolV2)
  • src/cohere/types/tool_v2function.py Lines L1-36 (ToolV2Function)

Signature

class ToolV2(UncheckedBaseModel):
    type: typing.Literal["function"] = "function"
    function: typing.Optional[ToolV2Function] = None

class ToolV2Function(UncheckedBaseModel):
    name: typing.Optional[str] = None
    description: typing.Optional[str] = None
    parameters: typing.Optional[typing.Dict[str, typing.Any]] = None

Import

from cohere import ToolV2, ToolV2Function

Inputs

  • name (str) — The name of the tool function
  • description (str) — A description of what the tool does
  • parameters (Dict[str, Any]) — JSON Schema describing the function parameters

Outputs

  • List[ToolV2] ready for the chat API tools parameter

Example

from cohere import ToolV2, ToolV2Function

tools = [
    ToolV2(
        function=ToolV2Function(
            name="get_weather",
            description="Get the current weather for a location",
            parameters={
                "type": "object",
                "properties": {
                    "location": {"type": "string", "description": "City name"},
                    "unit": {"type": "string", "enum": ["celsius", "fahrenheit"]},
                },
                "required": ["location"],
            },
        )
    ),
]

Related

Page Connections

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