Base abstract message class.
Messages are the inputs and outputs of a chat model.
Examples include HumanMessage,
AIMessage, and
SystemMessage.
BaseMessage(
self,
content: str | list[str | dict] | None = None,
content_blocks: list[types.ContentBlock] | None = None,
**kwargs: Any = {}
)The contents of the message.
Reserved for additional payload data associated with the message.
For example, for a message from an AI, this could include tool calls as encoded by the model provider.
Examples: response headers, logprobs, token counts, model name.
The type of the message. Must be a string that is unique to the message type.
The purpose of this field is to allow for easy identification of the message type when deserializing messages.
An optional name for the message.
This can be used to provide a human-readable name for the message.
Usage of this field is optional, and whether it's used or not is up to the model implementation.
An optional unique identifier for the message.
This should ideally be provided by the provider/model which created the message.
Load content blocks from the message content.
Get the text content of the message as a string.
Can be used as both property (message.text) and method (message.text()).
Handles both string and list content types (e.g. for content blocks). Only
extracts blocks with type: 'text'; other block types are ignored.
As of langchain-core 1.0.0, calling .text() as a method is deprecated.
Use .text as a property instead. This method will be removed in 2.0.0.