Implementation:Cohere ai Cohere python AssistantMessage Model
| Knowledge Sources | |
|---|---|
| Domains | SDK, Chat |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
The AssistantMessage class is a Pydantic model representing a message from the assistant role that can contain text content, tool calls, and citations.
Description
The AssistantMessage model represents a message produced by the assistant in the Cohere chat API. It can contain structured content via the content field (of type AssistantMessageV2Content), a list of tool calls (of type ToolCallV2) when the model invokes tools, a tool_plan string containing chain-of-thought reasoning when working with tools, and a list of Citation objects linking generated text to source documents. This model extends UncheckedBaseModel and is auto-generated from the Cohere API definition by Fern.
Usage
Use this model when constructing chat history for the V2 chat API. It is used to represent prior assistant turns in a multi-turn conversation, including any tool invocations and citations that were part of the assistant's response.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/types/assistant_message.py
Signature
class AssistantMessage(UncheckedBaseModel):
tool_calls: typing.Optional[typing.List[ToolCallV2]] = None
tool_plan: typing.Optional[str] = pydantic.Field(default=None)
content: typing.Optional[AssistantMessageV2Content] = None
citations: typing.Optional[typing.List[Citation]] = None
Import
from cohere.types import AssistantMessage
I/O Contract
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
tool_calls |
Optional[List[ToolCallV2]] |
No | None |
List of tool calls made by the assistant during this turn. |
tool_plan |
Optional[str] |
No | None |
A chain-of-thought style reflection and plan that the model generates when working with Tools. |
content |
Optional[AssistantMessageV2Content] |
No | None |
Structured content of the assistant message (text or thinking items). |
citations |
Optional[List[Citation]] |
No | None |
List of citations linking generated text to source documents. |
Usage Examples
from cohere.types import AssistantMessage
# Construct an assistant message for chat history
assistant_msg = AssistantMessage(
content=[{"type": "text", "text": "The capital of France is Paris."}],
citations=None,
tool_calls=None,
tool_plan=None,
)
# Use in a multi-turn conversation with the V2 chat API
import cohere
client = cohere.ClientV2(api_key="YOUR_API_KEY")
response = client.chat(
model="command-r-plus",
messages=[
{"role": "user", "content": "What is the capital of France?"},
{"role": "assistant", "content": "The capital of France is Paris."},
{"role": "user", "content": "What is its population?"},
],
)
# Access the assistant message from the response
assistant = response.message
if assistant.tool_calls:
for tc in assistant.tool_calls:
print(f"Tool call: {tc}")
if assistant.tool_plan:
print(f"Tool plan: {assistant.tool_plan}")