跳到内容

UNREACHABLE_NODE

LangGraph 无法识别到您节点之一的传入边。请检查以确保在构建图时添加了足够的边。

或者,如果您从节点返回 Command 实例以使您的图无边,您将需要在调用 addNode 时添加额外的 ends 参数,以帮助 LangGraph 确定您节点的目的地。

这是一个例子

import { Annotation, Command } from "@langchain/langgraph";

const StateAnnotation = Annotation.Root({
  foo: Annotation<string>,
});

const nodeA = async (_state: typeof StateAnnotation.State) => {
  const goto = Math.random() > .5 ? "nodeB" : "nodeC";
  return new Command({
    update: { foo: "a" },
    goto,
  });
};

const nodeB = async (state: typeof StateAnnotation.State) => {
  return {
    foo: state.foo + "|b",
  };
}

const nodeC = async (state: typeof StateAnnotation.State) => {
  return {
    foo: state.foo + "|c",
  };
}

import { StateGraph } from "@langchain/langgraph";

// NOTE: there are no edges between nodes A, B and C!
const graph = new StateGraph(StateAnnotation)
  .addNode("nodeA", nodeA, {
    // Explicitly specify "nodeB" and "nodeC" as potential destinations for nodeA
    ends: ["nodeB", "nodeC"],
  })
  .addNode("nodeB", nodeB)
  .addNode("nodeC", nodeC)
  .addEdge("__start__", "nodeA")
  .compile();

故障排除

以下方法可能有助于解决此错误

  • 确保您没有忘记在某些节点之间添加边。
  • 如果您从节点返回 Commands,请确保您正在传递一个 ends 数组,其中包含潜在目标节点的名称,如上所示。