AIMessageChunk#

class langchain_core.messages.ai.AIMessageChunk[source]#

Bases: AIMessage, BaseMessageChunk

Message chunk from an AI.

Pass in content as positional arg.

Parameters:
  • content โ€“ The content of the message.

  • kwargs โ€“ Additional arguments to pass to the parent class.

param additional_kwargs: dict [Optional]#

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.

param content: str | List[str | Dict] [Required]#

The string contents of the message.

param example: bool = False#

Use to denote that a message is part of an example conversation.

At the moment, this is ignored by most models. Usage is discouraged.

param id: str | None = None#

An optional unique identifier for the message. This should ideally be provided by the provider/model which created the message.

param invalid_tool_calls: List[InvalidToolCall] = []#

If provided, tool calls with parsing errors associated with the message.

param name: str | None = None#

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.

param response_metadata: dict [Optional]#

Response metadata. For example: response headers, logprobs, token counts.

param tool_call_chunks: List[ToolCallChunk] = []#

If provided, tool call chunks associated with the message.

param tool_calls: List[ToolCall] = []#

If provided, tool calls associated with the message.

param type: Literal['AIMessageChunk'] = 'AIMessageChunk'#

The type of the message (used for deserialization). Defaults to โ€œAIMessageChunkโ€.

param usage_metadata: UsageMetadata | None = None#

If provided, usage metadata for a message, such as token counts.

This is a standard representation of token usage that is consistent across models.

pretty_print() โ†’ None#
Return type:

None

pretty_repr(html: bool = False) โ†’ str#

Return a pretty representation of the message.

Parameters:

html (bool) โ€“ Whether to return an HTML-formatted string. Defaults to False.

Returns:

A pretty representation of the message.

Return type:

str

Examples using AIMessageChunk