Implementation:Cohere ai Cohere python AssistantMessageResponse Model
| Knowledge Sources | |
|---|---|
| Domains | SDK, Chat |
| Last Updated | 2026-02-15 14:00 GMT |
Overview
The AssistantMessageResponse class is a Pydantic model representing a response message from the assistant role with a role indicator and structured content items.
Description
The AssistantMessageResponse model represents the assistant's message as returned in a Cohere chat API response. It includes a fixed role field set to the literal value "assistant", a list of AssistantMessageResponseContentItem objects representing the content (which can be text or thinking items), optional ToolCallV2 entries for tool invocations, a tool_plan for chain-of-thought reasoning, and optional Citation objects. This model extends UncheckedBaseModel and is auto-generated from the Cohere API definition by Fern.
Usage
Use this model when processing chat API responses. It is the primary structure returned as the assistant's message in the response object, providing access to the generated text, any tool calls, and citations.
Code Reference
Source Location
- Repository: Cohere Python SDK
- File:
src/cohere/types/assistant_message_response.py
Signature
class AssistantMessageResponse(UncheckedBaseModel):
role: typing.Literal["assistant"] = "assistant"
tool_calls: typing.Optional[typing.List[ToolCallV2]] = None
tool_plan: typing.Optional[str] = pydantic.Field(default=None)
content: typing.Optional[typing.List[AssistantMessageResponseContentItem]] = None
citations: typing.Optional[typing.List[Citation]] = None
Import
from cohere.types import AssistantMessageResponse
I/O Contract
| Field | Type | Required | Default | Description |
|---|---|---|---|---|
role |
Literal["assistant"] |
No | "assistant" |
The role identifier, always set to "assistant".
|
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[List[AssistantMessageResponseContentItem]] |
No | None |
List of content items, each being either text or thinking content. |
citations |
Optional[List[Citation]] |
No | None |
List of citations linking generated text to source documents. |
Usage Examples
import cohere
client = cohere.ClientV2(api_key="YOUR_API_KEY")
response = client.chat(
model="command-r-plus",
messages=[
{"role": "user", "content": "Explain the theory of relativity."},
],
)
# Access the AssistantMessageResponse
message = response.message
print(message.role) # "assistant"
# Iterate over content items (text or thinking)
if message.content:
for item in message.content:
if item.type == "text":
print(f"Text: {item.text}")
elif item.type == "thinking":
print(f"Thinking: {item.thinking}")
# Check for tool calls
if message.tool_calls:
for tool_call in message.tool_calls:
print(f"Tool call: {tool_call}")
# Check for citations
if message.citations:
for citation in message.citations:
print(f"Citation: {citation}")