跳到内容

LangGraph Studio 故障排除

Safari 连接问题

Safari 会阻止 localhost 上的纯 HTTP 流量。当使用 `langgraph dev` 运行 Studio 时,您可能会看到“未能加载助手”错误。

解决方案 1:使用 Cloudflare Tunnel

pip install -U langgraph-cli>=0.2.6
langgraph dev --tunnel
# Requires @langchain/langgraph-cli>=0.0.26
npx @langchain/langgraph-cli dev

该命令会输出一个以下格式的 URL

https://smith.langchain.com/studio/?baseUrl=https://hamilton-praise-heart-costumes.trycloudflare.com

在 Safari 中使用此 URL 加载 Studio。这里的 `baseUrl` 参数指定了您的代理服务器端点。

解决方案 2:使用 Chromium 浏览器

Chrome 和其他 Chromium 浏览器允许在 localhost 上使用 HTTP。无需额外配置即可使用 `langgraph dev`。

Brave 连接问题

当 Brave Shields 启用时,Brave 会阻止 localhost 上的纯 HTTP 流量。当使用 `langgraph dev` 运行 Studio 时,您可能会看到“未能加载助手”错误。

解决方案 1:禁用 Brave Shields

在 URL 栏中点击 Brave 图标,为 LangSmith 禁用 Brave Shields。

Brave Shields

解决方案 2:使用 Cloudflare Tunnel

pip install -U langgraph-cli>=0.2.6
langgraph dev --tunnel
# Requires @langchain/langgraph-cli>=0.0.26
npx @langchain/langgraph-cli dev

该命令会输出一个以下格式的 URL

https://smith.langchain.com/studio/?baseUrl=https://hamilton-praise-heart-costumes.trycloudflare.com

在 Brave 中使用此 URL 加载 Studio。这里的 `baseUrl` 参数指定了您的代理服务器端点。

图边缘问题

未定义的条件边缘可能会在您的图中显示意外的连接。这是因为如果未正确定义,LangGraph Studio 会假定条件边缘可以访问所有其他节点。为解决此问题,请使用以下方法之一明确定义路由路径:

解决方案 1:路径映射

定义路由器输出与目标节点之间的映射

graph.add_conditional_edges("node_a", routing_function, {True: "node_b", False: "node_c"})
graph.addConditionalEdges("node_a", routingFunction, { true: "node_b", false: "node_c" });

解决方案 2:路由器类型定义 (Python)

使用 Python 的 `Literal` 类型指定可能的路由目的地

def routing_function(state: GraphState) -> Literal["node_b","node_c"]:
    if state['some_condition'] == True:
        return "node_b"
    else:
        return "node_c"