Skip to main content

Chat messages

We support 4 types of message objects:
  • SystemMessage: Instructions and context for the conversation
  • UserMessage: Messages from end users to the assistant
  • AssistantMessage: Responses from the AI assistant, potentially including tool calls
  • ToolMessage: Results from tools invoked during the conversation
Each message has a content field, which can either be a str or a list of Content objects with text and/or reasoning. We don’t support audio/image/video content yet. Each message also has an optional metadata field that can store additional structured information about the message as a dictionary.

Usage

The easiest way to convert a dict into a ChatMessage is to use parse_chat_message:
The function will automatically raise validation errors if the input message does not conform to the schema. You may also want to create messages manually:

Note on tool calls

There are two parts to a tool call:
  • On the AssistantMessage itself, the tool_calls field contains a list of ToolCall objects. These represent calls to various tools the agent has access to.
  • The ToolMessage object is the output of the tool, e.g. a list of files after calling ls.
Tool Call Agent Run Example For an example of parsing tool calls, check out the τ-Bench tab in the SDK ingestion guide.

ChatMessage module-attribute

Type alias for any chat message type, discriminated by the role field. This is the base message union used in Transcript and AgentRun contexts. For chat sessions, use DocentChatMessage instead.

DocentChatMessage module-attribute

Type alias for chat session messages with chat-specific assistant metadata.

BaseChatMessage

Bases: BaseModel Base class for all chat message types. Attributes:

text property

Get the text content of the message. Returns:

SystemMessage

Bases: BaseChatMessage System message in a chat conversation. Attributes:

text property

Get the text content of the message. Returns:

UserMessage

Bases: BaseChatMessage User message in a chat conversation. Attributes:

text property

Get the text content of the message. Returns:

AssistantMessage

Bases: BaseChatMessage Assistant message in a chat conversation. Attributes:

text property

Get the text content of the message. Returns:

DocentAssistantMessage

Bases: AssistantMessage Assistant message in a chat session with additional chat-specific metadata. This extends AssistantMessage with fields that are only relevant in Docent chat contexts Attributes:

text property

Get the text content of the message. Returns:

ToolMessage

Bases: BaseChatMessage Tool message in a chat conversation. Attributes:

text property

Get the text content of the message. Returns:

parse_chat_message

Parse a message dictionary or object into the appropriate ChatMessage subclass. This parses base messages without chat-specific fields. For chat sessions, use parse_docent_chat_message instead. Parameters: Returns: Raises:

parse_docent_chat_message

Parse a message dictionary or object into the appropriate DocentChatMessage subclass. This handles chat session messages which may include DocentAssistantMessage with citations and suggested_messages fields. Parameters: Returns: Raises:

Content module-attribute

Discriminated union of possible content types using the ‘type’ field. Can be either ContentText or ContentReasoning.

BaseContent

Bases: BaseModel Base class for all content types in chat messages. Provides the foundation for different content types with a discriminator field. Attributes:

ContentText

Bases: BaseContent Text content for chat messages. Represents plain text content in a chat message. Attributes:

ContentReasoning

Bases: BaseContent Reasoning content for chat messages. Represents reasoning or thought process content in a chat message. Attributes:

ToolCall dataclass

Tool call information. Attributes:

ToolCallContent

Bases: BaseModel Content to include in tool call view. Attributes:

ToolParam

Bases: BaseModel A parameter for a tool function. Parameters:

ToolParams

Bases: BaseModel Description of tool parameters object in JSON Schema format. Parameters:

ToolInfo

Bases: BaseModel Specification of a tool (JSON Schema compatible). If you are implementing a ModelAPI, most LLM libraries can be passed this object (dumped to a dict) directly as a function specification. For example, in the OpenAI provider:
In some cases the field names don’t match up exactly. In that case call model_dump() on the parameters field. For example, in the Anthropic provider:
Attributes: