铺就通往生产环境之路:受治理的企业级 AI 智能体
Paving the Road to Production: Governed Enterprise AI Agents
原文由官网提供,中文由 GPT-6 Luna 翻译。相邻片段合并排版,正文与时间点保持对应。
已插入 23 张经核对的幻灯片或演示截图;点击图片可放大。图注链接为当前视频时间,左侧正文时间保留原转录版本,二者可能不同。
共 50 个阅读段落

大家好。我想带大家了解,我们如何让 AI 智能体从实验阶段过渡到真正的企业环境。开始之前,先简单介绍一下我自己。我叫 Harish Gaggar。我在 Intuit Credit Karma 担任高级资深软件工程师,负责构建并维护 AI 分析基础设施和服务。此外,我还是顾问、作者和研究人员,也是多个组织的项目委员会成员,并指导年轻研究人员。好。
Hello, everyone. I would like to walk you through that how we can transition in AI agents from an experiment to the real enterprise environment. So before I begin, a quick introduction about me. My name is Harish Gaggar. I'm a senior staff software engineer at Intuit Credit Karma, where I built and own the AI analytics infrastructure and services. And beside that, I'm advisor, author, researchers, and also a program committee members for various organizations where I mentor the young researchers as well. All right.

我们来看看今天的议程。首先,我们会谈谈构建 AI 智能体并将其部署到生产系统时会遇到哪些挑战,以及如何构建不同的框架来应对这些挑战。然后看看相应的架构是什么样的。接着讲讲如何构建自己的 MCP 服务器和 MCP 网关,以及如何在这个网关上进行监控。之后,我们还会谈谈可以采用哪些不同类型的智能体框架,以及一些额外框架,例如管理记忆、跟踪和评测,还会讲到如何在数据到达 LLM 之前拦截 PII,以及使用 Context Optimizer 节省 token。
So let's walk through the agenda here. So first, we would like to talk about what are the challenges we have when we build an AI agents and deploy into the production systems and how we can build a different framework to address that different challenges here. Then how the architecture looks like for it. Then how you can build your own MCP servers and MCP gateway. and then some monitoring on top of that gateway as well. Then further, we're going to talk about what are the different type of agent framework you can have and then some additional framework around managing the memories, tracking and eval, how you can block the PII data going before the LLMs, and then Context Optimizer to save your token.

那我们马上来看这些挑战。当然,许多智能体在生产环境中会失败,通常是因为缺少基础控制措施。关键原因是,大多数人没有设置网关,无法确保智能体通过网关先向正确的身份验证提供方完成身份验证,再被转发到正确的 MCP 服务器。第二,MCP 服务器缺少执行查询所需的正确工具。第三,我们有没有足够的跟踪和评估系统,确保发送给智能体的每个查询都被记录,并评估它们回复的质量?还有,我们有没有记忆管理系统?
So without delay, let me walk you through the challenge. Of course, there are many agents that generally get failed in production because their foundation controls are missing. And the key reason behind is that, you know, like most of the people are missing the gateway to make sure that the agent can, you know, communicate to the gateway to get authenticated first with the right auth providers so that they can redirect to the right MCP servers. Right. Second, that MCP servers are missing the right tool to execute your query. Third, do we have like enough tracking and evaluation system to make sure that every query when you are sending to the agents, whether they've been tracked or not, and are you evaluating their quality response or not? Right. Do we have any memory management system or not?
比如说,如果你与智能体长期互动,持续很多天,它能不能回想起你过去问过什么?另外,还有其他框架问题,比如有没有上下文优化器来节省 token?有没有足够的生产环境措施确保任何密钥都不会传给 LLM,也不会进入跟踪、追踪系统或记忆数据库之类的地方?还有很多悬而未决的问题。为了解决这些问题,我们不会,怎么说呢,在这个演示里造出一个神奇的智能体。我们要谈的是可以构建的不同框架,用来应对这些问题。
In terms of, let's say you are doing the interaction with agent for long or for many days, is it able to recall that what you have been asked in the past? Right. And then there are other framework, of course, like do you have a context optimizers to save the token? or do you have enough production in place to make sure that any secrets should not go into LLM or tracking or tracing or any memory DB or so, right? So a lot of open questions. So in order to resolve this, we are not going to, you know, like build a magical agent here in this demo. We're going to talk about like different framework that you can build to address this.
首先是智能体框架。这部分我们使用的是,
So first is the agent framework. This is where like we use the,

我们选择使用 LangChain 社区提供的 LangGraph 框架。它帮助我们根据用户问题构建特定任务的节点,也便于接入各种市场插件、技能和提示,确保智能体能根据查询高效作答。第二部分是构建 MCP 网关,确保智能体发起调用时,或者智能体通过服务账户发起调用时,都能安全地完成身份验证,接入这个 MCP 网关,然后被转发到正确的 MCP 服务器。
So like we choose to use the LangGraph framework, which is provided by LangChain community. This has helped us in building the task-specific node based on your questions, and which is easy to plug in any like marketplace plugins or skills and prompts to make sure that agents respond efficiently based on your query. Further, the second part is we are also building the MCP gateway to make sure that whenever agents make the call or any service account from that agent make the call, make sure that they are securely get authenticated to that MCP gateway and then get redirected to the right MCP servers.
第三是定制 MCP,也就是构建自己的 MCP 服务器,并配置好正确的工具来执行查询。最后,还要对实际执行的操作进行审计,对吧?然后我们会谈谈一些额外框架,例如如何拦截 PII 和密钥,如何把跟踪数据存到云端,以及如何保存记忆,尤其是每个上下文中的线程和检查点。还会讲如何整体优化上下文,确保运行查询时不会消耗太多 token。好,现在我们来谈谈智能体基础设施。首先,我们会介绍本地开发。整体做法应该是,
Third is the customized MCP, which means that you are building your own MCP servers with the right tool in place to execute your query. And then finally, some audit on top of what actually operation you're performing, right? And then we talk about some additional framework around, you know, like how you can block the PIA secrets, how you're going to store the tracking value into the cloud, and how you're going to purchase the memories, especially any threads and checkpoints on every context. And then also how you can optimize overall your context to make sure that you don't burn too many tokens when you run your query. All right. So we'll talk about now the agent infrastructure. So firstly, we'll go through the local development. The way the approach should be is that, you know, like

每当你构建一个智能体时,首先要把它注册到某个系统中。你通常要说明:“这是我的用例,这些用例会用于这个特定的业务领域或系统。”然后提交这些信息,系统会为你的智能体生成一个 ID。拿到 ID 后,你就可以使用开发者门户或内部门户,在里面录入所有详细信息,比如:“这是我的智能体用例,这是我的智能体 ID,这是我准备使用的框架,比如 LangGraph、LangChain 等,这是我准备使用的编程语言,比如 Python 或 TypeScript。”然后你可以选择自己的技能或提示。接着把信息提交给这个门户。
whenever you build an agent, right, first you have to register your agent into some system. You usually tell that, hey, look, this is my, the use case, and these are the use case going to use for this particular vertical or system. And you feed all those information and generate an ID for your agent, right? Once you have that, then you can have a dev portal, internal portal, where you You can ingest all the details saying that, hey, look, this is my agent use case. This is my agent ID. This is the framework I'm going to use, either LangGraph, LangChain or so. These are my language I'm going to use, either Python or TypeScript. And then you can choose, you know, like your skills or prompts. And then you submit your information, right, to this.
提交后,开发者门户会创建一个代码仓库,其中会包含的不只是智能体框架,比如 LangGraph 智能体框架,还会包含记忆框架、跟踪和评测框架,以及上下文优化框架和 PII 拦截 Web 框架。原因是并非所有开发者都会负责所有这些框架,对吧?他们可能只创建其中一部分框架,也就是 AI 助手工具通常一般会支持的那些框架,对吧?或者他们只采用一两个框架,对吧?
Once you submit this, the dev portal is going to create a repository, which is going to contains not just the agent framework like your LangGraph agent framework but is also going to contains your memory framework your tracking eval framework right and then your context optimizer framework and your PII blocking in web framework as well so the reason for that is because not necessarily all your developers are taking care of all this framework right they just sometimes create the framework what generally AI assistant tool are generally support, right? Or they stick to one or two framework, right?
所以我们只是想确保,推出这类框架时,它们能在整个公司保持一致,并且能够统一处理这些事情,集中到一个地方,这样你也能直观看到这些结果,对吧?拿到仓库后,开发者基本上会克隆这个仓库,然后构建自己的智能体,将其打包为 Docker 镜像并放进容器,再通过查询测试智能体的输入和输出。他们也可以用本地记忆进行测试,这里也许会用 Cloud Spanner 评估器。你还可以把跟踪数据存到某个数据库里,比如 SQLite 或 BigQuery,确保智能体在本地能完整运行。
So we just want to make sure that when you roll out such framework, make sure they are consistent across the company and they can take care of and they can be centralized in one place so you can visualize those results as well, right? So once you have that repository, so developers basically clone that repository, they can build their agent as a Docker image into containers and test their agent input and output through the query. And they can also test this on their local memory, maybe cloud spanner evaluator here. And you can also store this tracking in some of your DB, maybe SQLite or maybe BigQuery, to make sure that agents are fully working on your local.
智能体在本地跑起来之后,你就可以继续创建一个 PR。等 PR 获得两项审批后,
So once your agents are running in local, then you're ready to go ahead and generate a PR. And then once you get your two PR approval,

就会进入 CI/CD 流水线。PR 首先会把你的智能体注册到某个集中式智能体注册系统中;系统会为它提供一个 Langfuse URL,让你查看所有跟踪记录。然后 CI/CD 流水线会把你在本地构建的 Docker 容器构建到生产系统中。它会扫描镜像,确保不存在漏洞。如果一切正常并通过安全审批,就可以把这个镜像放回镜像仓库。
then it's go to the CI-CD pipeline. So the PR is basically going to, firstly, is going to register your agent into some centralized agent registry system, which provide a Langfuse URL to it to make sure that you see all the traces. And then the CI-CD pipeline is basically, you know, whatever the local Docker container you built here is going to build that container into production system. It will scan that image, make sure that there's no vulnerability. If everything looks great, security approved, you can move that image back into the registry.

此外,你还有自己的部署平台或编排平台,它会把智能体部署到 Kubernetes 集群指定的命名空间里。这里的好处是,这个门户不只是创建代码仓库。它还会创建一系列其他生产资源。例如工作负载身份、记忆数据库、跟踪和评测表,以及智能体密钥管理。也就是说,它会根据我们提供的名称创建这些不同资源,而不只是创建代码仓库。
Right. Further, you have your own deployment platform or orchestrator platform, which is going to deploy that agent into the Kubernetes cluster in a given namespace. Right. So the good part here is that this portal is not just creating the repository. Right. It also do create a bunch of other production resources. For example, the workload identity. Right. And then memory DB or tracking and eval tables and then agent secret management. Right. So it based on whatever the name we provide it, not just again, like not just repository, create all those different resources as well.

这样,当内部编排器部署智能体时,智能体已经知道自己应该使用哪个工作负载身份。这个绑定应该已经建立。因此,一旦完成 KSA 到 GSA 的绑定,智能体就能开始与所有这些资源通信。一切就绪后,智能体还会与其余端点服务通信,例如 AI 网关、MCP 服务器、用于追踪的 Langfuse,或其他 API 端点。接下来,我们先谈谈 MCP 服务器。前面已经讲了架构。
So what happened is when this internal orchestrator, when deploy the agents, the agent already know that, hey, what workload identity is supposed to work with. Right. That binding should already happen. So once this case to GSA binding happens, the agent will start communicating to all these resources. Once everything in place, agent is further going to communicate to the rest of your endpoint services, like, for example, AI gateway or MCP servers or Langfuse for tracing or some other API endpoints. So now, firstly, we talk about the MCP server as well. So we talk about architecture.
现在来看看不同组件。
Now we're going to the different component.

MCP 服务器当然可以使用外部已有的服务。但如果你在隔离网络环境中工作,强烈建议自己构建 MCP 服务器。好,定义我就不讲了。大家都知道。这里构建框架的方式是,你可以利用 FastMCP server 这个包或封装层来构建 MCP 服务器。然后可以在 FastMCP 封装层里创建不同的工具,以构建完整的服务器。你还要确保,定义 MCP 服务器时的每个工具都经过公司内部安全团队的全面审核,确保只有获准的工具才能进入生产环境。
So MCP server is something that you can definitely use, something which is outside available. But if you're working on air gap environment, it's highly recommended that you build your own MCP servers. So, yeah, and you can use the I will not go with the definition. Everyone knows about it. So the way the framework has been built here is that you can leverage the FastMCP server package or wrapper to, you know, build that MCP servers. and you can create a different set of tools inside that FastMCP wrapper to construct the overall servers. And then you make sure that every tool when you define an MCP server, they have to be fully reviewed by your own internal security team to make sure that only authorized tool can be go in production.
这样就能强制执行过滤、限制并屏蔽相关字段,避免那些其实不需要发送给 LLM 来获取信息的字段,或者避免泄露你无权获取的信息。第三,你当然还需要以这样的方式构建 MCP 服务器:当流量从 MCP 客户端经过 MCP 网关到达 MCP 服务器时,无论请求来自用户还是服务账户,都必须先在 MCP 网关完成身份验证,这样才能访问 MCP 工具并获取正确的信息。
And that's how you can enforce some filters, limits, and block the fills, which is really not required to go to LLM and get you the information, which is you're not supposed to get. And third part is, of course, you need to make sure that you build your MCP server in a way that whenever the traffic is coming from your MCP client to MCP gateway to MCP servers, either is coming from user or service account, they has to be authenticated to the MCP gateway first so that they can access your MCP tool to get that right information.

好,接下来讲网关部分,看看网关如何工作。如果你同样处于隔离网络环境,也可以自己构建内部 MCP 网关。它的工作方式是:你在使用本地代码辅助工具,或者自己的智能体。你第一次向智能体提交查询时,它会向 MCP 网关发送一次性身份验证请求。MCP 网关识别并接收你的请求。首先,它会把你的会话状态保存到 Redis。然后把 JWE 访问令牌返回给客户端。客户端收到 JWE 令牌后,就会知道要调用哪个 MCP 服务器。
All right. Now the gateway part. So the how the gateway works. So this is again, you can build it your own internal MCP gateway if you are again working on your air-gap environment. So the way it works is you are working on like local, you know, code assistance tool or maybe your agent. Right. So the moment you submit your first query to your agent, it will send that one-time authentication request to the MCP gateway. MCP gateway recognized and take your request. First, it will save your session state into the Redis. And then it will return back the JWE access token back to your client. Once client will receive that JWE token, it will know that what MCP server needs to call.
然后,它会在指定的命名空间提交工具调用请求,例如 /mcp,也就是说,比如 artifactory 或 github/mcp,并在请求中携带身份验证 Bearer 令牌。MCP 网关收到请求后,会识别要查找哪个命名空间,也就是哪个 MCP 服务器,然后解包 JWE 令牌,并把用户令牌附加到请求中,再将请求发送到相应的 MCP 服务器。MCP 服务器收到请求后,会向相应端点发起 API 调用,也就是调用对应服务的端点。然后交换这个 ID 令牌,并根据相应的权限范围返回结果,也就是用户获准查看的内容,对吧?
right so it will submit that tool slash call request on a given namespace slash mcp meaning let's say artifactory or github slash mcp with the auth bearer uh generally um token um into that so once mcp gateway um received that uh it will understand that what namespace meaning mcp server needs to look up for and then it will unwrap that jwe token and then it will attach that user token in that request and send it to the respective MCP servers. Now, once MCP server receives it, it will make that respective API calls to that endpoint of that, you know, to the service. And then it will exchange that ID token and return the response based on whatever scope that user is authorized to see, right?
用户收到令牌后,MCP服务器会解包所有数据,生成 MCP 网关能够接收的有效载荷,最后把最终有效载荷发回客户端,以便查看数据点。这说明,我们构建 MCP 网关,是为了提供一个集中的身份验证和路由枢纽,通过 MCP 网关和 MCP 服务器,将任何代码助手工具或智能体安全地连接到端点。任何端点都不应该允许直接访问。请求必须先经过 MCP 网关并完成适当的身份验证,然后才能到达 MCP 服务器和端点。
So once the user receives the token, you know, MCP server basically unwrapped all the data, make the payload which is compatible for MCP Gateway to receive, and then finally the final payload will send back to the client to see the data points. So what it shows is that, you know, like we build this MCP gateway to make sure that we have a centralized authentication and routing hub that securely connect any coding assistant tool or agents to the endpoint via this MCP gateway and MCP server. There should not be direct access provided on any endpoints. There has to go through the MCP gateway through proper authentications before they're reaching to the MCP server and the endpoints.
好。接下来是网关监控,对吧?前面我们讲了架构,
All right. So now the part is the gateway monitoring, right? We talk about, again, we talk about architecture,

也讲了 MCP 服务器和 MCP 网关。现在来讲监控。AI 智能体不能被信任,除非对它进行持续监控、评估并提供反馈,对吧?这就是我们构建 MCP 网关监控的原因。监控通常是这样工作的:每当你向智能体提交调用,它都会把所有操作日志发送到日志存储系统。你可以使用 ELK、Loki、CloudWatch 等。通常可以查询这类信息,比如:“显示我最近 10 分钟调用中所有 401 错误。”还可以查令牌刷新失败时发生了什么,对吧?这类请求都可以交给日志存储系统处理。
we talk about MCP server, MCP gateway. Now it's a monitoring. Again, the AI agent cannot be trusted without continuous monitoring, evaluation, and feedback, right? This is why we are building the MCP gateway monitoring. So the way the monitoring work is usually like the moment you submit any calls to your agent, it will send all the operation log into the log store. You can use ELK, Loki, or CloudWatch or so. And generally, this contains information like, show me all last 401s in my last 10 minutes call, right? And what did or do when the token refresh failed, right? So those kind of requests can go to the log store.
另外还有实时的跟踪和指标数据,也会发送到 OpenTelemetry。OpenTelemetry 是一个开源解决方案,用来收集所有跟踪和指标,并处理这些数据,再将数据转发到后端系统,对吧?在这个例子中,跟踪数据会发送到 Tempo。它也是一个开源解决方案,会存储所有跟踪数据,比如跟踪记录会包含这样的信息:这次请求中哪个工具响应很慢,调用来自智能体还是 IDE,这次失败调用的具体错误是什么,等等,对吧?
Now, there are some traces and metrics data, like real-time data that goes to the OpenTelemetry as well. OpenTelemetry, again, is open source solutions, which is going to collect all your traces and metrics and is going to process the data. and redirect to the backend system, right? And in this case, the traces will go to the Tempo. This is, again, an open source solutions, which is going to store all your traces in terms of, like, traces in the sense, like, you know, like, information around, like, which tool was slow on this request, whether this call is coming from agent or IDE, what was the exact error on this failed call or so, right?
这类数据会存储在 Tempo 中。哦,是我弄错了。好。至于指标,Prometheus 负责记录相关信息,比如某个工具的 P95 延迟是多少,对吧?某个时段的身份验证拒绝次数是否突然上升,对吧?这类指标会存储在 Prometheus 中。收集到跟踪和指标这些数据点后,所有聚合数据实际上会保存到 Grafana,供你……
So these kind of data are going to store into the Tempo. Oh, my bad. Okay. And then the metrics is about the Prometheus is all about the information about like what are P95 latencies for a given tool, right? Whether my auth rejection is spiking on a particular time or not, right? So those kind of metrics is going to store in Prometheus. So once you get all this data point like traces and metrics, this entire aggregate data back actually save into the Grafana for your

好,MCP 服务器、网关和监控都讲完了。现在来谈框架,也就是智能体框架。大多数情况下我们使用 LangGraph。LangGraph 再说一次,是由 LangChain 社区提供的。它提供基于图的架构,支持循环、分支和状态管理,适用于复杂的多智能体 AI 工作流,对吧?它的工作方式是,你提交第一个查询时,我们会先解读你的问题,判断它属于哪种问题,以及需要什么样的回答。
All right. So the MCP server, gateway and monitoring is covered. Now we're going to talk about the framework. So the agent framework, right? So we use LangGraph for most of the cases. and is basically LangGraph, again, it's provided by LangChain community. It's provided a graph-based architecture that support loops, branching, state management for complex multi-agent AI workflows, right? And the way it works is, the moment you submit your first query, we do interpret your question first, what type of questions it is and what response it's looking for.
然后据此制定计划,对吧?接着进入分类环节,判断这是不是单纯的读取操作,还是属于,怎么说呢,要进行修改的操作,或者你真的想删除某些内容,对吧?也可能是某种敏感操作。系统会据此调整整体结构,并相应地制定计划。下一步是规划。它本身其实就是一个子图,你会在其中衡量要执行的操作,也就是说,在计划阶段,一旦确定要执行什么操作,流程就会进入相应步骤,例如获取证据部分。
and based on that, it's create a plan, right? Then it will send for classify area where it will determine that, hey, whether it is just like a read operations or whether it is just like a, you know, modification level changes coming up or whether you really want to delete something, right? Or some sensitive operations. Based on that, it adjusts the overall structure and then plan accordingly. The next step is plan. It's actually itself is a subgraph where you do the measure of your operations, meaning that in the plan, like once you know what operation you're performing, it goes to the, like, let's say in a fetch evidence section
在那里,它会实际调用你在这里提出的具体问题;问题经过解读和分类后,它就会调用 MCP 网关,确保完成身份验证,然后调用 MCP 服务器,使用正确的工具获取数据,再生成相应的证据,对吧?验证所有发现之后,就会检查策略。它会检查这是不是只读操作;如果是,就继续执行,并把所有记录点保存到我们的审计日志中。但如果是写入操作或敏感操作,肯定会经过 HITL(人工参与审核)流程,等待审批。
where it actually call that, whatever the question you ask here, after all, interpret and classify, it actually go ahead and make the call to the MCP gateway, make sure they get authenticated, and then it make the call to the MCP server using the right tool and get the data and then generate that evidence, right? Once you validate all your finding, then it will check the policies. It will check whether it is a read-only, then go ahead and execute, and I will save all the record points into our audit logs. But if it is a write and sensitive operations, definitely it will go through the HITL process where you wait for an approval.
审批通过后,就继续执行。如果遭到拒绝,无论哪种情况,都会记录到审计日志中,对吧?
If it is approved, you go ahead and execute. If it is get rejected, in either case, it's going to save into the audit log, right?

把 MCP 网关、MCP 服务器和智能体结合起来,整体流程就是这样。最终,无论你构建什么智能体、提交什么调用,都要先到 MCP 网关进行身份验证。随后请求会被转发到正确的 MCP 服务器,由指定工具执行查询,再向相应端点发起 API 调用并获得响应。好,从基础设施角度来看,整体结构是这样的:智能体与 MCP 网关通信,再到 MCP 服务器,最后到端点。好,刚才我们谈了很多 MCP 网关、MCP 服务器和监控,也讲了智能体框架。现在我们来谈另外三四种框架,它们也是构建端到端生态系统时
So if we combine all this together, like MCP gateway, MCP server, and agent, this is how things looks like. So ultimately, whatever the agent you are building, whatever the call you are submitting, it will go to the MCP gateway for authentications. And then it will redirect to the right MCP servers to execute your query on a given tool so that it make the API call to that endpoint and get the response. right all right if it if we think from the infrastructure perspective this is how it looks like so agent is communicating to the mcp gateway goes to the mcp server and to the endpoint all right so now the we talked a lot about mcp gateway mcp servers um the monitoring um and the agent framework now we talk about uh three and four additional framework that we should

