@langchain/langgraph
Version:
42 lines (41 loc) • 1.46 kB
JavaScript
import { ReducedValue } from "../values/reduced.js";
import { DeltaValue } from "../values/delta.js";
import { messagesDeltaReducer, messagesStateReducer } from "../../graph/messages_reducer.js";
import { z } from "zod/v4";
//#region src/state/prebuilt/messages.ts
const messagesValueSchema = z.custom().default(() => []);
const messagesInputSchema = z.custom();
const MessagesValue = new ReducedValue(messagesValueSchema, {
inputSchema: messagesInputSchema,
reducer: messagesStateReducer,
jsonSchemaExtra: {
langgraph_type: "messages",
description: "A list of chat messages"
}
});
/**
* **Experimental.** A messages state field backed by a `DeltaChannel`.
*
* A drop-in alternative to {@link MessagesValue} that persists only per-step
* message deltas (plus periodic snapshots) instead of the full accumulated
* history in every checkpoint blob. Useful for long-running threads where
* re-serializing the entire message list on each step is costly.
*
* @example
* ```ts
* import { StateSchema, MessagesDeltaValue } from "@langchain/langgraph";
*
* const State = new StateSchema({ messages: MessagesDeltaValue });
* ```
*/
const MessagesDeltaValue = new DeltaValue(messagesValueSchema, {
inputSchema: messagesInputSchema,
reducer: messagesDeltaReducer,
jsonSchemaExtra: {
langgraph_type: "messages",
description: "A list of chat messages"
}
});
//#endregion
export { MessagesDeltaValue, MessagesValue };
//# sourceMappingURL=messages.js.map