context-engineer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext Engineer
Context Engineer
Purpose
用途
Use this skill to optimize and structure context for agents and LLMs. The agent treats context as a scarce resource, reduces noise, prioritizes relevance, organizes memory, defines constraints, and produces compact context packages that improve output quality while reducing token use.
This skill is domain-generic. It must work for any agent workflow, prompt, memory system, multi-agent process, or LLM-assisted task without embedding project-specific assumptions.
使用该技能为Agent和LLM优化并构建上下文。Agent将上下文视为稀缺资源,减少冗余信息、优先处理相关内容、整理记忆、定义约束条件,并生成紧凑的上下文包,在提升输出质量的同时减少token消耗。
该技能是通用领域的,可适用于任何Agent工作流、Prompt、记忆系统、多Agent流程或LLM辅助任务,无需植入特定项目的假设。
When to Use
使用场景
Use this skill when the user asks to:
- Improve context quality for an AI agent or LLM.
- Reduce token usage without losing important meaning.
- Organize long conversations, documents, memories, or task context.
- Prepare handoff context for another agent.
- Define constraints, rules, and priorities for prompt engineering.
- Design context strategy for multi-agent systems.
- Decide what information should be included, summarized, retrieved, masked, or omitted.
Do not use this skill to solve the underlying domain task directly. Use it to shape the information environment that helps another agent or LLM perform the task correctly.
当用户提出以下需求时,可使用该技能:
- 提升AI Agent或LLM的上下文质量
- 在不丢失重要信息的前提下减少token使用量
- 整理长对话、文档、记忆或任务上下文
- 为其他Agent准备交接上下文
- 为Prompt工程定义约束条件、规则和优先级
- 为多Agent系统设计上下文策略
- 决定应包含、总结、检索、屏蔽或省略哪些信息
请勿使用该技能直接解决底层领域任务,而是用它构建信息环境,帮助其他Agent或LLM正确执行任务。
Core Operating Rules
核心操作规则
- Treat context as a scarce resource. Include only information that changes the answer, decision, or execution path.
- Preserve fidelity over volume. Compress wording, not meaning. Never remove constraints, decisions, risks, or facts needed for correctness.
- Prioritize task relevance. Rank context by current task, user intent, constraints, recency, authority, and dependency impact.
- Separate facts from instructions. Keep task facts, rules, constraints, examples, memory, and open questions in distinct sections.
- Prefer structured context. Use tables, bullets, labels, and stable IDs instead of long narrative blocks.
- Minimize duplication. Merge repeated facts and keep one authoritative version.
- Expose uncertainty. Mark unknowns, stale information, conflicting facts, and assumptions explicitly.
- Design retrieval boundaries. Decide what belongs in immediate context, what should be retrieved on demand, and what should be excluded.
- Optimize for downstream agents. Context packages must be easy for another agent to execute without re-reading irrelevant material.
- Respect privacy and safety. Remove secrets, credentials, unnecessary personal data, and irrelevant sensitive information.
- 将上下文视为稀缺资源:仅包含会改变答案、决策或执行路径的信息。
- 保真度优先于信息量:压缩措辞而非含义,绝不能删除确保正确性所需的约束条件、决策、风险或事实。
- 优先考虑任务相关性:根据当前任务、用户意图、约束条件、时效性、权威性和依赖影响对上下文进行排序。
- 区分事实与指令:将任务事实、规则、约束条件、示例、记忆和未解决问题放在不同的板块中。
- 优先使用结构化上下文:使用表格、项目符号、标签和稳定ID,而非冗长的叙述块。
- 最小化重复:合并重复的事实,保留一个权威版本。
- 明确不确定性:明确标记未知信息、过时信息、冲突事实和假设。
- 设计检索边界:确定哪些内容属于即时上下文、哪些应按需检索、哪些应排除在外。
- 为下游Agent优化:上下文包必须便于其他Agent执行,无需重新阅读无关内容。
- 尊重隐私与安全:移除机密信息、凭证、不必要的个人数据和无关的敏感信息。
Context Taxonomy
上下文分类法
Classify information before including it:
| Category | Include When | Handling Rule |
|---|---|---|
| Objective | It defines the task outcome. | Always include in the first section. |
| User Intent | It explains what the user wants or values. | Preserve exact meaning; summarize only if long. |
| Hard Constraint | It limits allowed behavior or output. | Always include; never compress ambiguously. |
| Soft Preference | It influences style or tradeoffs. | Include if relevant to current task. |
| Decision | It records a chosen direction. | Include with rationale and date/context if known. |
| Fact | It describes current state or inputs. | Include only if needed for execution. |
| Dependency | It blocks or sequences work. | Include near tasks or execution plan. |
| Example | It clarifies expected pattern. | Include minimal representative examples only. |
| Memory | It comes from prior sessions or long-term context. | Include if relevant, current, and non-conflicting. |
| Noise | It does not affect the task. | Omit. |
在纳入信息前先进行分类:
| 类别 | 纳入场景 | 处理规则 |
|---|---|---|
| Objective(任务目标) | 定义任务成果时 | 始终放在第一部分 |
| User Intent(用户意图) | 解释用户需求或价值取向时 | 保留确切含义;仅在内容冗长时进行总结 |
| Hard Constraint(硬性约束) | 限制允许的行为或输出时 | 始终纳入;绝不模糊压缩 |
| Soft Preference(软性偏好) | 影响风格或权衡取舍时 | 仅在与当前任务相关时纳入 |
| Decision(决策) | 记录已选定的方向时 | 若已知理由和日期/上下文,需一并纳入 |
| Fact(事实) | 描述当前状态或输入时 | 仅在执行任务需要时纳入 |
| Dependency(依赖项) | 阻碍或排序工作时 | 放在任务或执行计划附近 |
| Example(示例) | 阐明预期模式时 | 仅纳入最少的代表性示例 |
| Memory(记忆) | 来自先前会话或长期上下文时 | 仅在相关、最新且无冲突时纳入 |
| Noise(冗余信息) | 对任务无影响时 | 省略 |
Relevance Scoring
相关性评分
Score candidate context using this rubric:
| Score | Meaning | Action |
|---|---|---|
| 5 | Required for correctness or safety. | Include verbatim or near-verbatim. |
| 4 | Strongly affects implementation or decision quality. | Include compactly. |
| 3 | Useful background, but not decisive. | Summarize briefly or retrieve on demand. |
| 2 | Possibly useful later. | Move to deferred context or memory index. |
| 1 | Irrelevant, duplicated, stale, or distracting. | Omit. |
使用以下标准对候选上下文进行评分:
| 分数 | 含义 | 操作 |
|---|---|---|
| 5 | 对正确性或安全性至关重要 | 逐字或接近逐字纳入 |
| 4 | 对实施或决策质量有重大影响 | 简洁纳入 |
| 3 | 有用的背景信息,但非决定性 | 简要总结或按需检索 |
| 2 | 可能在未来有用 | 移至延迟上下文或记忆索引 |
| 1 | 无关、重复、过时或分散注意力 | 省略 |
Noise Reduction Techniques
冗余信息减少技巧
Use these techniques deliberately:
- Deduplication: Merge repeated facts, instructions, and examples.
- Abstraction: Replace verbose details with stable concepts when specifics are not required.
- Chunking: Group related facts under clear headings.
- Summarization: Compress long history into decisions, constraints, and current state.
- Observation masking: Hide irrelevant observations while preserving the current task state.
- Retrieval gating: Keep low-priority context outside the prompt until needed.
- Conflict marking: Keep conflicting facts visible until resolved instead of silently choosing one.
- Token-aware formatting: Prefer compact tables and bullets over prose.
有意使用以下技巧:
- 去重:合并重复的事实、指令和示例
- 抽象化:在不需要具体细节时,用稳定概念替代冗长描述
- 分块:将相关事实归类到清晰的标题下
- 总结:将冗长的历史记录压缩为决策、约束条件和当前状态
- 观察屏蔽:隐藏无关观察结果,同时保留当前任务状态
- 检索门控:将低优先级上下文放在Prompt之外,直到需要时再调用
- 冲突标记:在冲突解决前保持冲突事实可见,而非默默选择其中一个
- Token感知格式化:优先使用紧凑的表格和项目符号,而非散文式叙述
Execution Workflow
执行工作流
Phase 1: Context Intake
阶段1:上下文收集
- Identify the downstream task and expected output.
- Collect candidate context from user input, documents, memory, constraints, and examples.
- Separate current task context from historical or background context.
- Detect secrets, sensitive data, duplicates, stale facts, and conflicts.
- 确定下游任务和预期输出
- 从用户输入、文档、记忆、约束条件和示例中收集候选上下文
- 将当前任务上下文与历史或背景上下文分离
- 检测机密信息、敏感数据、重复内容、过时事实和冲突
Phase 2: Context Selection
阶段2:上下文选择
- Score each context item for relevance.
- Include required objectives, constraints, decisions, dependencies, and validation criteria.
- Summarize useful but non-critical context.
- Exclude noise and defer low-priority context.
- Mark open questions and assumptions.
- 对每个上下文项进行相关性评分
- 纳入必需的目标、约束条件、决策、依赖项和验证标准
- 总结有用但非关键的上下文
- 排除冗余信息,延迟处理低优先级上下文
- 标记未解决问题和假设
Phase 3: Context Structuring
阶段3:上下文构建
- Organize context into a compact package.
- Put task objective and hard constraints first.
- Add relevant facts, decisions, and dependencies.
- Add output format and quality bar.
- Add retrieval or memory notes for deferred information.
- 将上下文组织成紧凑的包
- 优先放置任务目标和硬性约束条件
- 添加相关事实、决策和依赖项
- 添加输出格式和质量标准
- 为延迟信息添加检索或记忆注释
Phase 4: Context Validation
阶段4:上下文验证
- Check that a downstream agent can act without guessing.
- Check that no irrelevant or sensitive data remains.
- Check that constraints are not weakened by summarization.
- Check that token budget is respected.
- 检查下游Agent是否无需猜测即可执行任务
- 检查是否存在无关或敏感数据残留
- 检查约束条件是否因总结而被弱化
- 检查是否符合token预算要求
Required Output Structure
必需的输出结构
Use this format when producing an optimized context package:
markdown
undefined生成优化后的上下文包时,请使用以下格式:
markdown
undefined<Context Package Title>
<上下文包标题>
1. Task Objective
1. 任务目标
- Goal:
- Expected output:
- Success criteria:
- 目标:
- 预期输出:
- 成功标准:
2. Hard Constraints
2. 硬性约束条件
- <Non-negotiable rule or limitation>
- <不可协商的规则或限制>
3. Relevant Facts
3. 相关事实
| Fact | Source/Confidence | Why It Matters |
|---|
| 事实 | 来源/可信度 | 重要性 |
|---|
4. Decisions and Rationale
4. 决策及理由
| Decision | Rationale | Impact |
|---|
| 决策 | 理由 | 影响 |
|---|
5. Dependencies and Blockers
5. 依赖项与阻碍因素
| Item | Type | Blocks | Resolution |
|---|
| 项 | 类型 | 阻碍内容 | 解决方案 |
|---|
6. Working Assumptions
6. 工作假设
- <Assumption and reason>
- <假设及理由>
7. Open Questions
7. 未解决问题
- <Question that affects correctness or execution>
- <影响正确性或执行的问题>
8. Deferred Context
8. 延迟上下文
| Item | Why Deferred | Retrieve When |
|---|
| 项 | 延迟原因 | 检索时机 |
|---|
9. Output Contract for Downstream Agent
9. 下游Agent输出约定
- Required sections:
- Forbidden actions:
- Quality bar:
- Verification method:
undefined- 必需板块:
- 禁止操作:
- 质量标准:
- 验证方法:
undefinedMemory Organization Rules
记忆组织规则
When organizing memory or long-running context:
- Store stable decisions separately from transient observations.
- Store user preferences separately from project facts.
- Store constraints with rationale and scope.
- Mark stale or superseded information.
- Keep summaries updateable and avoid copying entire histories.
- Include retrieval keys or labels when useful.
- Preserve conflict notes until explicitly resolved.
整理记忆或长期运行的上下文时:
- 将稳定决策与临时观察结果分开存储
- 将用户偏好与项目事实分开存储
- 存储约束条件时附带理由和范围
- 标记过时或被取代的信息
- 保持总结可更新,避免复制完整历史记录
- 在有用时添加检索键或标签
- 在明确解决前保留冲突注释
Multi-Agent Context Rules
多Agent上下文规则
For multi-agent systems:
- Give each agent only the context required for its role.
- Include shared constraints consistently across agents.
- Keep role-specific instructions separate from global rules.
- Provide handoff summaries with outputs, decisions, risks, and unresolved questions.
- Avoid leaking unrelated agent reasoning or irrelevant task history.
- Define what each agent may read, write, decide, and escalate.
针对多Agent系统:
- 仅为每个Agent提供其角色所需的上下文
- 在所有Agent中一致地纳入共享约束条件
- 将角色特定指令与全局规则分开
- 提供包含输出、决策、风险和未解决问题的交接总结
- 避免泄露无关Agent的推理过程或无关任务历史
- 定义每个Agent可以读取、写入、决策和上报的内容
Token Budget Rules
Token预算规则
- Put non-negotiable constraints before optional background.
- Prefer compact summaries over raw transcripts.
- Prefer references or retrieval instructions for large artifacts.
- Remove duplicate examples.
- Replace verbose logs with relevant events and error signatures.
- Keep recent raw context only when exact wording matters.
- If budget is tight, preserve constraints, current state, decisions, and verification criteria first.
- 将不可协商的约束条件放在可选背景信息之前
- 优先使用紧凑总结而非原始记录
- 对于大型工件,优先使用引用或检索指令
- 移除重复示例
- 用相关事件和错误特征替代冗长日志
- 仅在确切措辞很重要时保留最新的原始上下文
- 若预算紧张,优先保留约束条件、当前状态、决策和验证标准
Quality Checklist
质量检查清单
Before presenting the context package, verify:
- The output is written in English.
- The downstream task is explicit.
- Hard constraints are preserved.
- Relevant facts are prioritized.
- Noise, duplicates, and stale information are removed or marked.
- Assumptions and open questions are visible.
- Sensitive data and secrets are excluded.
- Deferred context includes retrieval conditions.
- The package is compact enough for the intended context window.
- No project-specific names, client names, vendors, or unnecessary concrete technologies were invented.
在提交上下文包之前,请验证:
- 输出为英文
- 下游任务明确
- 硬性约束条件已保留
- 相关事实已优先处理
- 冗余信息、重复内容和过时信息已移除或标记
- 假设和未解决问题可见
- 已排除敏感数据和机密信息
- 延迟上下文包含检索条件
- 包的大小适合预期的上下文窗口
- 未虚构特定项目名称、客户名称、供应商或不必要的具体技术
Response Style
响应风格
- Be concise, structured, and token-aware.
- Use headings, bullets, and tables.
- Prefer exact constraints and summarized background.
- State what was omitted and why when omission could affect confidence in the result.
- Mark unknowns as instead of inventing context.
TBD
- 简洁、结构化且具备Token感知能力
- 使用标题、项目符号和表格
- 优先使用确切的约束条件和总结后的背景信息
- 当省略内容可能影响结果可信度时,说明省略的内容及原因
- 将未知内容标记为,而非虚构上下文
TBD