# LangGraph × 知识图谱：让查询返回需要的结果

原作：Beyond MCP Servers: Why Network Automation Agents Need Knowledge Graphs — Shereen Bellamy，FOSDEM 2026。

来源：https://archive.fosdem.org/2026/schedule/event/VSW38B-beyond_mcp_servers_why_network_automation_agents_need_knowledge_graphs/
许可：CC BY 2.0 BE https://creativecommons.org/licenses/by/2.0/be/
许可证据：https://video.fosdem.org/2026/h1302/
本站节选原讲 07:44.400–14:39.360，增加中文译文、章节与学习界面。原作者和会议不为本站背书。译文与节选按同一许可提供。

英文来自大会自动转写；KAG、LangGraph、Cypher 等专名按演示画面校订。中文为本站辅助译文。

## 00:00:00.000

先看一张整体界面的截图。

Here's just a quick screenshot from very far away. What it looks like, the base, I will zoom in

## 00:00:06.400

后面我会放大，在同一个界面里展示我的改动。我在开发

later and show you what I did in the same UI. So the problem that I encounter while working with

## 00:00:12.640

coffeeAGNTCY 时遇到的问题，是 Agent 缺乏对基础设施的感知。

coffeeAGNTCY is that there is an issue of infrastructure awareness among the agents. If I asked

## 00:00:19.200

问“你有多少咖啡豆”这类简单问题，它能回答；

it a simple question, like how many beans do you have, then yeah, it'll answer, but sometimes

## 00:00:27.360

但再深入一点，比如“这笔订单为什么失败了”，

if I answered something that required a little bit more depth, why did this order fail?

## 00:00:38.400

它就说不清具体原因，或者返回一大段文字。

It wouldn't be able to tell me specifically why or it would give me a very long paragraph

## 00:00:45.920

结合自己的开发过程，我认为问题在于：

in response. What I decided the issues were, based on what I was going through, is that the context

## 00:00:53.280

上下文窗口很快被填满，因为每次查询基本上都把

window was filling up really fast because every query that I was sending in was basically giving

## 00:01:00.560

整张图塞了进去，返回的内容也远远超出所需。通常的

the whole graph and in turn returning way more than I needed. And that's because when in the typical

## 00:01:07.520

架构把所有推理都交给大模型，

structure, the LLM was doing all of the reasoning and because of that, it was talk, it was using

## 00:01:14.400

因此消耗了太多 token。研究怎么解决时，我发现

way more tokens than needed. So in my research of how to fix this issue, I learned a lot about

## 00:01:23.760

有人把图接入 MCP 服务，也有相应的参考应用。

folks adding graphs to MCP servers and reference applications that exist in that round.

## 00:01:30.240

例如，Anthropic 有知识图谱记忆的参考实现和 MCP 服务。

Anthropic has reference application for knowledge graph memories and an MCP server.

## 00:01:36.880

Neo4j 也有 MCP 服务。就像前面说的，很多工具

There's an MCP server for a Neo4j going to what I said earlier. There's an MCP server for a lot of

## 00:01:41.680

都有对应的 MCP 服务。具体到 IT 基础设施，LinkedIn

different things. But specifically when it comes to IT infrastructure issues, LinkedIn was able to

## 00:01:50.400

也曾通过把知识图谱与 MCP 服务结合，改善工单处理。

resolve their amount of tickets that were solved due to integrating knowledge graph with their

## 00:01:57.120

Cisco 同样有几个案例，利用这种方式

MCP server. And Cisco also has a couple of case studies to where they were able to do some

## 00:02:03.360

做深入的网络排障，并实现了 Jarvis。

deep network troubleshooting in that manner and they were able to implement Jarvis. And that's

## 00:02:08.720

回到我的问题。我把刚才那种情况叫作“尝试一”：

sorry. So given that, I'm going to call attempt one that issue that I spoke about, where the LLM

## 00:02:18.000

大模型接收大量 JSON，于是耗费很多 token。

is dumping all of this JSON and in return, I'm getting all of these tokens used up because

## 00:02:24.560

看这里的字符量，就知道负担有多大。如果不再像图中这样，

look how many characters are there, right? It's a lot to block. So what if instead of this situation

## 00:02:31.840

由主管 Agent 向 MCP 服务提问，再让 MCP 服务

here where you have the supervisor asking a question to the MCP server and the MCP server

## 00:02:37.920

直接把 JSON 交给大模型解析，而是由 MCP 服务直接回答呢？

clearing directly to the LLM to parse that JSON, what if the MCP server answered it directly?

## 00:02:44.800

虽然主题叫“超越 MCP 服务”，关键是怎样增强它，

So I know I said that the talk is beyond MCP servers, but the key is what can we do to enhance it?

## 00:02:52.240

不是说去年做了 MCP，今年就应该丢掉它。我不是这个意思。

Not, you know, we did MCP last year. Let's get over it this year. I'm not on that boat.

## 00:03:00.320

接下来是“尝试二”，也是我真正动手试的第一个改进：

So attempt two, which is my actual first attempt, is that looking at knowledge graph extraction,

## 00:03:10.240

参考其他公司的案例，研究知识图谱抽取，

because that's all of those case studies from different companies. I look more into knowledge graphs

## 00:03:14.800

以及 KAG、GraphRAG 这样的检索方法。

and I learned about retrieval mechanisms that were out there, like KAG and GraphRAG. So

## 00:03:24.800

KAG 吸引我的地方，是逻辑形式引导的推理

the reason why these both interested me was because KAG was a logical form of guided reasoning

## 00:03:31.040

和多跳问答。网络拓扑本身就有很多“跳”，

with multi-hop Q&A. So I figured network topology has a lot of hops and you get usually to solve

## 00:03:36.640

而我们需要通过查询解决问题，听起来很有用。GraphRAG

queries, so sounds useful, and then for GraphRAG, because it's known for extracting entities and

## 00:03:46.160

擅长从文本中抽取实体和关系。考虑到网络拓扑

relationships. Again, I just felt like because of that natural graph traversal kind of property

## 00:03:52.240

天然适合图遍历，我觉得可以先从这两种方法

that network topology is naturally have, these two would be a good place to start in terms of looking

## 00:03:57.840

入手，看看怎样抽取知识图谱。具体做法是：

out what it would look like if I could extract a knowledge graph. So what that procedure looked like was

## 00:04:06.000

收集 Lungo 的部署日志、以文本表达的网络图等资料，

I collected the Lungo deployment logs and network diagrams as text, all the information

## 00:04:11.760

分别交给这两种方法，生成知识图谱。然后

fed it into both approaches, and then I generated a knowledge graph. And with that knowledge graph,

## 00:04:17.440

用生成的图查询：哪些服务依赖 SLIM 网关？

I would just query different things like what services depend on the SLIM gateway, which is the

## 00:04:24.560

SLIM 就是前面提到的传输层。我发现 KAG 仍会漏掉一些隐含连接，

transport that I mentioned. What I found was that KAG was still missing some implicit connections,

## 00:04:33.040

即使它宣称更擅长多跳推理。因此，这次尝试并不理想。

even though they claim to be better at the multi-hopbing and stuff. So that wasn't a good idea.

## 00:04:40.240

GraphRAG 更擅长总结，但运行很慢，而且

And then for GraphRAG, it was better at summarizing, but it was very, very slow and it kept

## 00:04:49.680

不断重建拓扑，和“尝试一”遇到的问题类似。再往深处想，

rebuilding every topology, which is the same issue that I came across in attempt one. And take

## 00:04:56.320

这两种方法都是从文档里抽图，

it one step further, I learned that both of these are actually two extract graphs from documents,

## 00:05:04.000

而文档提供的是静态信息。Lungo 的网络

which are, you know, just deterministic static modes of information. So since Lungo's network

## 00:05:12.240

拓扑实际上已经是结构化数据，本来就保存在

topology is already structured data technically because it's already structured in that

## 00:05:16.160

JSON 里。为什么还要重复抽取已经有的结构？这就引出了最终方案：

JSON, why extract what we already have, which led me to my final attempt, which is having a graph

## 00:05:25.680

让 MCP 服务背后直接连接图。我创建了适配这张

backed MCP server. And what that looked like was I ended up creating my own MCP server specifically

## 00:05:34.320

知识图谱的 MCP 服务，并把图数据库接上。

compatible with that knowledge graph, but then I also attached a graph database to it.

## 00:05:46.160

后面会展开。目标是让 token 的使用量更贴近

So I'll get more into that, but the goal for this was to have the tokens more aligned with the

## 00:05:55.120

实际需要的输出，减少膨胀，直接遍历图，而不是把同一件事生成两遍，

output to reduce the token below, have a native traversal instead of generating the same thing twice

## 00:06:00.880

并且直接执行查询。比如主管 Agent

and having more direct queries. So I figure if we're in a situation where the supervisor has a

## 00:06:06.960

向服务提问时，服务直接运行 Cypher 查询，

question for the server, the server is running directly a query, a Cypher query, which is what you

## 00:06:13.200

遍历数据库，让主管 Agent 收到所需的信息。

can use to traverse the database, then the supervisor would receive exactly the right amount of tokens.

## 00:06:21.200

这是我采用的技术栈：编排用 LangGraph，

This is the proposed stack of what I used to do that. The orchestration was with LangGraph,

## 00:06:26.240

接口用 MCP 服务，检索用 Cypher，数据保存在

the interface through the MCP server, the retrievals through the Cypher, and the data is done with

## 00:06:34.720

Neo4j 知识图谱里。这里展示的是 Neo4j 中

a knowledge graph in Neo4j. This is what a knowledge graph in Neo4j looks like, and it's the visual

## 00:06:42.720

用于拓扑演示的图。因此，主要产物有两项：知识图谱，

for the topology demo. So again, the two big things that I generated, it's the knowledge graph

## 00:06:49.520

以及面向网络拓扑、提供多项功能的 MCP 服务。

and the MCP server was several different features that align with network topology.

