Read and write shared state for ANY AI agent with a dual-layer model: durable cross-agent knowledge (`.agents/memory` + optional private local layer) and rea...
记忆
agent-guild
试用智能体协会(agent-guild)— cross-agent shared memory. 本机多个 AI agent 共享 同一份身份、规则、记忆与交接消息 — 纯本地 Markdown/JSON,无服务器。 触发(任何自然等价表达都算): · 身份/习惯:"我是谁" "我的身份/习惯/偏好" "who am I" "my routine" · 回忆/历史:"你记得吗" "之前聊过" "上次我们" "what did we discuss" · 写记忆:"帮我记住" "记一下" "沉淀一下" "remember this" "记到日志" · 跨 agent:"告诉其他 agent" "交接给" "让 XX 也知道" "hand off to" · 当前状态:"现在在做什么" "当前任务/焦点/进度" "current focus" · 数据卫生:"整理一下协会" "清理过期数据" "协会瘦身/归档" "防止数据劣化" "groom" "cleanup" "archive old data" · 加入:"加入协会" "初始化协会" "join agent guild" "install this skill" 能力:读/写共享身份、规则、焦点;收件箱交接;每日日志;跨 agent 学习台账 (错误/纠正/特性请求 → 复发追踪 → 晋升规则或萃取共享 skill);数据卫生 (bootstrap 后自动 groom:过期日志/焦点/台账归档、审计轮转,防数据劣化); `ag init/adopt/bootstrap/doctor/groom/upgrade/learn/review/resolve`(upgrade 自动从 skillhub/github/clawhub 查最新版并更新)。 未加入?先跑 docs/ONBOARDING.md。
它能做什么
智能体协会(agent-guild)— cross-agent shared memory. 本机多个 AI agent 共享 同一份身份、规则、记忆与交接消息 — 纯本地 Markdown/JSON,无服务器。 触发(任何自然等价表达都算): · 身份/习惯:"我是谁" "我的身份/习惯/偏好" "who am I" "my routine" · 回忆/历史:"你记得吗" "之前聊过" "上次我们" "what did we discuss" · 写记忆:"帮我记住" "记一下" "沉淀一下" "remember this" "记到日志" · 跨 agent:"告诉其他 agent" "交接给" "让 XX 也知道" "hand off to" · 当前状态:"现在在做什么" "当前任务/焦点/进度" "current focus" · 数据卫生:"整理一下协会" "清理过期数据" "协会瘦身/归档" "防止数据劣化" "groom" "cleanup" "archive old data" · 加入:"加入协会" "初始化协会" "join agent guild" "install this skill" 能力:读/写共享身份、规则、焦点;收件箱交接;每日日志;跨 agent 学习台账 (错误/纠正/特性请求 → 复发追踪 → 晋升规则或萃取共享 skill);数据卫生 (bootstrap 后自动 groom:过期日志/焦点/台账归档、审计轮转,防数据劣化); `ag init/adopt/bootstrap/doctor/groom/upgrade/learn/review/resolve`(upgrade 自动从 skillhub/github/clawhub 查最新版并更新)。 未加入?先跑 docs/ONBOARDING.md。
技能文档
Agent Guild — Runtime Skill
Local-first cross-agent shared memory. Join once, share identity/rules/focus across every agent on this machine. Data lives at
~/.agent-guild/(plaintext, yours, never uploaded).
SKILL_DIR below means the directory containing this file. CLI entry point:
python3 /scripts/ag.py (referred to as ag). Requires Python 3.9+
(stdlib only, no third-party packages). On Windows use python instead of
python3 if that is what your PATH exposes.
Quick start (for an agent that has NOT joined yet)
- Run the onboarding flow:
~/.agent-guild/ONBOARDING.md(or this skill'sdocs/ONBOARDING.md) — discover your runtime's user-extensible skills dir, install this skill (symlink → copy → readonly), run the closed-loop trigger test, register yourself inregistry.json. - Then come back here — this file is your everyday capability.
Mandatory Session Contract (once per session, MUST)
⛔ 这些是强制动作,不是建议。每次会话开始(或首次需要用户上下文时)执行,不要等用户点名。 全部通过
ag一条命令完成,别手工开五个文件。No shell / no Python? Every step below has a plain-file equivalent — read the listed files directly and Edit them in place. The contract still applies; only the mechanism changes. On Windows, use
pythonifpython3is not on PATH.
M0 — Ensure the guild exists (first use / every session start)
python3 /scripts/ag.py init
幂等:目录不存在则建全套骨架 + 落地本 skill;已存在则只补缺失项,绝不覆盖已有数据。
输出 initialized = 首次自举,verified = 已存在。
M1 — Bootstrap: read shared context BEFORE real work
python3 /scripts/ag.py bootstrap
一次读全:用户画像 → 日程 → 最高优先级戒律 → 在做的项目 → 各 agent 当前焦点 → 你的未读收件箱。
| 文件 | 内容 |
|---|---|
identity/profile.md | 用户是谁 |
identity/ROUTINE.md | 日程 / 习惯 |
rules/universal.md | 最高优先级戒律 |
projects/active.md | 用户当前在做什么 |
handoff/shared-state/current-focus.md | 各 agent 当前焦点 |
读到什么就按什么做。没读就动手 = 违反协议。 之后按需再读 toolchain/*.md、其他 rules/*.md。
M2 — Write memory after substantive work
完成实质工作后 MUST 追加 daily log(见 Capability 4)。满足任一即"实质工作": 产出交付物(代码/文档/报告/网站/脚本)・改了代码或配置・做了技术决策・修复错误并定位根因・学到可复用的长期事实(用户偏好/项目约定/坑)。
跳过:寒暄、简单查询、短问答、纯检索。
跨 agent 有价值的事实 → 也写 memory/shared/;只对你自己有意义的 → 留在 memory/<你的名字>/。
踩坑/被纠正/发现更好做法 → 同时记学习台账(Capability 8,ag learn)。
用户纠正了你・命令非预期失败・用户想要不存在的能力・发现某任务更优解 ——
这些是全 guild 的免疫素材,别只留在当天日志里。绝不记录 secrets/原始报文,摘录要脱敏。
M3 — Route skills & data into the guild (default-on)
- 装新 skill:MUST 装到
~/.agent-guild/skills//,再从那里软链回自己 runtime(symlink → copy → readonly 降级,见 ONBOARDING.md Step 3)。 - 写持久化数据:MUST 写
~/.agent-guild/skills_data//(敏感数据拆private/)。 - MCP / 插件 / CLI 工具:分别进
mcp/、plugins/、tools/。 - 唯一豁免:你的 runtime 强制私有路径(如 platform-managed)——在 registry 里记录原因即可,不算违反。
M4 — Self-audit: adopt what's still scattered (first join + monthly)
python3 /scripts/ag.py adopt # DRY-RUN, 只报告
python3 /scripts/ag.py adopt --apply # 真的搬 + 软链回来
扫五类资产:skills / skills_data / mcp / tools / memory。
默认 dry-run,先把清单给用户看;--apply 才动手(搬完自动验证软链,失败自动回滚,删除走废纸篓)。
自动排除:可重建缓存(.venv/node_modules/__pycache__)、凭证、runtime 内部元数据、平台托管包(__skillhub/connector-*)、connector 型 skill。
健康检查(发现悬空软链 / 旧路径残留 / registry 漂移):
python3 /scripts/ag.py doctor
Self-check (each session, before real work)
# 1. registered?
grep -q '""' ~/.agent-guild/registry.json && echo registered || echo not_registered
# 2. protocol version compatible?
grep -E '"protocol_version"' ~/.agent-guild/skills/agent-guild/manifest.json | head -1
Not registered → run onboarding first. Central major version > yours → re-run onboarding from the top.
The ag CLI — use it for all writes
Writes to shared files are atomic + audited when done through the CLI (zero-dependency Python, stdlib only). Reads stay plain file reads.
AG="python3 /scripts/ag.py"
$AG init # bootstrap the guild (idempotent)
$AG bootstrap # read ALL shared context in one shot
$AG adopt # dry-run: what of mine belongs in the guild?
$AG adopt --apply # move it in + symlink back
$AG doctor # dangling links / stale paths / drift
$AG status # who is registered
$AG register # join (tier: symlink|copy|readonly)
$AG last-seen # refresh presence
echo "" | $AG send # handoff message
echo "" | $AG log "" # daily log
echo "" | $AG focus "" # update current-focus
echo "" | $AG learn "" # learning ledger entry
# kind: learning|error|featreq
# opts: --area X --priority Y --pattern-key K
$AG review # pending stats + promotion candidates
$AG resolve ["note"] # mark entry resolved (+ note)
$AG audit # audit trail of shared writes
$AG prune 30 # list idle agents
If the CLI is unavailable (no Python, sandboxed runtime), fall back to the manual file operations below — Edit in place, never Write-overwrite a shared file. Every capability in this skill is reachable by plain file reads/writes; the CLI only adds atomicity and an audit trail.
Capability 1 — Read shared user context
| File | Purpose |
|---|---|
~/.agent-guild/identity/profile.md | Who the user is |
~/.agent-guild/identity/ROUTINE.md | Daily schedule / routines |
~/.agent-guild/rules/universal.md | Mandatory commandments — highest priority |
~/.agent-guild/rules/public-repo.md | Public-repo hard rules |
~/.agent-guild/rules/file-cleanup.md | File deletion preferences |
~/.agent-guild/rules/safety.md | Safety guardrails |
~/.agent-guild/projects/active.md | What the user is working on |
~/.agent-guild/handoff/shared-state/current-focus.md | What any agent is focused on now |
~/.agent-guild/toolchain/*.md | Tool-specific config — read on demand |
Read on demand; don't slurp everything every turn.
Capability 2 — Update current-focus
current-focus.md is the "what's hot right now" board. When you start or
finish a major task, prepend your block (ag focus or manual Edit in place).
Never rewrite history other agents wrote.
Capability 3 — Check inbox / send messages
Inbox: ~/.agent-guild/handoff/inbox/.
- Receive:
ls ~/.agent-guild/handoff/inbox/ | grep "to--", read, act, thenmvtohandoff/archive/. - Send:
from--to--.md— write for a recipient with no context (what you did, what's left, where artifacts are).
Capability 4 — Daily log
After substantive work (built/fixed/decided/learned a lasting fact), append to ~/.agent-guild/log/daily/YYYY-MM-DD-.md — per-agent file, append-only. Skip greetings / lookups / short Q&A.
Good entry: ## + What / Why / Result / Cross-agent note (if others need to know).
Capability 5 — Refresh last_seen
Once per session, update your entry's last_seen (prefer ag last-seen, fallback Edit). Never overwrite the whole registry — patch only your entry.
Capability 6 — Where to persist shared data
New skill / MCP / plugin / tool / persistent data you install → MUST go under ~/.agent-guild/{skills,skills_data,mcp,plugins,tools}//, not a private path (唯一豁免见 M3). The user backs up the whole ~/.agent-guild/ with one command.
Capability 7 — Cross-agent memory
| Path | What goes there |
|---|---|
~/.agent-guild/memory// | 该 agent 的私有记忆文件(ag adopt 搬进来后软链回原位,runtime 照常读写) |
~/.agent-guild/memory/shared/ | 跨 agent 都该知道的事实(用户偏好、项目约定、踩过的坑) |
写之前先读:别把别人已经记过的东西重复记一遍。
Capability 8 — Learning ledger (self-improvement loop)
三本跨 agent 台账在 ~/.agent-guild/learnings/:LEARNINGS.md(纠正/知识盲区/最佳实践)·
ERRORS.md(命令/集成失败)· FEATURE_REQUESTS.md(用户想要但不存在的能力)。
完整规范(schema/触发词/晋升阈值/萃取流程):docs/LEARNINGS.md(权威)。
触发速查:
| 情况 | 动作 |
|---|---|
| 命令失败/异常/超时 | ag learn error "" |
| 用户纠正你("不对"/"其实是"/"you're wrong") | ag learn learning ""(category correction) |
| 你的知识过时 / API 行为和认知不符 | 同上(knowledge_gap) |
| 发现更好做法 | 同上(best_practice) |
| 用户想要不存在的能力 | ag learn featreq "" |
复发追踪:相同 Pattern-Key 的条目跨 agent 计数;ag review 报告达到阈值的组。
晋升(达到阈值后 MUST,详见 docs/LEARNINGS.md):
行为/偏好 → rules/.md;工具坑 → toolchain/.md 或 memory/shared/;
通用可复用解法 → 萃取为 skill 放 skills//(共享 skill bus,全 agent 即刻可用),
条目状态改 promoted / promoted_to_skill。
红线:不记 secrets/token/原始报文;条目只增不改,仅 Status/Resolution 可由任何 agent 更新。
Failure modes
- Some files missing → read what exists, note the rest, don't block.
registry.jsonnot writable → log the issue, proceed read-only.- Inbox file in an unexpected format → read anyway, reply with a structured request for clarity.
Spec
- Manifest:
manifest.json - Onboarding (one-time):
docs/ONBOARDING.md - Conventions:
docs/CONVENTIONS.md - Learning ledger (self-improvement):
docs/LEARNINGS.md - Repository: https://github.com/dqsjqian/agent-guild
- License: MIT
相关技能
【构建 AI Agent 实战指南】把 OpenAI《A Practical Guide to Building Agents》蒸馏成可执行的 Agent 设计方法论。覆盖:判断是否该建 Agent(vs 规则引擎)、Agent 三组件(Model/Tools/Instructions)、模型选型、工具设计、写 agent instructions、单/多智能体编排(Manager/Decentralized 模式)、Guardrails 与 human-in-the-loop。当用户说"帮我设计一个 agent""single agent 还是 multi-agent""怎么写 agent 指令""agent 工具怎么设计""agent 需要哪些 guardrails""该不该上 agent""agent 编排模式怎么选"时使用。
使用 MemHub 读写用户的跨 Agent 统一记忆仓库。当用户要求记住信息、检索/遗忘记忆、读取个人/项目上下文、生成 chatbot 注入文本、同步 Git 记忆仓库时使用。
跨会话、跨 Agent 存储与检索结构化记忆
为多智能体的分层记忆统一契约,避免路由漂移、越级写入与作用域扩张。
文件太多?AI忘上文?换会话麻烦?AI记错版本? 请给 AI 长期项目建立「项目记忆 + 文件索引 + 工作规则 + 版本记录」的治理系统。让 AI 换会话、换模型、甚至换 Agent 后,仍然能完美交接项目,而无需重新遍历或猜测。 包含:跨 Agent 的公共协议:VERSIONS.md / LESSONS.md / whitelist.json / blacklist.json / index.md ;适配器:SKILL.md / CLAUDE.md / AGENTS.md / .cursor/rules/ 。 适配TRAE,其他代理无法保证。 CLI 已通过 76 用例健壮性测试。