Communitygithub.com

上下文工程

检查上下文使用限制、监控剩余时间、优化令牌消耗、调试上下文故障。在询问上下文百分比、速率限制、使用警告、上下文优化、智能体架构、记忆系统时使用。

上下文工程 是什么?

上下文工程是一项专门技能,旨在为LLM任务精选最小的高信号令牌集,核心目标是最大化推理质量的同时最小化令牌使用。该技能支持在Claude Code等AI智能体平台上使用,适用于设计/调试智能体系统、优化成本/延迟、构建多智能体协调、实现记忆系统和评估智能体性能等场景。它基于五大核心原则:上下文质量优先于数量、注意力有限(U形曲线)、渐进式信息揭示、通过分区隔离防止退化、先测量再优化。技能提供了详细的快速参考表,涵盖上下文基础、退化、优化、压缩、记忆、多智能体模式、评估、工具设计、管道开发和运行时感知等主题。它还定义了关键指标(如令牌利用率警告阈值70%、优化触发阈值80%)、四桶策略(写入、选择、压缩、隔离)以及反模式(如详尽上下文优于精选上下文、中间位置放置关键信息等)。运行时感知功能通过PostToolUse钩子自动注入使用情况,包括Claude使用限制和上下文窗口使用百分比,并设置了70%警告和90%临界阈值。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/majiayu000/claude-skill-registry-data/tree/HEAD/context-management/context-engineering-hoanghd218-landing-page-ai-kien-2

在你喜欢的 AI 中提问

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

文档

上下文工程 是做什么的?

上下文工程旨在为LLM任务精选最小的高信号令牌集。目标:在最大化推理质量的同时,最小化令牌使用。

何时激活

  • 设计/调试智能体系统
  • 上下文限制影响性能
  • 优化成本/延迟
  • 构建多智能体协调
  • 实现记忆系统
  • 评估智能体性能
  • 开发基于LLM的管道

核心原则

  1. 上下文质量 > 数量 - 高信号令牌优于详尽内容
  2. 注意力是有限的 - U形曲线有利于开头/结尾位置
  3. 渐进式披露 - 及时加载信息
  4. 隔离防止退化 - 跨子智能体分区工作
  5. 先测量再优化 - 了解你的基线

重要提示:

  • 为简洁起见,牺牲语法。
  • 在保证高质量的同时,确保令牌效率。
  • 将这些规则传递给子智能体。

快速参考

主题使用场景参考
基础理解上下文结构、注意力机制context-fundamentals.md
退化调试故障、中间丢失、注入context-degradation.md
优化压缩、掩码、缓存、分区context-optimization.md
压缩长会话、摘要策略context-compression.md
记忆跨会话持久化、知识图谱memory-systems.md
多智能体协调模式、上下文隔离multi-agent-patterns.md
评估测试智能体、LLM作为评判者、指标evaluation.md
工具设计工具整合、描述工程tool-design.md
管道项目开发、批处理project-development.md
运行时感知使用限制、上下文窗口监控runtime-awareness.md

关键指标

  • 令牌利用率:70%警告,80%触发优化
  • 令牌方差:解释了80%的智能体性能差异
  • 多智能体成本:约为单智能体基线的15倍
  • 压缩目标:减少50-70%,质量损失<5%
  • 缓存命中目标:稳定工作负载达到70%以上

四桶策略

  1. 写入:将上下文保存到外部(草稿板、文件)
  2. 选择:仅拉取相关上下文(检索、过滤)
  3. 压缩:减少令牌同时保留信息(摘要)
  4. 隔离:跨子智能体拆分(分区)

反模式

  • 详尽上下文优于精选上下文
  • 关键信息放在中间位置
  • 在达到限制前没有压缩触发
  • 单智能体处理可并行任务
  • 工具缺乏清晰描述

指南

  1. 将关键信息放在上下文的开头/结尾
  2. 在利用率达到70-80%时实施压缩
  3. 使用子智能体进行上下文隔离,而非角色扮演
  4. 使用4问题框架(什么、何时、输入、返回)设计工具
  5. 优化每个任务的令牌,而非每个请求的令牌
  6. 通过基于探测的评估进行验证
  7. 在生产环境中监控KV缓存命中率
  8. 从最小方案开始,仅在证明必要时增加复杂度

