Implementation:Cohere ai Cohere python ToolMessageV2 Model
Appearance
| 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.pyLines L1-32src/cohere/types/tool_content.pyLines L1-50src/cohere/types/chat_message_v2.pyLines 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 matchToolCallV2.id - content (
strJSON orList[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