最新资讯
dev.to 为 CI/CD 构建 AI 质量门禁 dev.to Kakao 发布面向 AI Agent 的决策模型 Kanana-2-v-decide computerworld.com Microsoft 对 Copilot Chat 企业用户扩大未公开的使用限制 pub.towardsai.net Google 发布 Gemini 4 Carbon:主打网络安全能力的前沿模型 gradientflow.com METR 研究:AI 正在加速构建 AI 的团队本身 www.infoq.com GitLab 19.5 将 Agentic 开发纳入 DevOps 平台的治理体系 aiacceleratorinstitute.com 研究:AI Agent 的复杂流程编排可能反而是问题所在 pub.towardsai.net MongoDB 推出 Vercel AI SDK 集成:为 AI 应用提供持久记忆 thenewstack.io Google 捐出被 Anthropic 和 OpenAI 使用的代码沙箱 gVisor,押注 AI Agent 基础设施开源 dev.to 在信任 AI 生成的测试用例前,如何逐条复核 unite.ai Franklin Templeton 构建 AI 研究工作流以揭示风险 techxplore.com AI 助力寻找更优的钛合金 3D 打印工艺参数
多元动态
登录 注册
智能体 dev.to · @Alexis Roberson

不要把 agent 护栏放在 system prompt 里

原文 我的收藏

文章指出,把“不要推送到 main”“不要碰密钥”“必须跑测试”等安全规则写进 system prompt 只是给模型的建议,而非真正的控制面。模型同时被训练为遵循指令和提供帮助,两者冲突时“有帮助”往往胜出;长对话、措辞巧妙的任务或对抗性用户都可能稀释甚至覆盖规则。即便没有对抗压力,仅靠 prompt 的护栏也会漂移,因为每次调整语气、增加工作流或粘贴更多上下文,都会改动本应执行策略的同一层。作者列举了 prompt 护栏在实践中反复出现的失败模式,主张安全不能依赖模型“记得守规矩”。

AI推荐理由 文章提出一个具体工程观点:把 agent 安全护栏放在 system prompt 里不可靠,因为 prompt 与用户消息同通道、会被稀释或覆盖,且调优 prompt 会改变策略执行面。属于有明确论点的经验性讨论,对做 coding agent 的开发者有实际参考价值;但正文片段只给出论点与部分失败模式,缺少可验证的对照实验或数据,来源为个人博客,故质量分中等。

72

正文

Coding agents write, refactor, and open pull requests at a pace humans can't match. The instinct is to stuff safety into the system prompt: "never push to main," "don't touch secrets," "always run the tests." That feels like control. It isn't. A system prompt is advice to a model. Models are trained to follow instructions, and they are also trained to be helpful. When those goals collide, helpful often wins. A determined user, a long thread, or a cleverly worded task can dilute or override the rules you thought were hard-coded. Even without adversarial pressure, prompt-only guardrails drift. Every time you tune tone, add a workflow, or paste more context, you change the same surface that was supposed to enforce policy. If your safety depends on the model remembering to behave, you don't have a control plane. You have a suggestion. Why prompt-only guardrails fail in practice Three failure modes show up again and again. First, prompts are soft. They sit in the same channel as user messages and tool output. There is no separate enforcement path. A policy that lives only in text can be negotiated, forgotten, or reinterpreted. Second, prompts are hard to operate. You can't gradually expose a new rule to 5% of agents, measure whether it reduces bad tool calls, and roll it back in one click. Changing a prompt usually means redeploying config for everyone at once. That is the opposite of how mature teams ship risky behavior. Third, prompts don't produce evidence. When something goes wrong, you need to know which control failed. A buried sentence in a 2,000-token system message rarely leaves a clear audit trail. External controls can log a deny, a blocked tool call, or a failed policy check. An ignored instruction usually just looks like "the agent did a weird thing." What "outside the prompt" actually means External guardrails live in the layers around the model, not inside its instructions. Think in four buckets. Permissions Decide what the agent is allowed to invoke before it speaks. Tool allowlists, deny lists, and scoped credentials belong here. If the agent cannot call git push --force or read production secrets, you don't need the prompt to politely refuse. Scope Limit where the agent may act: which repos, branches, environments, and file paths. Narrow blast radius by default. Broaden it deliberately. Release Treat agent-generated change like any other risky change: expose a small slice first, watch live signals, and reverse when those signals degrade, before the blast radius grows. Deploy behind a switch. Expand when signals look healthy. Pull it back without a rebuild when they don't. The agent can still move fast; you decide who feels the impact. Measurement Watch quality, cost, error rate, and review outcomes. When a new agent config or tool policy regresses those signals, pause or revert. Judgment without measurement is optimism. The system prompt still has a job. Use it for style, priorities, and how to reason about the task. Put the hard limits where a process—not a paragraph can enforce them. A practical control stack for coding agents You don't need a perfect architecture on day one. A useful starter set looks like this: Separate policy from personality. Keep the system prompt focused on how the agent works. Move "must / must not" rules into config that your runtime or CI checks independently. Default to least privilege on tools. Start with read-only where you can. Require explicit elevation for write, merge, deploy, and secret access. Log every elevation. Gate high-impact actions. Before the agent merges, deletes, or talks to production, run a policy check or human approval step that the model cannot skip by rephrasing the request. Ship agent output behind progressive release. Whether the change is a feature, a refactor, or a prompt-driven config, release it the way you release anything else that might hurt customers: small, observable, reversible. Instrument the boring failures. Track blocked tool calls, policy denials, failed tests after agent PRs, and rollback events. Those numbers tell you whether your guardrails are real. Teams that already wrap risky human-written code in flags and progressive delivery already know this pattern. Coding agents just raise the volume. The same control infrastructure that makes fast shipping safe for people makes fast shipping safe for agents. What to try this week Pick one coding agent workflow you already trust enough to use daily. Map every irreversible action it can take. For each one, ask: does a prompt ask it not to, or does something outside the model prevent it? Move the top three irreversible actions behind an external check. Leave the prompt alone for tone and task framing. You will learn more from three hard denials you can measure than from thirty soft rules the model might follow. Closing System prompts are guidance. Guardrails are infrastructure. If you want coding agents to move quickly without inheriting silent failure modes, put the limits where you can observe them, change them, and reverse them...outside the prompt.

来源报道 · 1 篇 · 以下链接均前往原始媒体

Alexis Roberson 不要把 agent 护栏放在 system prompt 里 09-27 · 原文发布
← 返回精选动态 原文

更多内容