UNPKG

@langgraph-js/pro

Version:

The Pro SDK for LangGraph - seamlessly integrate your AI agents with frontend interfaces and build complex AI workflows

20 lines (19 loc) 647 B
import { z } from "zod"; import { withLangGraph } from "@langchain/langgraph/zod"; import { MessagesZodMeta } from "@langchain/langgraph"; /** zod schema for agent state */ export const AgentState = z.object({ messages: withLangGraph(z.custom(), MessagesZodMeta).default([]), }); /** 合并两个 state,保证合并正确。messages 和 task_store 都会被合并 */ export const mergeState = (state, data) => { return { ...state, ...data, messages: [...state.messages, ...(data.messages || [])], task_store: { ...state.task_store, ...(data.task_store || {}), }, }; };