@langgraph-js/pro
Version:
The Pro SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces and build complex AI workflows
28 lines (27 loc) • 853 B
JavaScript
import { Annotation } from "@langchain/langgraph";
/**
* create state for langgraph, like python version
* @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));
},
};
};
/**
* 创建一个默认值注解
* @example
* const state = createState().build({
* current_plan: createDefaultAnnotation<Plan | null>(() => null),
* });
*/
export const createDefaultAnnotation = (defaultValue) => Annotation({
reducer: (_, a) => a,
default: defaultValue,
});