跳到内容

LangGraph Studio 故障排除

Safari 连接问题

Safari 会阻止 localhost 上的明文 HTTP 流量。当使用 langgraph dev 运行 Studio 时,你可能会看到“Failed to load assistants”(未能加载助手)错误。

解决方案 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 --tunnel

该命令输出一个以下格式的 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 时,你可能会看到“Failed to load assistants”(未能加载助手)错误。

解决方案 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 --tunnel

该命令输出一个以下格式的 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"