运行时感知

系统通过PostToolUse钩子自动注入使用感知:

<usage-awareness>
Claude使用限制:5h=45%,7d=32%
上下文窗口使用:67%
</usage-awareness>

阈值:

  • 70%:警告 - 考虑优化/压缩
  • 90%:临界 - 需要立即采取行动

数据来源:

  • 使用限制:Anthropic OAuth API(https://api.anthropic.com/api/oauth/usage)
  • 上下文窗口:状态栏临时文件(/tmp/ck-context-{session_id}.json)

脚本

Individual skills in this repo

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

majiayu000/claude-skill-registry-data

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry-data

Edit existing BMAD agents while maintaining compliance

majiayu000/claude-skill-registry-data

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry-data

Edit existing BMAD modules while maintaining coherence

majiayu000/claude-skill-registry-data

Analyzes current state and user query to answer BMad questions or recommend the next workflow or agent. Use when user says what should I do next, what do I do now, or asks a question about BMad

majiayu000/claude-skill-registry-data

Build AI agents with Google ADK Python (Agent Development Kit). Use for multi-agent systems, workflow agents (sequential/parallel/loop), Vertex AI deployment, tool integration, human-in-the-loop.

majiayu000/claude-skill-registry-data

Build AI agents with Google ADK Python (Agent Development Kit). Use for multi-agent systems, workflow agents (sequential/parallel/loop), Vertex AI deployment, tool integration, human-in-the-loop.

majiayu000/claude-skill-registry-data

Portfolio allocation and rebalancing optimizer. Manages asset allocation across stocks/cash/bonds, performs periodic rebalancing, and ensures diversification according to market regime and risk tolerance.

majiayu000/claude-skill-registry-data

Create a hilarious and ultra-realistic video of an anthropomorphic animal acting like a human vlogger in a real-world setting.

majiayu000/claude-skill-registry-data

Speech-to-text transcription and translation via OpenAI Audio API -- models, response formats, timestamps, prompting, streaming, chunking, and diarization

majiayu000/claude-skill-registry-data

This skill should be used when the user asks about libraries, frameworks, API references, or needs code examples. Activates for setup questions, code generation involving libraries, or mentions of specific frameworks like React, Vue, Next.js, Prisma, Supabase, etc.

majiayu000/claude-skill-registry-data

小省导购员数字人带货版即梦视频提示词生成系统,基于四大智能体协同(提示词生成师、质量管控师、知识库运维师、跨环节适配师),按照"主体+运动+场景+(镜头语言+光影+氛围)"公式输出中英文双版提示词,适配5s短视频。确保人物一致性、视觉连贯性、情绪连贯性,支持知识库智能复用和跨工具适配(Suno音乐、AI绘画),为数字人带货视频提供高质量提示词生成服务。

majiayu000/claude-skill-registry-data

Upload and manage files using Google Gemini File API via scripts/. Use for uploading images, audio, video, PDFs, and other files for use with Gemini models. Supports file upload, status checking, and file management. Triggers on "upload file", "file API", "upload image", "upload PDF", "upload video", "file management".

majiayu000/claude-skill-registry-data

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry-data

Analyze images/audio/video with Gemini API (better vision than Claude). Generate images (Imagen 4), videos (Veo 3). Use for vision analysis, transcription, OCR, design extraction, multimodal AI.

majiayu000/claude-skill-registry-data

Skill for discovering and researching autonomous AI agents, tools, and ecosystems using the AgentFolio directory.

majiayu000/claude-skill-registry-data

Conduct domain and industry research. Use when the user says "lets create a research report on [domain or industry]

majiayu000/claude-skill-registry-data

Conduct market research on competition and customers. Use when the user says "create a market research report about [business idea]".

majiayu000/claude-skill-registry-data

Conduct technical research on technologies and architecture. Use when the user says "create a technical research report on [topic]".

majiayu000/claude-skill-registry-data

Builds, edit or validate Agent Skill through conversational discovery. Use when the user requests to "Create an Agent", "Optimize an Agent" or "Edit an Agent".

相关技能