Community编程与开发github.com

上下文工程合集

提供上下文工程、驾驭工程、多智能体架构和生产级智能体系统构建所需的全方位技能。适用于需要有效上下文管理和可靠运行循环的智能体系统的构建、优化、评估与调试。

上下文工程合集 是什么?

该技能合集为构建生产级 AI 智能体系统提供了结构化指南,聚焦于有效的上下文工程。它涵盖从上下文基础(如注意力机制和上下文退化),到架构模式(如多智能体协调、长时程提示与记忆系统设计)的广泛主题。合集还深入操作优化,包括上下文压缩、自管理上下文、潜在简报技术(KV内存共享),以及评估框架与驾驭工程。最后,它涉及开发方法论(如任务-模型匹配分析)和认知架构(如信念-愿望-意图模型)。此合集是平台无关的,可与Claude Code、Cursor或任何支持自定义指令的智能体框架配合使用,为开发者提供一套完整工具,用于构建可靠、高效的智能体系统。

兼容平台✓Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/tree/main

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

上下文工程智能体技能合集

本合集通过有效的上下文工程,为构建生产级 AI 智能体系统提供结构化指导。

何时激活

当出现以下情况时激活这些技能:

  • 从头构建新的智能体系统
  • 优化现有智能体性能
  • 调试与上下文相关的故障
  • 设计多智能体架构
  • 创建或评估智能体工具
  • 实现记忆和持久化层
  • 设计自主研究或评估工具链

技能地图

基础上下文工程

理解上下文基础 上下文不仅仅是提示文本——它是推理时可用的完整状态,包括系统指令、工具定义、检索到的文档、消息历史记录以及工具输出。有效的上下文工程意味着理解哪些信息对于手头任务真正重要,并对这些信息进行策划以获得最大的信噪比。

识别上下文退化 语言模型在上下文增长时会表现出可预测的退化模式:"中间丢失"现象(中间信息注意力减少);U形注意力曲线(优先考虑开头和结尾);端对端错误污染;以及无关信息淹没相关内容的上下文干扰。

架构模式

多智能体协调 生产级多智能体系统收敛于三种主要模式:具有集中控制的主/编排架构、用于灵活交接的对等群体架构,以及用于复杂任务分解的层次结构。关键洞察在于,子智能体主要存在是为了隔离上下文,而非模拟组织角色。

长时程提示 长期运行的自主智能体和并行编排的成功与否取决于启动提示。伪正式任务简报指定成功谓词、非计数结果、带审计门控返回条件的持久性规则、努力下限、针对并行组合的多样性策略以及污染防护,对没有机器可检查成功条件的问题应用形式化验证的约束语。在编排运行中,每个工作进程返回带有命名检查的输出契约,只有被证实的违规才会阻止返回。

记忆系统设计 记忆架构的范围从简单的便签本到复杂的时序知识图谱。向量RAG提供语义检索,但会丢失关系信息。知识图谱保留结构,但需要更多的工程投入。将文件系统作为记忆的模式能够实现即时上下文加载,而无需塞满上下文窗口。

基于文件系统的上下文 文件系统为存储、检索和更新可扩展的上下文提供了单一接口。关键模式包括用于卸载工具输出的便签本、用于长时程任务的计划持久化、通过共享文件进行子智能体通信以及动态技能加载。智能体使用 ls、glob、grep 和 read_file 进行目标上下文发现,在结构查询方面通常优于语义搜索。

托管智能体基础设施 后台编码智能体运行在远程沙盒环境中,而非本地机器上。关键模式包括定期刷新的预构建环境镜像、用于即时会话启动的温沙盒池、用于会话持久化的文件系统快照,以及用于协作智能体会话的多玩家支持。关键优化包括允许在 git 同步完成前读取文件(仅阻止写入)、当用户开始输入时进行预测性沙盒预热,以及用于并行任务执行的自我生成智能体。

工具设计原则 工具是确定性系统与非确定性智能体之间的契约。有效的工具设计遵循整合原则(优先使用单一综合工具而非多个狭窄工具)、在错误中返回上下文信息、支持响应格式选项以节省令牌,并使用清晰命名空间。

卓越运营

上下文压缩 当智能体会话耗尽记忆时,压缩成为必需。正确的优化目标应是每任务的令牌数,而非每请求的令牌数。带有明确文件、决策和下一步骤的结构化摘要能比激进压缩保留更多有用信息。在所有压缩方法中,工件轨迹完整性仍然是最弱的维度。

上下文优化 技术包括紧凑化(在接近限制时总结上下文)、观察屏蔽(用引用替换冗长的工具输出)、前缀缓存(跨请求重用KV块)以及策略性上下文分区(将工作分散到具有隔离上下文的子智能体中)。

自管理上下文 模型(而非驾驭框架)决定哪些内容保留在其实时上下文中:可编辑区域作为文件暴露给模型,模型使用代码工具重写该文件,并在每轮重新解析。驾驭框架维护不变量(固定的系统和任务前缀、角色折叠、编辑门控、回执、确定性预算读数、溢出时回滚)。在前缀缓存下,编辑成本与编辑后的文本长度成比例,因此编辑被批量处理并放置于尾部附近;策略可通过指令引导、作为技能演化,或通过成功门控的效率奖励进行训练。

