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 ToolMessageV2 Model

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

Overview

Concrete Pydantic models for submitting tool execution results back to the chat API.

Description

ToolChatMessageV2 (role="tool") wraps tool results with the matching tool_call_id. ToolMessageV2 has tool_call_id and content (ToolMessageV2Content — either a JSON string or List[ToolContent] blocks). Used in the messages list alongside the assistant's tool call message.

Code Reference

  • src/cohere/types/tool_message_v2.py Lines L1-32
  • src/cohere/types/tool_content.py Lines L1-50
  • src/cohere/types/chat_message_v2.py Lines L73-88 (ToolChatMessageV2)

Signature

class ToolChatMessageV2(UncheckedBaseModel):
    role: typing.Literal["tool"] = "tool"
    tool_call_id: str
    content: ToolMessageV2Content

class ToolMessageV2(UncheckedBaseModel):
    tool_call_id: str
    content: ToolMessageV2Content

Import

from cohere import ToolChatMessageV2

Inputs

  • tool_call_id (str) — Must match ToolCallV2.id
  • content (str JSON or List[ToolContent]) — The result of the tool execution

Outputs

  • Updated messages list ready for next chat() call

Example

from cohere import ToolChatMessageV2, AssistantChatMessageV2
import json

# After tool execution, build the follow-up message list
messages = [
    # ... original user message ...
    AssistantChatMessageV2(
        tool_calls=response.message.tool_calls,
        tool_plan=response.message.tool_plan,
    ),
    ToolChatMessageV2(
        tool_call_id=tool_call.id,
        content=json.dumps({"temperature": 72, "condition": "sunny"}),
    ),
]

# Send back to get final response
final = client.chat(model="command-a-03-2025", messages=messages, tools=tools)
print(final.message.content[0].text)

Related

Page Connections

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