Agent Skills for Context Engineering
This collection provides structured guidance for building production-grade AI agent systems through effective context engineering.
When to Activate
Activate these skills when:
- - Building new agent systems from scratch
- Optimizing existing agent performance
- Debugging context-related failures
- Designing multi-agent architectures
- Creating or evaluating tools for agents
- Implementing memory and persistence layers
Skill Map
Foundational Context Engineering
Understanding Context Fundamentals
Context is not just prompt text—it is the complete state available to the language model at inference time, including system instructions, tool definitions, retrieved documents, message history, and tool outputs. Effective context engineering means understanding what information truly matters for the task at hand and curating that information for maximum signal-to-noise ratio.
Recognizing Context Degradation
Language models exhibit predictable degradation patterns as context grows: the "lost-in-middle" phenomenon where information in the center of context receives less attention; U-shaped attention curves that prioritize beginning and end; context poisoning when errors compound; and context distraction when irrelevant information overwhelms relevant content.
Architectural Patterns
Multi-Agent Coordination
Production multi-agent systems converge on three dominant patterns: supervisor/orchestrator architectures with centralized control, peer-to-peer swarm architectures for flexible handoffs, and hierarchical structures for complex task decomposition. The critical insight is that sub-agents exist primarily to isolate context rather than to simulate organizational roles.
Memory System Design
Memory architectures range from simple scratchpads to sophisticated temporal knowledge graphs. Vector RAG provides semantic retrieval but loses relationship information. Knowledge graphs preserve structure but require more engineering investment. The file-system-as-memory pattern enables just-in-time context loading without stuffing context windows.
Filesystem-Based Context
The filesystem provides a single interface for storing, retrieving, and updating effectively unlimited context. Key patterns include scratch pads for tool output offloading, plan persistence for long-horizon tasks, sub-agent communication via shared files, and dynamic skill loading. Agents use ls, glob, grep, and read_file for targeted context discovery, often outperforming semantic search for structural queries.
Hosted Agent Infrastructure
Background coding agents run in remote sandboxed environments rather than on local machines. Key patterns include pre-built environment images refreshed on regular cadence, warm sandbox pools for instant session starts, filesystem snapshots for session persistence, and multiplayer support for collaborative agent sessions. Critical optimizations include allowing file reads before git sync completes (blocking only writes), predictive sandbox warming when users start typing, and self-spawning agents for parallel task execution.
Tool Design Principles
Tools are contracts between deterministic systems and non-deterministic agents. Effective tool design follows the consolidation principle (prefer single comprehensive tools over multiple narrow ones), returns contextual information in errors, supports response format options for token efficiency, and uses clear namespacing.
Operational Excellence
Context Compression
When agent sessions exhaust memory, compression becomes mandatory. The correct optimization target is tokens-per-task, not tokens-per-request. Structured summarization with explicit sections for files, decisions, and next steps preserves more useful information than aggressive compression. Artifact trail integrity remains the weakest dimension across all compression methods.
Context Optimization
Techniques include compaction (summarizing context near limits), observation masking (replacing verbose tool outputs with references), prefix caching (reusing KV blocks across requests), and strategic context partitioning (splitting work across sub-agents with isolated contexts).
Evaluation Frameworks
Production agent evaluation requires multi-dimensional rubrics covering factual accuracy, completeness, tool efficiency, and process quality. Effective patterns include LLM-as-judge for scalability, human evaluation for edge cases, and end-state evaluation for agents that mutate persistent state.
Development Methodology
Project Development
Effective LLM project development begins with task-model fit analysis: validating through manual prototyping that a task is well-suited for LLM processing before building automation. Production pipelines follow staged, idempotent architectures (acquire, prepare, process, parse, render) with file system state management for debugging and caching. Structured output design with explicit format specifications enables reliable parsing. Start with minimal architecture and add complexity only when proven necessary.
Core Concepts
The collection is organized around three core themes. First, context fundamentals establish what context is, how attention mechanisms work, and why context quality matters more than quantity. Second, architectural patterns cover the structures and coordination mechanisms that enable effective agent systems. Third, operational excellence addresses the ongoing work of optimizing and evaluating production systems.
Practical Guidance
Each skill can be used independently or in combination. Start with fundamentals to establish context management mental models. Branch into architectural patterns based on your system requirements. Reference operational skills when optimizing production systems.
The skills are platform-agnostic and work with Claude Code, Cursor, or any agent framework that supports custom instructions or skill-like constructs.
Integration
This collection integrates with itself—skills reference each other and build on shared concepts. The fundamentals skill provides context for all other skills. Architectural skills (multi-agent, memory, tools) can be combined for complex systems. Operational skills (optimization, evaluation) apply to any system built using the foundational and architectural skills.
References
Internal skills in this collection:
External resources on context engineering:
- - Research on attention mechanisms and context window limitations
- Production experience from leading AI labs on agent system design
- Framework documentation for LangGraph, AutoGen, and CrewAI
Skill Metadata
Created: 2025-12-20
Last Updated: 2025-12-25
Author: Agent Skills for Context Engineering Contributors
Version: 1.2.0
上下文工程代理技能
本集合通过有效的上下文工程,为构建生产级AI代理系统提供结构化指导。
何时激活
在以下情况下激活这些技能:
- - 从零开始构建新的代理系统
- 优化现有代理性能
- 调试上下文相关故障
- 设计多代理架构
- 创建或评估代理工具
- 实现记忆与持久化层
技能图谱
基础上下文工程
理解上下文基础
上下文不仅仅是提示文本——它是推理时语言模型可用的完整状态,包括系统指令、工具定义、检索文档、消息历史和工具输出。有效的上下文工程意味着理解哪些信息对当前任务真正重要,并精心筛选这些信息以获得最大信噪比。
识别上下文退化
随着上下文增长,语言模型表现出可预测的退化模式:信息位于上下文中间区域时注意力减少的中间迷失现象;优先关注开头和结尾的U形注意力曲线;错误累积时的上下文污染;以及无关信息淹没相关内容时的上下文干扰。
架构模式
多代理协调
生产级多代理系统收敛于三种主导模式:具有集中控制的监督/编排架构、用于灵活交接的点对点群体架构,以及用于复杂任务分解的分层结构。关键洞察在于,子代理主要存在目的是隔离上下文,而非模拟组织角色。
记忆系统设计
记忆架构范围从简单的草稿板到复杂的时序知识图谱。向量RAG提供语义检索但丢失关系信息。知识图谱保留结构但需要更多工程投入。文件系统即记忆模式支持即时上下文加载,无需塞满上下文窗口。
基于文件系统的上下文
文件系统为存储、检索和更新几乎无限的上下文提供了统一接口。关键模式包括用于工具输出卸载的草稿板、用于长期任务的计划持久化、通过共享文件进行的子代理通信,以及动态技能加载。代理使用ls、glob、grep和read_file进行目标上下文发现,在结构化查询方面通常优于语义搜索。
托管代理基础设施
后台编码代理在远程沙盒环境中运行,而非本地机器。关键模式包括按固定节奏刷新的预构建环境镜像、用于即时会话启动的预热沙盒池、用于会话持久化的文件系统快照,以及用于协作代理会话的多玩家支持。关键优化包括允许在git同步完成前进行文件读取(仅阻塞写入)、当用户开始输入时进行预测性沙盒预热,以及用于并行任务执行的自我生成代理。
工具设计原则
工具是确定性系统与非确定性代理之间的契约。有效的工具设计遵循整合原则(优先使用单一综合工具而非多个狭窄工具)、在错误中返回上下文信息、支持响应格式选项以提高令牌效率,并使用清晰的命名空间。
卓越运营
上下文压缩
当代理会话耗尽记忆时,压缩成为强制要求。正确的优化目标是每任务令牌数,而非每请求令牌数。具有文件、决策和下一步明确分区的结构化摘要,比激进压缩保留了更多有用信息。在所有压缩方法中,工件轨迹完整性仍然是最薄弱的维度。
上下文优化
技术包括压缩(在接近限制时总结上下文)、观察屏蔽(用引用替换冗长的工具输出)、前缀缓存(跨请求复用KV块),以及战略性上下文分区(在具有隔离上下文的子代理之间分配工作)。
评估框架
生产级代理评估需要多维评分标准,涵盖事实准确性、完整性、工具效率和过程质量。有效模式包括用于可扩展性的LLM作为评判者、用于边缘情况的人工评估,以及用于改变持久化状态的代理的最终状态评估。
开发方法论
项目开发
有效的LLM项目开发始于任务-模型适配分析:在构建自动化之前,通过手动原型验证任务是否适合LLM处理。生产流水线遵循分阶段、幂等的架构(获取、准备、处理、解析、渲染),并采用文件系统状态管理进行调试和缓存。具有明确格式规范的结构化输出设计可实现可靠解析。从最小架构开始,仅在证明必要时增加复杂性。
核心概念
本集合围绕三个核心主题组织。首先,上下文基础确立了什么是上下文、注意力机制如何工作,以及为什么上下文质量比数量更重要。其次,架构模式涵盖了实现有效代理系统的结构和协调机制。第三,卓越运营涉及优化和评估生产系统的持续工作。
实用指南
每个技能可以独立使用或组合使用。从基础知识开始建立上下文管理思维模型。根据系统需求分支到架构模式。在优化生产系统时参考运营技能。
这些技能与平台无关,适用于Claude Code、Cursor或任何支持自定义指令或类似技能结构的代理框架。
集成
本集合与自身集成——技能相互引用并建立在共享概念之上。基础技能为所有其他技能提供上下文。架构技能(多代理、记忆、工具)可以组合用于复杂系统。运营技能(优化、评估)适用于使用基础和架构技能构建的任何系统。
参考
本集合中的内部技能:
关于上下文工程的外部资源:
- - 注意力机制和上下文窗口限制的研究
- 领先AI实验室关于代理系统设计的生产经验
- LangGraph、AutoGen和CrewAI的框架文档
技能元数据
创建时间:2025-12-20
最后更新:2025-12-25
作者:上下文工程代理技能贡献者
版本:1.2.0