需要考虑的。第一种是智能体记忆管理。它基本上是一种流程,可以随时间保存和恢复工作流状态,确保每次查询运行都能持久保存,并顺利恢复。它的工作方式是:每当你向智能体提交查询,系统实际上会创建一个线程,对吧?在线程中提出第一个问题时,系统会为其创建一个运行 ID。你继续提出更深入的问题时,流程会进入 LangGraph 中的某个节点,并执行查询。
have to take care of when building the end-to-end ecosystem, right? One is them is agent memory management. Again, it's basically a process where you can save and restore the state of your workflow over the time, right? Ensuring that it's provide you a durability and seamless recovery across your every query run. So, the way it work is like whenever you submit any query to your agent, it actually generate a thread, right? On that given thread, when you ask your first question, it will going to create a run ID for that. So the moment you ask some deeper questions, it will go on a particular node in that LangGraph and execute that query.
然后在该节点保存相应的检查点,对吧?如果你在同一个线程中提出后续问题,系统会创建另一个运行 ID。接着根据你的后续问题,进入特定节点,并在那里保存检查点,对吧?本地开发时,这些数据可以存到 SQLite 数据库,但在生产环境中,除非是在 GCP 环境,可以用 Cloud Spanner,至于其他数据库,Azure 和 AWS 上也有相应选择,对吧?我快速演示一下记忆功能。
And on that node, it's going to save that respective checkpoint here, right? Now, if you ask your follow-up questions on the same thread, it's going to create another run ID. And again, depend on your follow-up questions, it go to a specific node and save the checkpoint over there, right? And all this data for your local development, you can use the SQLite DB, but in production, unless in GCP, you can use Cloud Spanner and in respect to databases, you can use in Azure and AWS as well, right? So just walk you through the quick demo here on the memory.

比如说,我刚在本地构建了这个智能体,然后尝试在 SQLite 数据库上运行查询,看看里面有没有数据。一开始里面没有任何数据。现在我提交查询。你会看到返回了一条记录,上面写着:“这是我的线程 ID,这是我提出的问题,以及这条查询执行的确切时间。”现在,如果我再运行一个查询,看看指定线程中生成了多少条消息,可以通过继续运行查询来获取这些信息。对。
So for example, I have, you know, like just built this agent locally, And then, you know, trying to run this query on SQLite DB to see if there isn't data or not. So I'm just, you know, initially I don't have any data. Now I submit my query. You will see that I received the one record, which is saying that, hey, this is my thread ID. This is the question I have been asked and exact time, you know, when this query was executed. Now, if I run the next query to see that, hey, how many messages I've been produced on a given thread, you can get this information by running the further queries. Right.
现在,如果我想查看查询的所有元数据,可以再运行一次查询,查看详细信息,比如调用了多少个工具、线程 ID、运行 ID,以及其他信息。如果我还想查看运行这条查询时执行了哪些工具,也可以看到相应 MCP 服务器上具体的工具名称。接下来,我还想看看 LangGraph 框架中的执行进度。也可以在记忆数据库上运行这类查询来查看。你会看到实际运行这条查询时调用的不同节点。
Now, if I would like to run to see that, you know, like all the metadata level information on my query, I can run my query again and you can see the detail description around, you know, like how many tool I get invoked, what is my thread ID, what is my run ID, you know, like and all those informations. Now, if I want to also see that, hey, what tool have been executed when I run this query, you can go ahead and see the exact tool name as well on that given MCP servers. Now further, I also want to see that how the progression was happened on my LangGraph framework. That also you can see by running this type of query on your memory DB. You can see that here like different kind of nodes been called when actually that query has been run.
好。
All right.

接下来是跟踪和评测。先澄清一下,免得大家混淆。前面我们讲的是 MCP 网关监控,这里讲的是智能体层面的跟踪。我们这样做,是因为确实想跟踪你向智能体提交了什么查询,返回了什么响应,使用了什么 LLM 模型,token 的成本是多少,消耗了多少 token,以及评测标准是什么样的,回复质量如何,等等,对吧?所以从第一天起就要存储这些数据。想象一下,如果你有 1000 多个智能体,每个智能体都会有自己的跟踪和评测项目及数据表,对吧?
Now the tracking and eval. So just to make sure that there is no confusion here. like we talked about earlier the MCP gateway monitoring, this is agent level tracking. So we do this because we really want to track that what query you have been submitting to the agent and what the response is coming, what LLM model you have been used, what's the cost of your token, how many token you have been burned and what's your evaluation criteria looks like, what is the quality of your response or not, right? So you need to store that data from the day one And imagine that if you have a thousand plus agent, every agent will have their own, you know, agent tracking and eval project and the tables, right?
比如说,如果有 100 个智能体,就会有 100 个不同的项目,每个项目都有各自的跟踪和评测表。六个月后,如果有人问你的智能体表现如何、回复是什么、质量如何、消耗了多少 token,你就可以汇总所有这些数据,并据此创建高管仪表板,查看
So if you combine, let's say if you have 100 agents, you will have 100 different projects and each project has their own respective tracking and eval tables. Now, tomorrow, six months down the line, if somebody asks you that how your agent has been performed, what was the response, what was the quality, how much token you've been born, you can aggregate all this data and you can create executive dashboards around it to see