潜在简报(KV内存共享) 编排器-工作进程系统可能累积令牌,因为监督者积累长轨迹,而工作进程仅看到较窄的文本片段。潜在简报使用任务引导的注意力机制(类似注意力匹配的紧凑化)在工作进程模型的KV缓存中压缩编排器轨迹,因此当堆栈暴露工作进程KV状态且模型兼容时,工作进程无需完整文本回放即可接收相关潜在状态。

评估框架 生产级智能体评估需要确定性检查和涵盖事实准确性、完整性、工具效率和过程质量的多维度评分标准。仅在结构、证据和评分规则有效后使用模型评判器;将评判器设计、成对比较和偏见缓解引导至高级评估。

驾驭工程 可靠的自主智能体需要围绕模型的显式运行循环:锁定指标、可编辑表面、持久化日志、新颖性检查、回滚规则和人工批准边界。驾驭框架防止智能体削弱评估器、在紧凑化中丢失状态,或将模糊目标变为不可审查的更改。

自我改进循环 当驾驭框架本身成为优化目标时,会采用不同的规范:递归自我改进、元驾驭搜索、故障驱动的有界自我编辑、演化性支架搜索和上下文机制演化。控制约束包括经验性两拆分接受门、包含原始轨迹的文件系统经验存档、每个可编辑表面外部的运行时强制约束,以及防止塌缩的多样性保护。

开发方法论

项目开发 有效的LLM项目开发始于任务-模型匹配分析:通过手动原型验证任务是否适合LLM处理,之后再构建自动化。生产管道遵循分阶段、幂等的架构(获取、准备、处理、解析、渲染),并利用文件系统状态管理进行调试和缓存。带有明确格式规范的结构化输出设计能够实现可靠解析。从最小架构开始,仅在证明必要时增加复杂性。

认知架构

BDI心智状态 信念-愿望-意图建模提供了一种将结构化外部上下文转化为智能体心智状态的正式方法。将其用于理性代理、可解释性以及需要信念、目标和所选行动之间有可审计联系的系统。

核心概念

本合集围绕四个核心主题组织。首先,上下文基础确立了上下文定义、注意力机制工作原理以及上下文质量比数量更重要的原因。其次,架构模式涵盖了构建有效智能体系统的结构和协调机制。第三,卓越运营涉及优化、评估和驾驭可靠性。第四,开发方法论和认知架构涵盖了项目执行和正式心智状态建模。

实践指导

每个技能可以独立使用,也可以组合使用。从基础开始,建立上下文管理的心智模型。根据系统需求,分支到架构模式。在优化生产系统时参考操作技能。

这些技能是平台无关的,可与Claude Code、Cursor或任何支持自定义指令或类似技能结构的智能体框架一起使用。

集成

本合集内部集成——技能相互引用并建立在共享概念之上。基础技能为所有其他技能提供背景。架构技能(多智能体、记忆、工具)可组合用于复杂系统。操作技能(优化、评估)适用于使用基础和架构技能构建的任何系统。

参考

本合集内部技能:

关于上下文工程的外部资源:

  • 关于注意力机制和上下文窗口限制的研究
  • 领先AI实验室在生产环境中的智能体系统设计经验
  • LangGraph、AutoGen和CrewAI的框架文档

技能元数据

创建日期:2025-12-20 最后更新:2026-10-01 作者:上下文工程智能体技能贡献者 版本:2.6.0

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

advanced-evaluation

This skill should be used for advanced LLM evaluation: LLM-as-judge systems, direct scoring, pairwise comparison, rubric calibration, evaluator bias mitigation, confidence scoring, and automated quality assessment.

bdi-mental-states

This skill should be used when modeling agent mental states with BDI concepts: beliefs, desires, intentions, RDF-to-belief transformations, rational agency traces, cognitive agents, BDI ontologies, and neuro-symbolic AI integration.

book-sft-pipeline

This skill should be used for book-to-SFT pipelines: ePub extraction, literary segmentation, author-voice dataset construction, style-transfer training, LoRA workflows, and model evaluation for voice replication.

comprehensive-research-agent

Ensure thorough validation, error recovery, and transparent reasoning in research tasks with multiple tool calls

context-compression

This skill should be used when long-running agent sessions need context compression, structured summarization, compaction, token-per-task optimization, or durable handoff summaries that preserve decisions, files, risks, and next actions.

context-degradation

This skill should be used for diagnosing and mitigating context degradation: lost-in-middle failures, context poisoning, context clash, context confusion, attention-pattern issues, and agent performance degradation caused by accumulated or conflicting context.

context-fundamentals

