import { ... } from "@langchain/core/messages";Default keys that should be preserved (not merged) when concatenating message chunks. These are identification and timestamp fields that shouldn't be summed or concatenated.
'Merge' two statuses. If either value passed is 'error', it will return 'error'. Else it will return 'success'.
Collapses an array of tool call chunks into complete tool calls.
This function groups tool call chunks by their id and/or index, then attempts to
parse and validate the accumulated arguments for each group. Successfully parsed
tool calls are returned as valid ToolCall objects, while malformed ones are
returned as InvalidToolCall objects.
The default text splitter function that splits text by newlines.
Filter messages based on name, type or id.
Immediately-invoked function expression.
Type guard to check if a value is a valid Message object.
Transforms an array of BaseMessage instances into an array of
StoredMessage instances. It does this by calling the toDict method
on each BaseMessage, which returns a StoredMessage. This function
is used to prepare chat messages for storage.
Transforms an array of StoredMessage instances into an array of
BaseMessage instances. It uses the mapV1MessageToStoredMessage
function to ensure all messages are in the StoredMessage format, then
creates new instances of the appropriate BaseMessage subclass based
on the type of each message. This function is used to prepare stored
messages for use in a chat context.
Merge consecutive Messages of the same type.
NOTE: ToolMessages are not merged, as each has a distinct tool call id that can't be merged.
Trim messages to be below a token count.
Convert from a standard data content block to a provider's proprietary data content block format.
Don't override this method. Instead, override the more specific conversion methods and use this method unmodified.
Utility function for ChatModelProviders. Parses a base64 data URL into a typed array or string.
Utility function for ChatModelProviders. Parses a mime type into a type, subtype, and parameters.
Base class for all types of messages in a conversation. It includes
properties like content, name, and additional_kwargs. It also
includes methods like toDict() and _getType().
Represents a chunk of an AI message, which can be concatenated with other AI message chunks.
Base class for all types of messages in a conversation. It includes
properties like content, name, and additional_kwargs. It also
includes methods like toDict() and _getType().
Represents a chunk of a message, which can be concatenated with other
message chunks. It includes a method _merge_kwargs_dict() for merging
additional keyword arguments from another BaseMessageChunk into this
one. It also overrides the __add__() method to support concatenation
of BaseMessageChunk instances.
Represents a chat message in a conversation.
Represents a chunk of a chat message, which can be concatenated with other chat message chunks.
Represents a function message in a conversation.
Represents a chunk of a function message, which can be concatenated with other function message chunks.
Represents a human message in a conversation.
Represents a chunk of a human message, which can be concatenated with other human message chunks.
Message responsible for deleting other messages.
Represents a system message in a conversation.
Represents a chunk of a system message, which can be concatenated with other system message chunks.
Represents a tool message in a conversation.
Represents a chunk of a tool message, which can be concatenated with other tool message chunks.
This function is used by memory classes to get a string representation of the chat message history, based on the message content and role.
Produces compact output like:
Human: What's the weather?
AI: Let me check...[tool_calls]
Tool: 72°F and sunny
This avoids token inflation from metadata when stringifying message objects directly.
Infers the content type for a specific message type from a message structure.
This utility type determines the appropriate content type based on the message structure's output version and the specified message type. The content type varies depending on the output version (see MessageOutputVersion)
Infers the content blocks for a specific message type in a message structure.
This utility type extracts the content block type that corresponds to a given message type from the message structure's content definition.
Infers the properties for a specific message type from a message structure.
This utility type extracts the properties object that corresponds to a given message type from the message structure's properties definition, and excludes the reserved "content" and "type" properties to avoid conflicts with the core message structure.
If the specified type is not defined in the message structure's properties, it returns a generic Record<string, unknown> type to allow for arbitrary properties.
Merges two content definition objects from message structures.
This utility type combines content definitions from two message structures, handling the merging of content block types for each message type. The merge logic follows these rules:
Merges two discriminated unions A and B based on a discriminator key (defaults to "type"). For each possible value of the discriminator across both unions:
Recursively merges two object types T and U, with U taking precedence over T.
This utility type performs a deep merge of two object types: