如何为 AI 智能体构建知识工厂
原题How to build a knowledge factory for AI agents
读前速览
为 AI 智能体构建知识工厂,需要收集、整理并维护组织知识,包括技能、领域知识和数据访问指南,让智能体能够正确执行任务,并通过反馈循环持续改进。
知识工厂是 AI 智能体从简单任务走向规模化应用的关键。
更好的模型和更多上下文固然有帮助,但企业级 AI 仍缺少一项关键要素:经过结构化整理、能说明组织如何运作的知识。它能帮助智能体正确完成复杂且细致的工作。
知识不同于上下文,应当能在不同任务中重复使用。
知识代表持久且可复用的理解,例如指标定义或公司政策;上下文则是针对特定任务的输入,会随每次交互而变化。
知识工厂通过智能体、策展智能体和存储系统之间的反馈循环运作。
智能体会标记知识缺口或错误,定期运行的策展智能体会审查执行轨迹和原始资料,以更新知识库;知识以策展智能体能够处理的灵活格式存储。
三类关键知识分别是技能、领域知识和数据访问指南。
技能涵盖符合公司标准的工作流程;领域知识包含有关产品、客户和政策的稳定事实;数据访问指南则告诉智能体到哪里查找当前数据,以及如何在 Snowflake 或 Salesforce 等系统中查询数据。
知识工厂借助智能体在真实场景中的使用实现持续改进。
通过观察智能体的执行轨迹并纳入人工反馈,知识库能够不断演进,将运营经验转化为更新后的技能,并减少未来的错误。
完整摘要
本文介绍了知识工厂这一系统化方法,旨在为 AI 智能体提供有效运作所需的组织知识。文章区分了上下文(智能体执行任务时掌握的信息)和知识(关于业务如何运作的可复用理解)。知识工厂包含三类知识:技能(完成工作的流程)、领域知识(核心业务事实)和数据访问指南(当前信息的查找方式)。文章还阐述了一个由反馈驱动的系统:智能体标记缺失或错误的知识,策展智能体通过审查执行轨迹和原始资料来维护知识库,知识则以灵活的格式存储。端到端示例展示了智能体如何在准备营收报告时使用并更新知识,体现了迭代改进的循环。
目录 · 6 节
要让 AI 真正为你的公司发挥作用,缺少的并不是更好的模型,也不只是更多上下文,而是更优质的知识——包括你的公司如何运作、有哪些运营标准,以及数据存储在哪里、如何访问。In order to make AI work for your company, the missing bit is not better models, it’s not just more context - it’s better knowledge. It’s knowledge of how your company works, what standards for operating you have in place, where data is stored and how it’s accessed.
效率最高的员工脑子里掌握着这些知识。他们知道该找谁沟通、去哪里寻找问题的答案,以及你们为什么要以某种特定方式做事。这些知识往往是默会的、隐性的、零散的——有时只存在于他们的脑海中,有时则散落在各种文档里。Your most efficient employees have this knowledge in their head. They know who to talk to, where to go to answer questions, why you do things in a particular way. That knowledge is often tacit, implicit, scattered - sometimes present only in their head, sometimes scattered across a variety of documents.
为了让 AI 为你的公司发挥作用,你需要收集、整理并维护一份知识表示,以便传递给智能体。帮助你完成这些工作的一套系统,我们称之为知识工厂。In order to make AI work for your company, you need to collect, curate, and maintain a representation of that knowledge to pass to agents. The system that helps you do that is what we’re calling a knowledge factory.
我们在 LangChain 以多种方式构建了这套机制。我们的内部 GTM 和内容工作室智能体由知识工厂提供支持。LangSmith Engine(我们的智能体,可分析 traces 并提出修复建议)也会为每个智能体维护一个知识工厂。这篇博客分享了我们的经验。We’ve built this at LangChain in a few ways. Our internal GTM and content studio agents are powered by a knowledge factory. LangSmith Engine (our agent that runs over traces and suggests fixes) maintains a knowledge factory per agent as well. This blog shares our learnings.
上下文与知识Context vs knowledge
上下文是代理执行任务时可用的信息。Context is what an agent has available when doing a task.
知识是我们保留并可重复使用的理解,能帮助我们正确完成这项任务:某项指标的含义、应信任哪个来源,或如何处理特定情况。有时会把这些知识记录下来,但更多时候不会。Knowledge is the reusable understanding we maintain so it can do that task correctly: what a metric means, which source to trust, or how we handle a particular situation. Sometimes written down, often not.
知识工厂将零散的文档和经验转化为知识,使其能够成为未来工作的背景信息。A knowledge factory turns scattered documents and experience into knowledge that can become context for future work.
因此,知识是智能体获取的一种上下文,但通常并不是(也不应该是)智能体获取的唯一上下文。其他类型的上下文,你已经能够可靠地接入并存储,也可以直接提供给智能体(参见下文关于快速变化数据的部分)。So knowledge is a form of context that the agent will get, but it’s often not (and shouldn’t be) the only context the agent gets. Other types of context you already ingest/store reliably, and that can just be provided directly to the agent (see the section on quickly changing data below).
从软件工厂到知识工厂From Software Factory to Knowledge Factory
软件工厂的理念在过去一年半中迅速兴起。这个理念认为,与其让最优秀的工程师亲自开发软件,不如让他们构建工厂(也就是系统),帮助公司里的每个人更高效地开发软件。软件本身则可以由智能体来构建。The idea of software factories has risen sharply over the past year and a half. The idea is that rather than having your best engineers actually build software, they should build the factory (the systems) to help everyone at the company build software more efficiently. The actual building of the software can be done by agents.
一般知识型工作如今也正沿着类似的路径发展。智能体已经足够胜任制作演示文稿、制作发布视频以及开展外联等任务。你应该尽可能多地让它们承担这些工作。但要完成这些任务,它们需要掌握所有那些隐性、未明说且分散各处的知识。General knowledge work is now following a similar path. Agents are good enough to make presentations, launch videos, do outbound. You should be leveraging them as much as possible for those tasks. But in order for them to accomplish those tasks they need all that tacit, implicit, scattered knowledge.
这才是你应该投入资源的地方。你需要积累这方面的知识,更重要的是,建立一套收集、筛选和维护这些知识的机制。这才能让你把更多通用知识类任务外包给智能体。That is where you should devote resources. You need to build that knowledge, and more importantly a factory to collect, curate and maintain that knowledge. That is what will let you outsource more general knowledge tasks to agents.
这些知识片段The pieces of knowledge
通常需要维护几方面的知识。There are generally a few pieces of knowledge you want to maintain.
- 如何开展工作——技能。按照公司预期的方式完成任务所需的流程、说明和脚本。How to do the work — Skills. Procedures, instructions, and scripts for accomplishing tasks the way your company expects.
- 业务如何运作——领域知识。关于你的产品、客户、竞争对手和组织的定义、政策和事实。How the business works — Domain knowledge. Definitions, policies, and facts about your products, customers, competitors, and organization.
- 在哪里获取最新信息——数据访问指南。应使用哪些数据源、数据分别存储在哪里,以及如何查询。Where to get current information — Data access guidance. Which sources to use, what data lives where, and how to query it.
技能:这是关于如何在公司内部“正确”做事的流程,也就是按照公司要求的特定方式完成任务的说明和脚本。很多时候,这些内容以前从未被写下来(而是由同事口口相传)。你应该努力把它们记录下来。Skills: these are procedures for how to do things “properly” inside your company. Instructions, scripts, for how to accomplish tasks in the particular way that your company requires. Often times, these were never written down before (instead passed coworker to coworker). You should strive to write them down.
领域知识:这类知识不太会频繁过时。它通常是关于人物、产品和竞争对手的核心信息。这些信息往往有记录,但由于知识量实在太大,记录通常并不完整(甚至有误)。Domain knowledge: this is knowledge that does not go stale frequently. It is often core information about people, products, competitors. This is often information that was written down - but was usually incomplete (or incorrect) just due to the sheer amount of knowledge here.
数据访问指南:你应该制定良好的数据策略(例如 Snowflake、Databricks 等)。这是打造实用智能体的基础。如果数据的唯一可信来源已经在这些平台上,而且数据完整且及时更新,就没必要再维护一份单独的副本。相反,你需要维护的是清晰的说明,明确数据存放在哪里以及如何查询。Data access guidance: You should have a good data strategy (Snowflake, Databricks, etc). That’s the foundation of useful agents. If the source of truth of data is there already, and it’s complete and up to date - there’s no need to maintain a separate copy. Rather, the new thing you’ll want to maintain is clear instructions on what data lives where and how to query it.
工厂的组成部分The pieces of the factory
所有这些信息都是构建实用智能体所必需的。不要试图手动维护这些信息——那会是一项艰巨的任务。相反,你需要建立一套维护机制。通常,这些组成部分如下:All of this information is needed for useful agents. Don’t try to maintain it manually - that’s a herculean effort. Rather, you will want to create a system for maintaining it. Generally, the pieces look like:
让智能体标记缺失知识的一种方法:了解哪些知识有所缺失,最好的方法之一就是让智能体在工作过程中进行标记。如果它们接到任务后找不到相关信息,或发现找到的信息有误,就应该将其标记出来!至少要为智能体提供一个工具,让它们能够报告错误之处;还可以选择让它们建议正确的更新内容。A way for agents to flag missing knowledge: One of the best ways to learn what pieces of knowledge are missing is to have agents flag it as they are working. If they are asked to do something, and can’t find information, or find information that they discover is wrong - they should flag it! Give the agent a tool to at a minimum report what is wrong, and optionally suggest the correct update.
策展代理:一种用于更新、整理和维护这些知识的代理:这些知识不应该靠人工手动维护更新——工作量太大。也不应该只靠使用这些知识的代理来维护更新——它们很擅长指出错误或缺失之处,但要修正这些问题,就需要深入理解底层知识和其他数据来源。让主要专注于实现自身目标的代理来妥善更新和维护这些知识,会导致知识体系变得杂乱无章、充满矛盾。相反,你需要一个在后台按一定周期运行、负责更新这些知识的策展代理。它应该能够访问所有原始数据来源(Notion、Slack 等),因为这些知识可能分散在其中。它还应该能够访问代理的执行轨迹,以便了解人们如何尝试使用代理,并将这些做法归纳为技能。它还应该能够访问代理标记为有误的内容(见上文)。The curator agent: an agent to update, curate, and maintain this knowledge: This knowledge should not be kept up to date manually - too much work. And it should not be kept up to date solely by the agents that use it - they are great at flagging what’s wrong or missing, but fixing it requires deep understanding of the underlying knowledge and other sources of data. Asking agents - who are mainly trying to accomplish their own goals - to properly update and maintain this knowledge will cause it to become unruly and full of contradictions. Rather - you will want a curator agent that runs in the background, on some cadence, to update this knowledge. It should have access to all the raw sources of data (Notion, Slack, etc) where this knowledge may be scattered. It should have access to agent traces, so it can see how people are trying to use agents and codify that into skills. It should have access to the things that agents have flagged as wrong (the above section).
知识的存储:从某些方面来说,这其实是最不重要的事情。你可以将这些知识以 skill 格式存储在 GitHub 中,存储在 Notion 的单个文件中,以 OKF 格式存储在 LangSmith Context Hub 中,或者存储在 Neo4j 的知识图谱中。策展代理应该知道如何与所有这些格式交互(这并不难)。但从另一方面来说,这又是探索最少的领域。我们该如何表示记忆?作为一个行业,我们在“程序性记忆”方面已经逐渐形成共识,采用 skills。对于更多语义记忆,可能会出现另一种标准(OKF?)。目前还处于早期阶段,尚未出现任何标准,因此最好不要对这种格式应该是什么样子规定得过于死板,也不要把它搞得过于复杂。Storage for the knowledge: In some ways, this is actually the least important thing. You can store this knowledge in skill format in GitHub. In a single file in Notion. In OKF format in LangSmith Context Hub. In a knowledge graph in Neo4j. The curator agent should know how to interact with all of these formats (not that hard). In other ways, this is the least explored area. How do you represent memory? As an industry, we’ve converged on skills for “procedural memory”. For more semantic memory, a different standard will likely emerge (OKF?). It is early and no standard has yet emerged - so it’s probably best to not be too prescriptive or overly complicate what this format should look like.
综合运用上述内容Putting it all together
最后,我们通过一个端到端示例来看看智能体如何准备收入报告。Let’s finish with an end to end example of an agent preparing a revenue report.
代理需要一些基础上下文:存储在 BigQuery 和 Salesforce 中的原始收入数据。There’s base context the agent will need: the raw revenue numbers, stored in BigQuery and Salesforce.
然后是知识。它可能包含几种不同的类型:Then there’s knowledge. It may consist of a few different types:
- 技能:如何以 LangChain 风格创建报告。这些内容以标准技能格式存储在 GitHub 中。Skills: how to create reports in LangChain style. These are stored in GitHub in the standard skills format.
- 长期有效的知识:我们计算 ARR 的方式。这些内容存储在公司内部 Wiki 中。Long duration knowledge: the way we calculate ARR. This is stored in a company wiki.
- 如何访问快速变化的知识:如何在 BigQuery/Salesforce 中访问这些原始数据。这些也只是以技能的形式存储,不过这次是在 Context Hub 中。How to access quickly changing knowledge: how to access that raw data in BigQuery/Salesforce. These are also just stored as skills, but this time in Context Hub.
代理运行时,可能会注意到我们在 BigQuery 中重命名了某个列。它会即时找出正确的列,并使用用于报告问题的工具标记此问题,同时建议正确的列名。The agent runs. Maybe it notices that we renamed a column in BigQuery. It figures out the correct column on the fly. It uses its tool it has to report issues to flag this, and suggest the proper column name.
生成报告后,我们的财务负责人会与智能体同步协作,修复一些格式问题,其中包括要求它使用一个新的页眉,而我们现在需要在所有 LangChain 文档中使用这个页眉。After it creates the report, our finance lead works synchronously with the agent to fix a few formatting issues, including telling it to use a new header we now need to use for all LangChain documents.
当晚,策展代理看到了这个被标记的问题。它还检查了该代理的执行轨迹,并注意到它与我们的财务负责人之间的这段来回交流。随后,它相应地更新了相关技能(在获取数据时使用新列,在起草报告时使用新表头)。That night, the curator agent sees the flagged issue. It also inspects the traces of the agent and notices this back and forth with our finance lead. It updates the relevant skills accordingly (to use the new column when fetching data, and to use the new header when drafting report).
结论Conclusion
目标并不是在智能体开始工作之前就把所有内容都记录下来,而是构建一个系统,让实际工作揭示缺少哪些知识,并通过填补这些空缺来改进今后的工作。从一个反复出现的工作流程入手,观察智能体在哪些环节遇到困难,并形成闭环。The goal isn’t to document everything before agents can start working. It’s to build a system where doing the work reveals what knowledge is missing, and resolving those gaps makes future work better. Start with one recurring workflow, inspect where agents struggle, and close that loop.
我们在 LangChain 构建了这项功能,目前正与几位客户合作,将其引入他们的智能体(内部和外部)。如果你对此感兴趣,请联系我们,我们很乐意提供帮助!We’ve built this at LangChain, and are working with a few customers to bring this to their agents (internal and external). If you’re interested in this - please reach out, we can help!