Bypass a reducer and write the wrapped value directly to a BinaryOperatorAggregate channel.
Receiving multiple Overwrite values for the same channel in a single
super-step will raise an InvalidUpdateError.
Brand-based type guard that recognises any StreamChannel
instance, even ones originating from a different copy of this
package. Prefer this over instanceof StreamChannel when code
may observe channels that were constructed elsewhere.
import { Annotation, StateGraph, Overwrite } from "@langchain/langgraph";
const State = Annotation.Root({
messages: Annotation<string[]>({
reducer: (a, b) => a.concat(b),
default: () => [],
}),
});
const replaceMessages = (_state: typeof State.State) => {
return { messages: new Overwrite(["replacement"]) };
};