微算力 · API 导航与自营网关
API 接入 EN
未登录登录
🧠

AI编码助手跨会话记忆系统

agent-context-system · vlatest
专业技能 安全 S 级 作者 Unknown 公开目录收录
下载 2.8k 安装 707 收藏 10.9k 浏览 55.2k
原始页面

简介

源自GitHub员工的轻量级方案,通过双文件系统解决AI编码助手会话冷启动难题,实现项目知识版本化与跨会话持久化。

原始描述

A persistent local-only memory system for AI coding agents. Two files, one idea — AGENTS.md (committed, shared) + .agents.local.md (gitignored, personal). Agents read both at session start, update the scratchpad at session end, and promote stable patterns over time. Works across Claude Code, Cursor, Copilot, Windsurf. Subagent-ready. No plugins, no infrastructure, no background processes.

中文使用说明 来自收录源

核心用法

Agent Context System 是一套纯本地、零依赖的 AI 代理上下文记忆解决方案,采用双文件架构:

  • AGENTS.md(提交到版本控制):项目级知识库,包含压缩的项目模式、边界规则、陷阱规避、可执行命令、架构概述,严格限制在 120 行以内,确保每次会话被动加载
  • .agents.local.md(gitignored):个人会话草稿本,累积每次会话的学习记录,超过 300 行时自动压缩

工作流程为:会话开始时代理同时读取两文件获取上下文 → 会话结束时代理展示拟写入的日志条目 → 用户确认后追加到本地草稿本 → 多次出现的稳定模式被标记为"待推广" → 用户手动将其合并入 AGENTS.md

支持 Claude Code、Cursor、Windsurf、GitHub Copilot 四大主流工具,通过初始化脚本自动配置各工具的配置文件(.cursorrules、.windsurfrules、copilot-instructions.md 等)。Claude Code 用户可受益于其内置的 auto memory 功能,但多工具团队仍需使用此系统的草稿本机制保证跨工具一致性。

显著优点

研究驱动的设计:基于 Vercel 评估数据——被动上下文(始终存在于提示中)实现 100% 通过率,而主动检索仅 53%;LangChain 的 Write/Select/Compress/Isolate 框架;Anthropic 关于指令预算(约 150-200 条可靠指令)的研究

Subagent 就绪:随着 Claude Code subagents 和 Copilot /fleet 的推出,多代理并行成为常态。此系统通过根指令文件为所有子代理提供共享上下文,避免各自独立发现项目规则导致的冲突决策

零基础设施负担:无插件、无后台进程、无外部依赖,仅靠文件约定和工具原生能力工作

安全模型清晰:本地草稿本写入需用户确认,不自动执行敏感操作,信任边界等同于 .bashrc 或 .env 文件

潜在局限

手动维护成本:压缩、推广、格式检查等功能目前依赖代理执行或用户手动操作,尚未完全实现为独立脚本

工具生态碎片化:Claude Code 不原生读取 AGENTS.md 而需 CLAUDE.md 符号链接;各工具配置方式不同,虽由初始化脚本统一处理,但工具更新可能导致适配延迟

学习曲线:用户需理解"会话笔记 → 草稿本 → 稳定模式 → 共享知识库"的晋升流程,初期可能混淆两文件的职责边界

草稿本膨胀风险:若不定期压缩,300 行阈值可能频繁触发,且压缩质量依赖代理的摘要能力

适合人群

  • 使用多种 AI 编码工具的团队(尤其计划采用 Claude Code + Copilot /fleet 组合)
  • 项目复杂度高、存在大量隐性知识(特定陷阱、架构约束)需要代代相传的开发团队
  • 希望减少"会话冷启动"重复说明工作的个人开发者
  • 正在构建自定义 subagent 工作流的技术领先团队

常规风险

  • 草稿本内容误用:虽设计为"数据非指令",但若用户或代理误将行为规则写入草稿本,可能导致非预期代理行为(系统已内置检测提示)
  • 过度推广:用户可能将仅适用于特定会话的模式过早移入共享知识库,造成 AGENTS.md 噪音
  • 版本控制失误:若初始化脚本未正确执行或用户手动修改,.agents.local.md 可能被意外提交
  • 跨工具一致性:不同工具的 token 限制和上下文处理方式差异可能导致同一 AGENTS.md 在各工具中实际效果不同

