Jump to content

Connect Leeroopedia MCP: Equip your AI agents to search best practices, build plans, verify code, diagnose failures, and look up hyperparameter defaults.

Implementation:Cohere ai Cohere python ToolCallV2 Model

From Leeroopedia
Property Value
Type Implementation
Domain Tool Use, Response Parsing, Pydantic Models
Source Cohere Python SDK
Last Updated 2026-02-15
Implements Principle:Cohere_ai_Cohere_python_Tool_Call_Parsing

Overview

Concrete Pydantic models for tool call requests with auto-generated UUID support.

Description

ToolCallV2 has id (str, auto-generated UUID via overrides.py monkey-patch), type ("function"), and function (ToolCallV2Function with name and arguments as JSON string). The overrides.py make_tool_call_v2_id_optional patch modifies ToolCallV2 at import time to make the id field optional with a uuid4 default.

Code Reference

  • src/cohere/types/tool_call_v2.py Lines L1-26
  • src/cohere/types/tool_call_v2function.py Lines L1-20
  • src/cohere/overrides.py Lines L37-80

Signature

class ToolCallV2(UncheckedBaseModel):
    id: str  # Auto-generated UUID if not provided (via overrides.py patch)
    type: typing.Literal["function"] = "function"
    function: typing.Optional[ToolCallV2Function] = None

class ToolCallV2Function(UncheckedBaseModel):
    name: typing.Optional[str] = None
    arguments: typing.Optional[str] = None  # JSON-encoded arguments

Import

from cohere import ToolCallV2  # accessed via response.message.tool_calls

Inputs

  • V2ChatResponse with finish_reason == "TOOL_CALL"

Outputs

  • List[ToolCallV2] with id, function.name, function.arguments (JSON string)

Example

import json

response = client.chat(model="command-a-03-2025", messages=messages, tools=tools)

if response.finish_reason == "TOOL_CALL":
    for tool_call in response.message.tool_calls:
        func_name = tool_call.function.name
        func_args = json.loads(tool_call.function.arguments)
        tool_call_id = tool_call.id  # UUID for matching results
        print(f"Call: {func_name}({func_args}), id={tool_call_id}")

Related

Page Connections

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