构建这么多智能体的投资回报率(ROI)是多少。下面我来演示一下跟踪和评测。这里先看一下,首先你会看到,这里列出了 6 张表,其中一张是作业跟踪表,它包含大部分信息,比如查询内容、回复内容等。还有其他一些表,记录质量相关信息、工具调用、节点级执行情况等等。这次我会先向智能体提交第一个查询。刚开始你会发现没有数据,因为需要一点时间。
what is the ROI in building so many agents. So let me walk you through the tracking and eval demo here. So here, like if I look at this one, so first, like, you know, like if you see that there are six tables are listed here, one is a job tracking table, and which is contains most of this like information around what query, like what is your query, what's the response and everything. And there are a bunch of other tables as well, like your quality related and your tool invocations and then node level executions and all that. So in this case, I'm going to submit my first query on my agent, and you will see that there will not be any data in the first place because it takes some time.
我再刷新一下。这次刷新后,你会看到,对于某条查询,我能看到请求 ID、会话 ID、智能体名称、提出的问题,以及该问题的输出,它是否已经完成,耗时多久,使用了什么模型,以及一些元数据信息。再来看看质量数据,每次运行会有 8 项质量检查。
So I will refresh this again. And this time I will see that when I refresh, I do see that for a given query, I get my request ID, my session ID, my agent name, you know, what question I've been asked, and what was the output of that question, whether it has completed or not, and then what is the time it took, what is the model I've been used, and then some of the metadata-level informations. Further, if I look for the quality, again, there is eight quality checks per run.

你可以看到这一行记录,每项对应一项检查,例如成功情况、延迟和成本,工具准确性、安全性等等,这些数据都存储在这里。再看评测分数,每次运行会有一行记录。这是该次运行的评分表,分数介于 0 到 1 之间,用一行记录所有质量维度的得分。接着看质量指标,它会深入展示某次运行的情况。基本上,一行宽表中会用嵌套字段记录回复质量、安全性、延迟、成本和工具统计信息。接下来是工具调用。
And you can see that this one row, each for success, latency cost, tool accuracy, safety, et cetera, Like all this has been stored here. Right. Now, the Eval scores, this is again, this is going to be a one row. This is going to be a scoreboard for your given run, which is basically varies between zero to one, which is scores, you know, like all the quality dimension in a single row. Right. Now the quality metrics. So, again, it's a deep dive on that particular one run. Basically, a nested field for the response, quality, safety, latency, cost, and the tool stat in one wide row. Now, the tool invocation.
每次工具调用都会记录运行了哪个 MCP 工具、耗时多久,以及是否成功。
So, every tool call, which MCP tool ran, how long it took, and whether it succeeded or not.

然后是智能体工具轨迹,它会按顺序记录本次运行的逐步过程、每次 LLM 调用和图状态,比如规划、总结等。
And now, the tool agent trajectory, which is talking about step-by-step story of the run, each LLM call, and the graph state in order, like plan, summarize, et cetera.

好。接下来是智能体中的 PII 处理。这非常重要,因为使用智能体时,有时查询中可能会包含输入进来的密钥。比如你上传了一份包含敏感信息的文档。有时你输入内容时,也可能带上 API 密钥之类的信息。因此,我们有一个框架,用来定义不同的数据类型及其严重程度。如果严重程度超过 90%,我们就会立即拦截并遮蔽密钥,确保密钥绝不会传给 LLM 模型。对。
All right. So now. The next is the agent PIA treatment. This is very, very important because many times it happens that when you're working in agents or this thing, sometimes there is a possibility that there are some secret being ingested as a part of your query. Let's say you are uploading some doc, which has some sensitive information. And sometimes while typing, you may have some API keys or so. So we have a framework which defines that different sort of data types and their severity level. If your severity is above 90 percent or so, we will block and redact that secrets immediately so that make sure that that secret is never goes to LLM models. Right.
它既不会进入记忆数据库,也不会进入跟踪和评测表或追踪系统。这里的目标是,在传感数据被摄入的那一刻,也就是你输入它时,立即将其拦截。
Neither it will go to your memory DB, nor it will go to tracking and eval tables or tracing systems as well. So the goal here is to just block this sensor data as it is the moment it gets ingested, the moment you type.

最后一个框架是上下文优化器。这是我最喜欢的领域之一,因为每次提交查询时都非常重要,对吧?当你提交很多查询时,有时会上传大量数据点和一堆文件、系统内容之类的东西,对吧?这时非常重要的一点是,每次查询都要尽量节省 token。因此我们构建了上下文优化框架,在发送给 LLM 之前,先整理并裁剪查询内容。裁剪时,我们会根据 token 限额筛选有效载荷。然后重新排序,确定提交如此庞大的上下文时,哪些信息最相关、最值得关注。
The last framework is all about now is the context optimizer. This is one of my favorite areas where, like, you know, whenever you submit, it's very important, right? Whenever you submit too many queries, sometimes you upload a lot of the data points and you upload a bunch of files, systems or so, right? It's very important that time is, you know, like you make sure that you save your token in every query. So we build in context, optimize your framework where you actually shape your query and then you prune it before you go to LLM. In the pruning system, we do select the payload based on the token limit. Then we re-rank that, hey, which is the most relevant information that we should target for when you submit this huge, giant context.
接着去重,移除所有重复内容,形成一组独特且经过精心筛选的数据,也就是提供给 LLM 的核心数据。最后,在将这个大型有效载荷发送给 LLM 之前,我们会对它进行压缩。我们来看一下这个演示。很快就好。比如说,我先提交第一个查询。“帮我找出 JFrog Artifactory 中的所有制品。”你会看到,即使我还没有提交任何查询,这里也没有数据。我提交第一个查询后,再刷新这里的查询记录,就能看到新增了一条记录。你可以看到,使用了 24,000 个 token。
And then we dedupe that, remove all the duplicates and create a very unique set of very curated data, like, I mean, the main data for the LLM. And then we finally compress this large payload before it goes to the LLM. So let's see this demo here. This will be quick. So for example, let's say I will submit my first query. Hey, find me all the artifacts in my JFrog Artifactory. You see that first when even I no submitted any query yet, there is no data here. So the moment I submit this first query, and if I refresh my query here, and then you can see that the record has been added. So you can see there is a 24,000 token has been used.
我稍微往回看一下,给大家展示一下。你可以看到,这个问题用了 24,000 个 token。现在我在后台启用上下文优化器,再重新运行完全相同的查询。这次你会看到,对于同一个查询,刷新这次运行记录后,使用的只有 2,400 个 token。查询完全相同,几乎节省了 90%。我也可以在 Slack 机器人上重新演示一遍,我会问 Slack 机器人:“告诉我所有 Docker 镜像,涵盖 Artifactory 中的所有仓库。”
I will go back a little bit just to show the thing. So you can see this 24,000 token has been used for given questions. Now if I ask, now I enable the context optimizer behind the scene and I'm rerun the exact same query again. So this time you will see that, you know, for the same query, if I refresh this run and you will see that this time it used just 2,400 token. for the exact same query, which is almost like 90% saving. I can rerun the same demo on the Slack bot as well, where I'm asking Slack bot, hey, tell me all my Docker images across all the repositories in Artifactory.
运行这条查询时,还没有数据。现在我要提交查询。查询运行之后,我再在这里运行一次查询,你会看到创建了记录,这条查询同样用了大约 24,000 个 token。现在我会在后台打开优化器,再通过 Slack 机器人重新运行同一条查询。
When I run this query, there is no data. Now I'm going to submit my query. So once this query will run, and if I run my query again here, and you will see that record get created, it's again used like 24,000 for this particular query. Now, what I will do is I will turn on my optimizer behind the scene and I rerun the same query in the Slack bot.

然后再运行这条查询,会显示它只用了大约 1,500 个 token,同样节省了 90% 左右。大多数情况下,我们能节省 70% 到 78% 的 token。想象一下,如果你有成千上万个智能体,每天运行许多查询,通过这个框架能节省多少 token。
And then if I run this query again, it will show like it exactly used 1,500 almost token, which is again like 90% saving. In most of the cases, we get like 70 to 78% token saves. So imagine that you have thousands of, you know, like if you have thousands of like agents, which is running like, you know, many queries per day, imagine how much token you can save with this framework.

好,关键要点是:对我们来说,应该构建企业级框架,而不只是构建一个智能体。要确保底层具备所有这些框架。不要急着快速构建某个智能体,然后马上部署上线。确保整个系统经过所有这些框架的处理,这样才不会事后才意识到自己本来就应该一开始就把这些框架准备好。第二,要确保有完善的网关系统。每个工具调用请求,无论来自本地环境还是智能体,都必须经过某种集中式 MCP 网关。
All right. So now the key takeaway here is, you know, like for us is like make sure that we build an enterprise framework, not just an agent. Right. Which make sure that you have all the framework underneath. Don't try to be interested in building some agent quickly and deploy ship it. Make sure that it has to go through all the framework altogether so that you should not realize the literacy that, you know, I should have this framework in place. in the very first place. Second is make sure that you have a proper gateway system. Make sure that every tool called request, either you are doing this from your local or through agent, it has to go through some sort of centralized MCP gateway.
确保请求在到达 MCP 服务器之前完成身份验证。还要确保 MCP 服务器能控制应该使用哪个工具来执行特定查询。并确保为这些工具执行配置监控和完整审计。当然,每个操作事项和每个高风险事项都应该始终有人参与审核。确保具备可观测性和审计机制。最后一点,务必始终配置上下文优化器,以证明智能体的成本合理。对了,我还想分享一下,我最近在 Amazon 发布了我的 MCP 图书,大家可以免费下载 Kindle 版,也有纸质版。好,非常感谢大家观看这个视频。如果有任何问题,欢迎通过 LinkedIn 或 Twitter 联系我,我很乐意回答。
Make sure it's authenticated before it reaching to the MCP servers. And then make sure that your MCP servers take a control on what tool you should use to execute a particular query. And make sure that you have monitoring in place and complete auditing in place for that tool executions. And of course, you should keep the always human in the loop process for every action items, every high risk items. Make sure that there is an observability and auditing has to be in place. And last but not least, make sure that context optimizer should always be there to justify your cost on your agents. right um so just want to share is that i released my um mcp book recently on amazon so feel free to download it's free and kindle um and it's a hard copy is also available all right um thank you so much for watching this video um and if you do have any questions feel free to you know like reach out to me over linkedin or twitter i'm happy to answer