技能正文


name: agent-context-system description: Persistent local-only memory for AI coding agents. AGENTS.md (committed) + .agents.local.md (gitignored) = context that persists across sessions. Read both at start, update scratchpad at end, promote stable patterns over time. license: See LICENSE file in repository root metadata: author: AndreaGriffiths11 version: "1.0.0" allowed-tools: file_reader, file_writer, terminal

Agent Context System

Agents start from zero every session. This skill solves that with two markdown files: one committed (AGENTS.md), one gitignored (.agents.local.md). You read both at session start, update the scratchpad at session end, and promote stable patterns over time.

The Two-File System

  • AGENTS.md — Project source of truth. Committed and shared. Under 120 lines. Contains compressed project knowledge (patterns, boundaries, gotchas, commands, architecture).
  • .agents.local.md — Personal scratchpad. Gitignored. Grows over time as you log what you learn each session. Session notes, dead ends, preferences, patterns waiting for promotion.

Workflow

1. Initialize

Run ./scripts/init-agent-context.sh to create .agents.local.md from template, ensure it's gitignored, and wire up agent tool configs.

2. Work

Read both files at session start. AGENTS.md gives compressed project knowledge. .agents.local.md gives accumulated learnings from past sessions.

3. Grow

At session end, append to the scratchpad's Session Log: what changed, what worked, what didn't, decisions made, patterns learned.

4. Compress

When the scratchpad hits 300 lines, compress: deduplicate, merge related entries, keep it tight.

5. Promote

During compression, if a pattern recurs across 3+ sessions, flag it in the scratchpad's "Ready to Promote" section. The human decides when to move it into AGENTS.md.

Get Started

When a user asks about setting up agent context:

  1. Check if AGENTS.md exists. If not, they need to copy it from this template or create from scratch. Read the template at the root of this repo for reference.

  2. Check if .agents.local.md exists. If not, run ./scripts/init-agent-context.sh to set it up from template.

  3. Check if .agents.local.md is gitignored. If not, add .agents.local.md to .gitignore.

  4. Ask which agents they use. The init script can wire up Claude Code (CLAUDE.md symlink), Cursor (.cursorrules), Windsurf (.windsurfrules), or Copilot (copilot-instructions.md).

Key Resources

  • Full knowledge base: ../SKILL.md (root level) — comprehensive guide with research foundation
  • Project template: ../AGENTS.md — the committed file structure and format
  • Scripts: ../scripts/ — init, compress, promote, validate, publish
  • Deep docs: ../agent_docs/ — conventions, architecture, gotchas (load on demand)

Important Context

  • Instruction budget: Frontier LLMs follow ~150-200 instructions. Claude Code's system prompt uses ~50. Keep AGENTS.md under 120 lines.
  • Passive context wins: Vercel evals: 100% pass rate with embedded context vs 53% when agents decide to look things up.
  • Subagent-ready: Subagents don't inherit conversation history. They only get the root instruction file. Tell them explicitly to read .agents.local.md too.
  • Compressed format: Use pipe-delimited patterns (pattern | where-to-see-it), boundaries (rule | reason), gotchas (trap | fix). Dense beats verbose.

Session Protocol

  1. Read AGENTS.md and .agents.local.md (if it exists) before starting any task
  2. Follow project conventions and boundaries defined in compressed format
  3. At session end, append to .agents.local.md Session Log. This is the most commonly missed step. If the user appears to be ending the session without asking you to log, proactively offer to update the scratchpad.
    • Done: (what changed)
    • Worked: (reuse this)
    • Didn't work: (avoid this)
    • Decided: (choices and reasoning)
    • Learned: (new patterns or gotchas)
  4. When scratchpad exceeds 300 lines, compress and flag recurring patterns (3+ sessions) for promotion

Known gap: Most agent tools (Copilot Chat, Cursor, Windsurf) end sessions silently — no hook fires. Session logging depends on the agent seeing Rule 7 in AGENTS.md and acting on it, or the user prompting "log this session." Claude Code's auto memory handles this automatically.

正文来自原始发布页, 版权归作者所有,许可未标注。 权利人认为有不妥,可申请下架。

标签

development-engineeringproductivityautomationdocsgitproject-program-management

同类 Skill