@langgraph-js/sdk
Version:
The UI SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces
21 lines (20 loc) • 666 B
JavaScript
import { Annotation } from "@langchain/langgraph";
/**
* create state for langgraph
* @example
* export const GraphState = createState(createReactAgentAnnotation(), ModelState, SwarmState).build({
* current_plan: createDefaultAnnotation<Plan | null>(() => null),
* title: createDefaultAnnotation<string>(() => ""),
*});
*/
export const createState = (...parents) => {
return {
build: (state = {}) => {
return Annotation.Root(Object.assign({}, ...parents.map((p) => p.spec), state));
},
};
};
export const createDefaultAnnotation = (defaultValue) => Annotation({
reducer: (_, a) => a,
default: defaultValue,
});