import { StateGraph, START, END, Annotation } from "@langchain/langgraph"; import { BaseMessage } from "@langchain/core/messages"; // 1. Define Agent State Annotation (March 2026 Fleet Standard) export const AgentState = Annotation.Root({ messages: Annotation({ reducer: (state, update) => state.concat(update), default: () => [], }), context: Annotation>({ reducer: (state, update) => ({ ...state, ...update }), default: () => ({}), }), }); // 2. Define Nodes (Placeholders for A2A Logic) async function reasoningNode(state: typeof AgentState.State) { // Bind MCP Tools to LLM here return { context: { reasoned: true } }; } async function toolNode(state: typeof AgentState.State) { // Wrap MCP Tools via @langchain/langgraph ToolNode return { messages: [] }; } // 3. Construct A2A Graph Workflow export function createAgentGraph() { const workflow = new StateGraph(AgentState) .addNode("reasoning", reasoningNode) .addNode("tools", toolNode) .addEdge(START, "reasoning") .addEdge("reasoning", "tools") .addEdge("tools", END); return workflow.compile(); // Optional: pass { checkpointer: new SupabaseSaver() } here }