正在加载陈远的个人网站

模型升级后的 Agent 上下文工程方法

Anthropic 经验显示:精简系统提示词,转向分层、按需披露与自动记忆的 Agent 上下文架构。

原始内容

Anthropic 讲解了随着模型的提升,应该如何更新自己的上下文规则,推荐看看。 随着 Fable 5 和 Opus 5 的发布,他们精简了 80% 的系统提示词,但在编程测评上没有任何损失。 其核心问题在于,Claude 的提示词只是它获取上下文的一小部分,更多的上下文来自于系统提示词、Skills、claude.md 以及 Memory。 这里的难点在于:上下文是跨多个请求通用的,不能像单个提示词那么具体。 他们之前对 Claude Code 的约束过度了,而且经常存在互相矛盾的指令(约束越多,冲突的概率就越大)。 像 Fable 5、GPT 5.6 这种新模型,完全能够靠上下文和自己的判断力处理很多事情,因此没必要过度约束。 他们总结了过去到现在关于上下文转变几条趋势: 1. 从“给规则”到“让 Claude 运用判断力”:比如旧版会写“默认不写注释”,新版可以改成“写出与周围代码一致的代码”,这样它自己就会去匹配周围代码的注释密度、命名和习惯。 2. 从“给具体示例”到“设计接口”:给具体示例容易让模型变得死板。现在可以给一些设计接口(比如脚本文件的设计),让参数更具表达力,以此来引导它,而不是塞给它具体的示例。 3. 从“全部前置的上下文”到“渐进式披露”:把代码审查、验证等相互独立的信息放在不同的 Skills 里面,按需调用。模型可以通过文件搜索去查找,而不需要一次性塞入。 4. 不在系统提示词和工具描述里重复提示:直接把用法写进工具描述里,不再到系统提示词里去强调。 5. 从“手动记录”到“自动记忆”:以前是在 claude.md里存记忆,现在直接由模型自动记忆,不再依赖手写输入。 6. 从“简单规则”到“丰富的引用”:以前规则非常单一,现在可以把图片、HTML 文件、测试文件、测试代码、函数甚至是评分标准,都作为模型的上下文塞进去。 --- 关于如何将这些原则运用到你自己的上下文管理中,有以下几点建议: 系统提示词定位:在系统提示词里明确告诉 Claude 在什么产品里做什么。如果你在构建 Agent,需要投入精力重新编写系统提示词。 保持 [claude.md]或 [agent.md]的轻量:把仓库用途和说明性内容花在最核心的地方(比如已知的坑或缺陷上)。避免把 Claude 一看代码就能懂的事情非要写进 [claude.md]里。 多用 Skills 进行模块化:把需要按需查找的信息打包成 Skills。如果 Skills 过长,需要采用渐进式披露的方式拆分成多个文件。 优先引用代码形式:在使用 @ 引用文件时,优先引用代码。比如引用 HTML 模板的效果,通常比只给设计描述或截图效果更好。 使用自动化工具:他们还提到了 `claude doctor` 这个命令,可以自动帮你精简 Skills 和 [claude.md]文件。

