The Anatomy of an AI Agent: Five Parts and the Framework That Wires Them Together
The Anatomy of an AI Agent: Five Parts and the Framework That Wires Them Together
AI 智能体的解剖学:五个核心组件与连接它们的框架
Ask a language model to book you a table for six this Thursday and it will do something quietly maddening. It will explain, fluently and with total confidence, exactly how one might book a table for six this Thursday. Then it will stop. Articulate, helpful, and unable to lift a finger. That gap between knowing and doing is the whole difference between a chatbot and an agent.
如果你让一个语言模型帮你预订本周四六个人的餐位,它会做出一种让人抓狂的举动。它会流利且极其自信地向你解释预订餐位的具体步骤,然后就停下了。它表达清晰、乐于助人,却无法采取任何实际行动。“知”与“行”之间的鸿沟,正是聊天机器人与智能体(Agent)的本质区别。
And the reason for the gap is blunt: a language model can only ever produce text. It cannot click a button, run a program, remember yesterday, or wait for your approval. So an agent is not a smarter model. It’s a model surrounded by parts that cover what it can’t do — and, just as importantly, a framework that wires those parts together and runs them. That second half is the part most explanations skip. You can read ten articles listing “the components of an agent” and still have no idea how they actually connect. So here’s the plan: meet the five parts, then meet the thing that binds them. If the parts are organs, the framework — LangChain being the best-known — is the nervous system that turns a pile of organs into a body that can act.
造成这种鸿沟的原因很直接:语言模型只能生成文本。它无法点击按钮、运行程序、记住昨天发生的事,也无法等待你的批准。因此,智能体并不是一个更聪明的模型,而是一个被各种组件包围的模型,这些组件弥补了它无法做到的事情——同样重要的是,还需要一个框架将这些组件连接起来并驱动它们运行。大多数解释都忽略了后半部分。你可以阅读十篇列举“智能体组件”的文章,却依然搞不懂它们是如何连接的。所以,我们的计划是:先认识这五个部分,再认识连接它们的纽带。如果说这些组件是器官,那么框架(LangChain 是其中最著名的)就是神经系统,它将一堆器官变成了一个能够行动的生命体。
1. The Brain: the LLM
1. 大脑:大语言模型 (LLM)
At the center sits a large language model, the same family of technology behind ChatGPT and Claude. This is where understanding and judgment live. It reads the request, thinks it through, and decides what should happen next. By a wide margin, it is the smartest thing in the room. It also cannot do a thing. Left alone, the model — whether it’s OpenAI’s GPT, Anthropic’s Claude, Google’s Gemini, Meta’s Llama, or Mistral — is the brilliant colleague locked in a room with no phone. On each turn it does exactly one thing: it’s handed the story so far as text and asked “what next?”, and it replies with either a finished answer or a request to use a tool. It never acts. It only decides and describes. Everything else in this article exists to carry those decisions out into the world and bring the results back — and the framework is what does the carrying.
核心是一个大语言模型,即 ChatGPT 和 Claude 背后的同类技术。这是理解力和判断力的所在地。它读取请求、进行思考,并决定下一步该做什么。在整个系统中,它是最聪明的部分,但它什么也做不了。如果孤立存在,无论它是 OpenAI 的 GPT、Anthropic 的 Claude、Google 的 Gemini、Meta 的 Llama 还是 Mistral,它就像一个被锁在没有电话的房间里的天才同事。在每一轮交互中,它只做一件事:接收到目前的对话文本,被问及“接下来做什么?”,然后回复一个最终答案或使用工具的请求。它从不直接行动,只负责决策和描述。本文提到的其他所有内容,都是为了将这些决策付诸实践并将结果带回——而框架正是负责执行这些“搬运”工作的角色。
2. The Hands: skills and tools
2. 双手:技能与工具
Tools are the specific abilities you bolt onto the model: search the web, run code, send an email, query a database. Each is a door from thinking into doing. But notice the problem — the model can’t open a door, only ask for one. This is the first thing the framework does for you. You write an ordinary function and describe it in plain language; the framework advertises that description to the model as an available tool, and when the model replies “call search_web with query: ramen near Shibuya,” it’s the framework, not the model, that runs the real function and feeds the result back. Your tools sit on one side; the model only ever names them; the framework is the hand that reaches between. The reach of an agent is whatever is on that menu — for a sense of how much can be, browse a collection like this catalog of AI agent tools.
工具是你为模型安装的具体能力:搜索网页、运行代码、发送电子邮件、查询数据库。每一个工具都是从“思考”通往“行动”的一扇门。但请注意这个问题——模型无法打开门,只能请求开门。这是框架为你做的第一件事。你编写一个普通的函数并用通俗语言描述它;框架将该描述作为可用工具告知模型。当模型回复“调用 search_web,查询:涩谷附近的拉面”时,是框架(而非模型)在运行实际函数并将结果反馈回来。你的工具位于一侧,模型只负责命名它们,而框架则是连接两者的那只手。智能体的能力范围取决于菜单上的内容——想了解其潜力,可以浏览像 AI 智能体工具目录这样的集合。
3. The Notebook: memory
3. 笔记本:记忆
Here’s a fact that surprises people: the model remembers nothing between turns. Each call starts cold. So the “story so far” it reads every turn has to be handed to it, fresh, every single time — and holding that story is another of the framework’s jobs. The framework keeps a running transcript of the task: your request, each tool the model called, each result that came back. Before every turn it re-injects that transcript so the model can pick up where it left off. That’s short-term memory, and it’s why an agent’s second step can build on its first instead of forgetting it. Long-term memory is the same idea stretched across tasks — facts worth keeping, like your preferences, stored outside the conversation and pulled back in when relevant. When an agent “knows” a teammate is vegetarian, the framework fetched that fact and dropped it into the transcript so the model sees it as if it always knew. Without this thread, every turn is déjà vu.
一个令人惊讶的事实是:模型在每一轮交互之间什么都不记得。每一次调用都是从零开始。因此,它每一轮读取的“故事进展”必须每次都新鲜地提供给它——而保存这些记录正是框架的另一项工作。框架会维护一份任务的实时记录:你的请求、模型调用的每个工具、返回的每个结果。在每一轮之前,它会重新注入这份记录,以便模型能从上次中断的地方继续。这就是短期记忆,也是为什么智能体的第二步可以基于第一步进行,而不是将其遗忘。长期记忆则是将这一理念扩展到跨任务场景——将值得保留的事实(如你的偏好)存储在对话之外,并在需要时调取。当智能体“知道”某位队友是素食主义者时,是框架提取了该事实并将其放入记录中,让模型看起来像是早就知道一样。如果没有这条线索,每一轮交互都将是“既视感”(déjà vu)。
4. The Strategist: planning
4. 战略家:规划
Give a capable person a shapeless goal and the thing standing between them and paralysis is a plan. Planning turns “organize the team offsite” into a sequence: find venues, check dates, draft an invite, send it once you’ve approved. In an agent, planning isn’t a separate box that fires once. It’s that “what next?” decision, made again on every turn — reason a little, pick a tool, read the result, reason again. (You’ll see this pattern named ReAct, for reason and act.) And the reason it can happen repeatedly is the framework: it’s the framework that loops back to the model after every tool result and asks “what next?” once more, so the model can adjust — rerouting when the first restaurant turns out to be fully booked, because nothing is hard-coded and the next move is decided fresh each pass. Planning is what turns a pile of tools into a route; the framework is what lets the route be drawn one step at a time.
给一个有能力的人一个模糊的目标,让他们免于陷入瘫痪的就是计划。规划将“组织团队团建”变成了一个序列:寻找场地、确认日期、起草邀请函、在你批准后发送。在智能体中,规划不是一个只运行一次的独立盒子。它是每一轮都要做出的“接下来做什么?”的决策——推理一下、选择工具、读取结果、再次推理。(你会看到这种模式被称为 ReAct,即推理与行动)。它之所以能反复进行,是因为框架的存在:框架在每次工具返回结果后都会循环回到模型,再次询问“接下来做什么?”,这样模型就可以进行调整——比如当第一家餐厅订满时重新规划路线,因为没有任何东西是硬编码的,每一步的行动都是在每一轮中重新决定的。规划将一堆工具变成了一条路线,而框架则是让这条路线能够一步步绘制出来的保障。
5. The Co-pilot: human in the loop
5. 副驾驶:人在回路 (Human in the loop)
The last part is the one most often left off the diagram, and the one you’d miss the most: you. Its place in the machine is exact. Remember the hand-off — when the model asks for a tool, the framework runs it. Human-in-the-loop is a checkpoint the framework enforces on that step. For anything cheap and reversible, like a search, it runs the tool and moves on. For anything that spends money or can’t be undone, like book_venue, the framework pauses before executing, surfaces the pending call — “ready to book the $1,200 venue for Thursday, shall I go ahead?” — and waits. Approve and it runs; decline or edit and your reply becomes the next line in the transcript, which the model reads and adapts to. You’re not watching from outside. You’re a conditional step the framework fires only on the moves that carry weight.
最后一部分是图表中经常被遗漏,但你最不能缺少的部分:你。你在机器中的位置非常明确。还记得交接过程吗——当模型请求使用工具时,框架会运行它。“人在回路”是框架在该步骤中强制执行的一个检查点。对于搜索这类低成本且可逆的操作,它会直接运行并继续。但对于涉及金钱或不可撤销的操作(如预订场地),框架会在执行前暂停,弹出待处理的调用——“准备预订周四价值 1200 美元的场地,要继续吗?”——然后等待。批准后它才会运行;拒绝或修改后,你的回复将成为记录中的下一行,模型会读取并据此调整。你不是在旁观,你是框架仅在关键步骤中触发的一个条件性环节。
The framework: the wiring that makes it an agent
框架:赋予其智能体属性的连接线
Line the five parts up and you still don’t have an agent. They don’t touch. A model can’t run a tool; a tool can’t recall the transcript; the transcript can’t decide what to do next; you can’t approve a call nobody surfaced to you. Something has to connect them — pass each part’s output.
将这五个部分排列起来,你依然没有得到一个智能体。它们互不接触。模型无法运行工具;工具无法回忆记录;记录无法决定下一步做什么;你无法批准一个没人向你展示的调用。必须有某种东西将它们连接起来——传递每个部分的输出。