This skill should be used to explain or reason about the foundational concepts of context engineering: what context is, the anatomy of a context window, how attention mechanics work, the U-shaped attention curve, why context quality matters more than quantity, and the mental models needed to interpret every other context-engineering decision. Use this for conceptual explanation, onboarding, and background reading. Route operational work to the specialized skills: debugging attention failures goes to context-degradation, token-efficiency work goes to context-optimization, conversation summarization goes to context-compression, and project-shape decisions go to project-development.

context-optimization

This skill should be used for improving context efficiency: context budgeting, observation masking, prefix or KV-cache strategy, partitioning, token-cost reduction, retrieval scoping, and extending effective context capacity without lowering answer quality.

evaluation

This skill should be used when building agent evaluation systems: deterministic checks, regression suites, multi-dimensional rubrics, quality gates, production monitoring, baseline comparison, and outcome measurement for agent pipelines.

filesystem-context

This skill should be used when agent work needs file-backed context: durable scratchpads, tool-output offloading, just-in-time discovery, cross-agent handoff files, filesystem memory, or cleanup policies for context stored outside the prompt.

harness-engineering

This skill should be used when designing autonomous agent harnesses: research loops, evaluation scaffolds, locked and editable surfaces, durable logs, novelty gates, pruning, rollback, PR preparation, and human approval boundaries.

hosted-agents

This skill should be used when designing hosted or background agent infrastructure: sandboxed execution, remote coding environments, warm pools, session persistence, multiplayer collaboration, self-spawning agents, or Modal-style sandboxes.

latent-briefing

This skill should be used when the user asks to "share memory between agents", "KV cache compaction for multi-agent", "orchestrator worker context", "latent briefing", "reduce worker tokens", "cross-agent memory without summarization", or discusses Attention Matching compaction, recursive language models with workers, or token explosion in hierarchical agents.

long-horizon-prompting

This skill should be used when writing, enhancing, or evaluating the launch prompt for a long-running autonomous agent or a parallel multi-agent orchestration attacking a hard problem: pseudo-formal task briefs that define terms and an exact success predicate linguistically, enumerate non-counting outcomes, set persistence rules with explicit stop and return conditions and effort floors, manage a diverse portfolio of parallel approaches with an approach registry and blocked-route bookkeeping, and gate the return on adversarial audit. Route agent topology and coordination protocols to multi-agent-patterns, runtime control surfaces and loop governance to harness-engineering, evaluator and quality-gate construction to evaluation, judge design to advanced-evaluation, and compaction or memory mechanics to context-compression and memory-systems.

memory-systems

This skill should be used for persistent semantic memory in agent systems: cross-session knowledge retention, entity tracking, temporal validity, graph or vector retrieval, memory consolidation, and memory benchmark selection. Route file-backed scratchpads to filesystem-context, handoff summaries to context-compression, and token-efficiency tactics to context-optimization.

multi-agent-patterns

This skill should be used when designing multi-agent systems that need context isolation, supervisor or swarm coordination, explicit handoffs, parallel execution, or a decision on whether multiple agents are justified.

project-development

This skill should be used for project-level decisions about LLM-powered systems: whether an LLM is the right primitive for the task at hand, the shape of a multi-stage batch or agent pipeline, token and cost estimation, choosing between single-agent and multi-agent at the project level, structured output design for downstream parsing, and structuring agent-assisted iteration. Use this when the unit of work is a whole project or a multi-stage pipeline. Route individual tool design to tool-design and individual skill-loading or context-budget tactics to context-optimization.

self-improvement-loops

This skill should be used when the harness, scaffold, workflow, or optimizer itself is the optimization target: recursive self-improvement (RSI) loops, meta-harnesses, self-improving harnesses that mine their own failures and propose bounded edits, evolutionary or population-based search over agent scaffolds, acceptance gates for self-modifying systems, and agentic context evolution where the mechanism that produces context is versioned and evolved. Route governance of a single autonomous loop (locked surfaces, durable logs, rollback, novelty gates, approval boundaries) to harness-engineering, measurement and quality-gate design to evaluation, judge design to advanced-evaluation, and remote sandbox infrastructure to hosted-agents.

self-managed-context

This skill should be used when a model gets read-write control over its own live context window instead of a harness-scheduled compaction policy: the context exposed as an editable file the model rewrites with code tools, model-driven eviction and in-place updates, the harness invariants that keep self-editing safe (pinned prefix, edit gate, edit receipts, budget readouts, rollback on overflow), the prefix-cache cost of mid-context edits, and steering or training the model's own context-editing strategy. Route note content and fixed-threshold summarization to context-compression, cache-stable layout under harness control to context-optimization, file offloading to filesystem-context, and loop governance to self-improvement-loops.

tool-design

This skill should be used for the tool-interface layer of an agent system specifically: writing tool descriptions agents can route on, designing tool schemas and response formats, naming conventions, actionable error recovery messages, MCP server design, tool-set consolidation, and deciding when to add or remove an individual tool. Use this when the unit of work is a single tool or a set of tools. Route project-shape, pipeline architecture, and task-model-fit decisions to project-development; route deciding whether to introduce sub-agents to multi-agent-patterns.

相关技能