领域深度 · 智能体Field guide · Agents
智能体:先写清它能做什么、不能做什么Agents: write down what it may and may not do
你让智能体“帮我处理工单”,它真的去查了订单、改了地址、发了一封邮件。演示时看起来很聪明,上线后问题才出现:它凭什么改地址?出错谁负责?能不能回放?先把任务、权限、状态和停止条件写清楚,再谈多智能体。You ask an agent to “handle the ticket”. It looks up the order, changes the address and sends an email. In a demo that looks smart. In production the questions arrive: who allowed the address change, who owns the mistake, and can we replay it? Write the task, permissions, state and stop conditions before talking about multi-agent systems.
- 智能体 = 模型 + 工具 + 状态 + 循环 + 权限,少一个都不算。An agent is model + tools + state + loop + permissions. Miss one and it is not one.
- 先限定一件事、一个负责人、一个完成定义。Start with one job, one owner and one definition of done.
- 能调用不等于该调用。每个工具单独开权限。Being able to call a tool is not permission to call it. Grant each tool separately.
完整版从下面开始;表格是查的时候用,不用背。The full guide starts below. Use the tables for reference; you do not need to memorise them.
假设一个具体活:每天从工单系统取 20 张单,判断是否退款,写回复,但发信前必须有人点确认。这条流程要能停、能查、能回放。Take one concrete job: pull 20 tickets a day, decide whether to refund, draft a reply, but require a human click before sending. The flow must stop, be auditable and replayable.
1 · 五个部件:模型、工具、状态、循环、权限1 · Five parts: model, tools, state, loop, permissions
模型负责提出下一步,工具负责改变外部世界,状态负责记住之前发生了什么,控制循环负责在合适的时候继续或停止,权限负责决定哪些动作根本不能做。五者缺一,智能体就会退化成「会调用函数的聊天」。The model proposes the next step, tools change the outside world, state remembers what happened, the control loop decides whether to continue or stop, and permissions decide which actions are forbidden. Remove one and the agent collapses into a chatbot that calls functions.
最容易被忽略的是权限。模型可以「想」做任何事,但系统只能让它「做」被明确授权的动作。把权限写在提示词里不算权限。权限必须由运行时代码、身份系统或审批流程执行。Permissions are the most overlooked part. A model may think about anything, but the system may only let it do explicitly authorised actions. Writing permissions in a prompt is not permission; they must be enforced by runtime code, an identity system or an approval flow.
| 部件Part | 回答的问题Question | 常见失败Common failure |
|---|---|---|
| 模型Model | 下一步做什么What next | 只会说,不会停Talks but does not stop |
| 工具Tools | 怎样改变外部世界How to change the outside world | 参数错、权限过大、返回不可信Wrong arguments, excessive permission, untrusted returns |
| 状态State | 之前发生了什么What happened before | 把旧状态当现在,或什么都没有记Stale state or no state at all |
| 循环Loop | 什么时候继续、重试、停止When to continue, retry or stop | 无限循环、重复写入、成本失控Infinite loops, duplicate writes, runaway cost |
| 权限Permissions | 哪些动作绝对不许做Which actions are forbidden | 提示词约束被绕过Prompt-level constraints bypassed |
2 · 任务边界:一件事、一个负责人、一个完成定义2 · Task boundary: one job, one owner, one definition of done
一个可上线的智能体,任务应该能用一句话说清:它读什么、做什么、产出什么、什么情况下停。任务越宽,越难判断它有没有做完,也越难限制它的副作用。A shippable agent should have a task describable in one sentence: what it reads, what it does, what it produces and when it stops. The broader the task, the harder it is to know whether it is done and to limit side effects.
每个任务要有一个人类负责人。负责人不是「出了问题再找的人」,而是事先定义完成标准、审批不可逆动作、决定什么时候停的人。没有负责人的智能体,出事时只会互相指认。Every task needs a human owner. The owner is not the person you call after something breaks; they define done criteria in advance, approve irreversible actions and decide when to stop. An agent without an owner produces blame, not accountability.
不可逆动作要单独列出:对外发送、付款、删除、发布、改权限、动生产数据。对这些动作,默认要人工确认。如果确实要自动执行,必须有额度、白名单、回滚和审计。List irreversible actions separately: sending externally, paying, deleting, publishing, changing permissions, touching production data. By default these require human confirmation. If they must be automated, they need limits, allowlists, rollback and audit.
3 · 工具与权限:能调用不等于该调用3 · Tools and permissions: can call does not mean should call
工具定义越模糊,模型越容易乱填参数。每个工具要写清:做什么、输入是什么、输出是什么、失败返回什么、是否幂等、是否会产生副作用。最好让工具在参数不合法时直接拒绝,而不是「猜一个」继续。The vaguer the tool definition, the more likely the model fills in wrong arguments. Each tool should state what it does, its input, its output, its failure return, whether it is idempotent and whether it has side effects. Tools should reject invalid arguments instead of guessing and continuing.
权限要按「身份 × 动作 × 对象 × 范围」授予。同一个智能体,读知识库和发外部邮件应该是两种权限。读一个项目和读所有项目也应该是两种权限。把工具权限收窄,比在提示词里写「不要乱来」有效得多。Grant permissions by identity × action × object × scope. For the same agent, reading a knowledge base and sending external email are different permissions; reading one project and reading all projects are different too. Narrow tool permissions is far more effective than writing “do not misbehave” in a prompt.
MCP、插件和第三方工具还是供应链。固定版本、核对来源、限制网络与文件访问、保留清单,和装一个依赖没有本质区别。工具越多,攻击面越大。先接一个真正需要的工具,比接十个「以后可能用得上」的更安全。MCP servers, plugins and third-party tools are also supply chain. Pin versions, verify sources, limit network and file access, keep an inventory — it is no different from adding a dependency. More tools mean more attack surface. Connect one tool you truly need before ten you might need later.
4 · 状态与记忆:先能回放,再谈长期记忆4 · State and memory: replay first, long-term memory later
状态不是「把聊天记录全塞进上下文」。至少要区分:本次任务的临时状态、跨任务的长期记忆、外部系统的真实状态。三者混在一起,智能体会把旧结论当现在,把猜出来的东西当事实。State is not stuffing the whole chat history into context. Separate at least: temporary state for this task, long-term memory across tasks, and the real state of external systems. Mix them and the agent treats old conclusions as current and guesses as facts.
先做可回放:记录每一步的输入、模型输出、工具调用、工具返回、审批和最终结果。回放不是为了「看日志」,而是为了在失败时判断是哪一步错了,以及能不能用同一输入复现。没有回放,评测和审计都无从谈起。Build replay first: record each step’s input, model output, tool call, tool return, approval and final result. Replay is not for “looking at logs”; it is for identifying which step failed and whether the same input reproduces. Without replay, evaluation and audit are impossible.
长期记忆要有写入规则、过期规则和删除规则。什么值得记、记多久、谁能读、如何纠错,都要在写入前想清楚。把所有对话永久向量化,既贵又容易把错误固化。Long-term memory needs write rules, expiry rules and deletion rules. Decide what is worth remembering, for how long, who can read it and how to correct it before writing. Permanently vectorising every conversation is expensive and freezes mistakes.
5 · 控制循环:继续、重试、停止都要有上限5 · Control loop: continuing, retrying and stopping all need limits
一个健康的循环至少有四道闸:最大步数、最大时长、最大成本、最大重试次数。没有上限的循环,会在工具反复失败时不断重试,或在模型反复「再确认一下」时烧掉预算。A healthy loop has at least four gates: maximum steps, maximum duration, maximum cost and maximum retries. Without limits, a loop keeps retrying when a tool fails repeatedly, or burns budget while the model “checks once more”.
重试要区分可重试和不可重试。网络超时可以重试。参数错误、权限拒绝、对象不存在通常不该重试。写操作还要幂等:同一个动作重复执行,不能产生两封邮件、两笔付款或两条记录。Distinguish retryable from non-retryable failures. Network timeouts can be retried; invalid arguments, permission denials and missing objects usually should not. Write actions must be idempotent: repeating the same action must not create two emails, two payments or two records.
停止条件要显式:任务完成、达到上限、需要人工审批、出现安全违规、或证据不足。最危险的不是「不会做」,而是「不知道已经该停」。Stop conditions must be explicit: task done, limit reached, human approval needed, safety violation, or insufficient evidence. The most dangerous state is not “cannot do it” but “does not know it should stop”.
6 · 评测:看任务、轨迹、工具和安全,不只看最终一句话6 · Evaluation: task, trajectory, tools and safety, not just the final sentence
智能体的评测不能只看最终答案。至少要记录:任务是否完成、步骤是否合理、工具调用是否正确、是否越权、成本多少、失败时是否安全退出。一个答案看起来对、但中间读了不该读的数据的 Agent,不能算通过。Agent evaluation cannot look only at the final answer. Record at least: whether the task was completed, whether the steps were reasonable, whether tool calls were correct, whether permissions were exceeded, the cost, and whether it exited safely on failure. An agent with a plausible answer that read data it should not have read has not passed.
先做固定任务集:同一批任务、同一套工具、同一环境、同一预算,重复跑。任务集要包含正常、边界、失败和恶意输入。只测顺风顺水的任务,上线后一定会在异常输入上出问题。Start with a fixed task set: same tasks, same tools, same environment, same budget, repeated. Include normal, edge, failure and adversarial inputs. Testing only happy paths guarantees trouble on abnormal inputs after launch.
上线前先影子运行:让 Agent 在真实输入上跑,但不执行副作用,只记录它会做什么。对比人工结果,统计「会做对」「会做错」「会越权」「会卡住」四类,再决定是否放权。Run in shadow mode before launch: let the agent process real inputs without side effects and record what it would do. Compare with human results across four buckets — would do right, would do wrong, would exceed permission, would get stuck — then decide how much authority to grant.
7 · 失败分支:先让系统停得住7 · Failure branches: make the system able to stop
智能体的失败往往不是「答错一句」,而是「做错一件事」。失败分支要按副作用分级:只读的可以重试,写入的要先检查再补偿,不可逆的要人工介入。Agent failures are often not a wrong sentence but a wrong action. Grade failure branches by side effect: read-only can retry, writes need check-then-compensate, irreversible actions need a human.
| 失败Failure | 先做什么First action | 不要做什么Do not |
|---|---|---|
| 工具报错Tool error | 分类:可重试 / 不可重试Classify: retryable / not | 无脑重试到上限Retry blindly to the limit |
| 循环重复Repeated loop | 停、记录轨迹、回到上一步Stop, record the trace, return to the previous step | 继续加提示词让它「聪明点」Add more prompt text to make it “smarter” |
| 部分写入Partial write | 查真实状态,补偿或回滚Check real state, compensate or roll back | 假设第一次没成功Assume the first write failed |
| 提示注入Prompt injection | 隔离内容与指令,降权,人工复核Separate content from instructions, reduce privilege, review | 把网页内容当系统指令Treat web content as system instructions |
| 成本失控Runaway cost | 触发预算闸,停止并报告Trigger the budget gate, stop and report | 先跑完再算账Finish first and count later |
8 · 最小落地路径8 · A minimum path to deployment
先做一条只读、单任务、可回放的流程。跑稳后再逐个加工具、加写权限、加自动化。每加一个能力,都要重新跑同一套任务集。Start with one read-only, single-task, replayable process. After it is stable, add tools, write permissions and automation one at a time. Every added capability must rerun the same task set.
- 写清任务、输入、输出、完成标准和不可逆动作。Write the task, input, output, done criteria and irreversible actions.
- 只接一个必要工具,定义参数、返回、失败和幂等性。Connect one necessary tool; define arguments, returns, failures and idempotency.
- 用运行时强制权限,不把权限写进提示词。Enforce permissions in the runtime, not in the prompt.
- 记录每一步,先做到可回放。Record every step; make replay possible first.
- 加步数、时长、成本、重试四道闸。Add four gates: steps, duration, cost, retries.
- 用固定任务集测正常、边界、失败和恶意输入。Test normal, edge, failure and adversarial inputs on a fixed task set.
- 影子运行,对比人工结果与越权率。Run in shadow mode; compare with human results and permission-violation rate.
- 小范围放权,保留人工审批与一键停。Grant authority gradually; keep human approval and a stop button.
来源与延伸阅读Sources and further reading
以下链接用于核对事实、许可证与官方口径。外部页面可能更新;引用时以原文与核验日为准。These links are for checking facts, licences and official scope. External pages may change; cite the original text and check date.
- 工具站 · 服务型 Agent 流程Tools · Service agent playbook从任务边界到上线的服务型 Agent 步骤。Steps for a service agent from task boundary to launch.
- 工具站 · 护栏Tools · Guardrails输入、输出、工具与运行时护栏的分层。Layers of input, output, tool and runtime guardrails.
- 工具站 · Agent 记忆Tools · Agent memory短期状态、长期记忆与检索的边界。Boundaries between short-term state, long-term memory and retrieval.
- 工具站 · 编排Tools · Orchestration单 Agent、工作流与多 Agent 的选择。Choosing single-agent, workflow or multi-agent.
- 工具站 · 失败库Tools · Failure library常见失败模式与排查顺序。Common failure modes and triage order.
- 模型站 · Agent 评测Models · Agent evaluation任务、轨迹、工具与安全评测。Task, trajectory, tool and safety evaluation.
- 开源库 · Agent 框架场景OSS · Agent frameworksAgent 框架仓库与许可证入口。Agent framework repositories and licences.
- 学 AI · 工作流编排Learn · Workflow orchestration编排、状态与失败恢复的概念页。Concept page on orchestration, state and recovery.
下一步Next
- 回到“搭智能体”路线Back to the agent route
- 下一步:把权限和证据补齐Next: complete permissions and evidence
- 看其他 15 条主题路线Browse the other 15 topic routes
如果你照着做时卡住了,先回到对应主题路线,不要从头重读。If you get stuck while following it, go back to the matching route instead of rereading the whole guide.
← 回到首页← Back to home 发现错误?提交纠错Spot an error? Send a correction