session-guard
它能做什么
这个智能体帮助你跟踪又长又复杂的任务。它会检查 AI 是否遵守既定规则,并防止它“忘记”之前约定好的内容,尤其是在对话过长或部分内容丢失的时候。
适用场景
- ✓当 AI 已经完成了很多步骤(超过 40 步)时。
- ✓当 AI 开始做出与之前约定的规则不一致的事情时。
- ✓当 AI 丢失了部分对话内容(上下文压缩)之后。
技能链接
https://github.com/wshobson/agents/blob/main/plugins/skill-forge-essentials/skills/session-guard/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“AI,请检查你是否仍在遵守我们一开始约定的文件命名规则。”
每周 5 个新技能,1 分钟读完。
工作原理
它通过观察 AI 的行为来工作。如果 AI 做的事情太多,或者开始偏离方向,它就会提醒 AI 注意重要规则,或者建议把任务拆分开,以免混乱。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Session Guard
Overview
Long sessions corrupt silently. Context compaction drops instructions unannounced. Hooks don't fix it (confirmed by multiple developers on GitHub issues #19471, #9796, #64171). This skill prevents both through behavioral self-enforcement: monitor health, anchor critical rules through compaction, split before damage occurs. No packages, no databases - pure behavioral enforcement that works in every harness.
When to Use
- Session exceeds 40 tool calls
- Agent contradicts earlier decisions
- Style/naming conventions start drifting
- After any context compaction event
- Task scope growing unbounded
Health Signals
| Signal | Threshold | Action |
|---|---|---|
| Tool call count | >40 | YELLOW: checkpoint + recite critical rules |
| Tool call count | >60 | RED: split or compact with anchor |
| Agent contradicts earlier decision | Any | VERIFY: re-read source of truth |
| Style/naming drift | Any | RECITE: state the active rules aloud |
| File read returns unexpected content | Any | RE-READ: don't trust cached state |
| Task scope growing unbounded | Continuous | SPLIT: one task per session |
Protocol
Green Zone (0-40 tool calls)
Normal operation. No intervention needed.
Yellow Zone (40-60 tool calls)
- CHECKPOINT - summarize progress in one paragraph
- RECITE - state the 3-5 most critical active rules aloud: "Active rules: [naming convention], [file structure], [error handling pattern], [testing requirement]"
- ASSESS - almost done? Push through. Not done? Prepare split.
- REDUCE - no exploratory reads. Only targeted operations.
Red Zone (60+ tool calls OR drift signal)
- STOP - do not make more tool calls
- VERIFY - re-read project rules (don't trust memory)
- CHECKPOINT - write state to handoff document
- SPLIT - create handoff, suggest fresh session
Context Anchoring (anti-compaction)
When compaction has occurred (sudden loss of earlier context, or after /compact):
- RE-READ the project's rules file immediately
- RECITE the 3-5 critical rules aloud in your response
- VERIFY your planned next action matches those rules before executing
- If uncertain about ANY prior decision, RE-READ the source file - don't guess
What survives compaction:
- Most recent user messages (high priority)
- Currently-invoked skill body (capped at 5K tokens, oldest dropped first)
- Git status and project structure
- File contents read AFTER compaction
What gets LOST in compaction:
- Decisions made early in conversation
- Architectural rules stated only verbally (not in files)
- Context from tool outputs (file reads, command outputs)
Compaction-Safe Pattern
Keep critical instructions in FILES (CLAUDE.md, CONTEXT.md), NOT in conversation. If a rule matters, it must live in a file the agent can re-read - not in something agreed on earlier.
Common Mistakes
- Trusting that you remember the rules after 50+ tool calls (you don't - re-read)
- Re-reading EVERYTHING to be safe (wastes tool calls - be targeted)
- Feeling fine therefore assuming context is fine (compaction is SILENT)
- Splitting AFTER noticing problems (split BEFORE - prevention, not recovery)
Why This Matters
Context compaction is the #1 unsolved platform problem in 2026. Hooks don't fix it (confirmed: the agent ignores post-compaction injections because the compaction summary creates narrative momentum). This skill is the lightweight behavioral countermeasure: no infrastructure, no packages - disciplined self-monitoring that works in every harness.
常见问题
什么是“上下文压缩”(context compaction)?
为了节省内存,AI 会丢弃对话中较早的部分。这可能导致它“忘记”重要的规则或决定。
AI 为什么会“忘记”内容?
在非常长的对话中,AI 很难记住所有指令和规则。上下文压缩会删除旧信息,使这个问题更加严重。
我怎样确保 AI 遵守规则?
把最重要的规则写进文本文件,让 AI 可以随时重新阅读。这样即使对话被压缩,AI 也能通过查阅文件来记起这些规则。
详情
作者的原始描述
Use when working on complex multi-step tasks, when a session is getting long (40+ tool calls), when the agent starts ignoring rules it followed earlier, when conventions drift, when output quality seems to degrade, or after any context compaction event. Prevents long-session corruption AND context compaction amnesia through behavioral self-enforcement.
repo: wshobson/agents
热度
- GitHub 星标
- 41k
- 排名
- #6789
- 许可证
- MIT
- 更新时间
- 2026/10/15
评论
- …