The new rules of context engineering for Claude 5 models I’ve written previously about how to best [prompt the newest generation of Claude 5 models](https://x.com/trq212/status/2073100352921215386) and work with them iteratively to discover what you want to build. But when you send a message to Claude, the prompt is only a small part of the context it gets. Much of your context is assembled from your system prompt, Skills, CLAUDE.md files, memory, and other sources. We call this [context engineering](https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents), and it makes a big impact on the results you generate when using Claude Code or in building your own agents. Unlike a prompt, context is used generally across many requests, so it cannot be as specific. How do you build these general prompts and guidance for Claude, especially when you don’t know what a user’s prompt might be? This can be surprisingly difficult as Claude’s own capabilities evolve. Most recently, we noticed a large jump in the way we prompt the newest generation of Claude models. We removed over 80% of Claude Code’s system prompt for models like Claude Opus 5 and Claude Fable 5 with no measurable loss on our coding evaluations. Here’s what we’ve learned about prompting this new class of models, and how you can utilize it to update your context engineering. We’ve put these best practices in `claude doctor`, use the command /doctor in Claude Code to rightsize your skills, and CLAUDE.md files. ## Unhobbling Claude Overall, we found that we were over-constraining Claude Code, both through our system prompt and in our CLAUDE.md files and skills. For example, when we read transcripts of our own internal usage of Claude Code, we see several conflicting messages in a single request like “leave documentation as appropriate,” or “DO NOT add comments” as our system prompt, skills, and user requests clash with each other. Generally, Claude can interpret the user’s intent to get to the right answer, but Claude must think more carefully about these overlapping and conflicting messages before deciding what to do. And while these constraints were once needed to avoid worst case scenarios, we have since found we can delete many of them and let the model use surrounding context and judgement instead. Additionally, Claude Code now has many more tools. Claude used to rely on CLAUDE.md as a source of memory, information, and guidance. Now we have memory, artifacts, and skills, which Claude can use to create new ways of loading and sharing context across sessions. ## Then and now There were a number of previous context engineering best practices that had become myths. Including: Then: Give Claude rules Now: Let Claude use judgement When we first rolled out Claude Code, we needed to be sure that Claude avoided worst case scenarios, such as deleting files. This meant we would give particularly strong guidance that might not always be true, For example, in the system prompt we used to say: In code: default to writing no comments. Never write multi-paragraph docstrings or multi-line comment blocks — one short line max. Don't create planning, decision, or analysis documents unless the user asks for them — work from conversation context, not intermediate files. But for a certain subset of prompts, this guidance would be wrong. In the case of documentation, the user may have their own preferences, or specific parts of very complex code might need multi-line comment blocks. Still, without these guardrails for older models, the comments Claude wrote would be incorrect in many cases and we had to accept this tradeoff. But newer models have better judgement and can handle these decisions well without explicit rules. In the new system prompt we say: Write code that reads like the surrounding code: match its comment density, naming, and idiom. Then: Give Claude examples Now: Design interfaces The number one rule for tool usage was to give Claude examples on how to use them. With our newest models, we’ve found that giving examples actually constrains them to a certain exploration space. Instead of using examples, think more about the design of your tools, scripts and files- what parameters does Claude have and how can they be more expressive? For example, in the Todo tool example, just listing status as an enumeration between pending, in_progress, and completed, hints to Claude about how to use it. The instruction on keeping one item in_progress helps define our requested behavior. Then: Put it all upfront Now: Use progressive disclosure Because Claude Code was focused on coding, our system prompt included detailed information on how to do code review and verification. These were not always needed, but when they were, it was crucial information. Since then, Claude Code has gotten very competent at using progressive disclosure- loading the right context at the right times. For example, we moved verification and code review into their own skills that Claude Code could selectively call. But progressive disclosure is not just for skills, we also use it for tools. Some of our tools are ‘deferred loading,’ which means the agent must search for their full definitions using ToolSearch before using them. This allows us to have more tools (such as our Task tools) that don’t take up context until they’re needed. The same can be applied to your own CLAUDE.md and Skill.md files. A common myth is that you want to make these a central repository for every known practice that you might run into, because Claude would not find it otherwise. Instead, [consider having a tree of files that can be loaded at the right time](https://claude.com/blog/a-harness-for-every-task-dynamic-workflows-in-claude-code). Then: Repeat yourself Now: Simple tool descriptions Earlier Claude models could sometimes need repeated instructions or be more likely to listen to instructions at the end of their context window than at the start. This meant our system prompt would sometimes have references to tools in the main system prompt as well as instructions in the tool description. We found we could delete these repeat examples and put instructions on how to use tools in the tool descriptions rather than the system prompt. Then: Memory in CLAUDE.md files Now: Auto-memory We used to encourage users to save things to Claude’s memory, by using the # hotkey to write to their [CLAUDE.md](http://claude.md/) automatically. Instead, Claude now automatically saves memories that are relevant to the work and to you. Then: Simple specs Now: Rich references In plan mode, Claude Code has heavily relied on markdown files with plans. Storing these files as plans helped Claude refer to them when needed. Another similar best practice was to store specs in the codebase for Claude to refer to while working across longer projects. But we’ve found that Claude can handle increasingly more complicated references. Instead of simple markdown files, Claude can reference HTML artifacts created by our new artifacts feature. You may also give Claude references in the form of code. A spec may also be a detailed test suite, or a function in a different codebase that Claude might port. Rubrics are another form of references. Rubrics allow Claude to try and verify your taste in a particular field (e.g. what does a good API design look like) by using [dynamic workflows](https://claude.com/blog/a-harness-for-every-task-dynamic-workflows-in-claude-code) and spinning up verifier agents with those rubrics. ## Applying this to your context Pulling this all together, what does this look like when you assemble your context? System Prompt A system prompt is heavily tied to the product context. It tells Claude what product it’s operating in and what it’s doing. For Claude Code, you will likely never modify this, but if you are building your own agent harness, this is where you should spend a lot of time. CLAUDE.md Keep your CLAUDE.md lightweight and briefly describe what your repo is for, but spend most of the tokens on gotchas inside of the codebase. For example, you may organize your code to keep types in one monolithic file and nowhere else. Avoid stating ‘the obvious’ things Claude should know by looking at your file system or your repo. Use progressive disclosure for more details, for example if you have several unique instructions on how to verify your work, create a verification skill and reference it from your CLAUDE.md. Skills Think of skills as lightweight guides to let Claude find information when needed. Avoid making them overconstrained, except in highly important areas. For long skills, try and use progressive disclosure as much as possible- divide it into many files and split them out. It’s best when skills encode particular opinions, knowledge, or best practices that are particular to you, your team, or product. References You can @ mention files to include them as references. References allow Claude to refer to in-depth information about the current plan. This might be in specs files, mockups, or even entire codebases. Generally you should prefer files that are in code as it provides clear, high-fidelity instructions to Claude in a language it knows very well. For example, a HTML mockup of a design will generally produce better results than a description of the design or a screenshot. ## Try simplifying Across your system prompt, skills, and CLAUDE.md files, you may need to simplify just like we did. We rolled out a new command called `claude doctor,` which will help you do this automatically as well. For more details on prompting more advanced models specifically, check out our [Fable field guide](https://claude.com/blog/a-field-guide-to-claude-fable-finding-your-unknowns).

— @trq212(Thariq)的引用原文
模型升级后的 Agent 上下文工程方法,来源媒体第 1 张,共 1 张

深度解析

是什么 这条内容围绕模型升级后的上下文工程,核心不是“提示词越短越好”,而是把一次性、密集的规则改造成分层且可检索的工作环境。系统提示词定义产品场景与 Agent 职责;CLAUDE.md 只保留仓库用途、已知坑和真正不可推断的约束;Skills 承载任务知识;代码、HTML、测试和评分标准提供高保真引用;Memory 负责跨请求积累。

核心设计 论点链条是:能力增强→不必把每个动作写死→硬规则减少后冲突下降→模型可依据环境做判断。具体包括用编码风格原则替代动作清单,用接口设计替代大量示例,用渐进式披露替代全部前置,并把工具用法放进工具描述,避免系统提示词重复。

关键洞察 上下文治理本质上是 Agent 的信息架构:短并非目标,清晰分层、低重复、易发现和有证据更重要。图片用四页编排、旧/新对照、堆叠组件和中心枢纽,把这套架构具象化,便于团队将规则放回正确位置。

边界与风险 删减不等于必然提升;关键安全边界、权限和验收条件仍应显式保留。自动记忆可能陈旧或错误,渐进式披露依赖命名与检索质量,过度抽象的原则也可能造成执行漂移。应以真实任务、回归测试和评分结果验证每次调整。