Agent 群體的集體潛意識:Shadow Brain + claudectl + Beads 構建多 Agent 記憶基礎設施
The background agents are still searching. I’ll wait for their results before writing.
Agent 群體的集體潛意識:Shadow Brain + claudectl + Beads 構建多 Agent 記憶基礎設施
---
title: "Agent 群體的集體潛意識:Shadow Brain + claudectl + Beads 構建多 Agent 記憶基礎設施"
date: "2026-06-16"
slug: "agent-shadow-brain-claudectl-beads-agent"
summary: "十幾個 AI agent 一齊做嘢,點樣唔撞車、唔失憶?Shadow Brain 嘅共享記憶、claudectl 嘅 swarm orchestration、Beads 嘅 graph-based state 同 arcrift 嘅 lifecycle management,構成多 agent 系統嘅集體潛意識基礎設施。"
tags:
- build
- multi-agent
- memory-infrastructure
- swarm-orchestration
- ai-engineering
draft: false
lang: zh-Hant
---
一個人寫 code 同十個人寫 code,最大分別唔係速度,而係溝通成本。十個 developer 各自改緊同一份 codebase,如果有人唔知其他人改咗啲乜,一日之內就會 merge conflict 到七彩。AI agent 都一樣——當你由一個 agent 進化到十幾個 agent 平行作戰,最頭痛嘅問題唔係 prompting,而係 **記憶點樣共享**。
我哋由一個 agent 獨自完成 task 嘅時代,走到 swarm 式協作嘅臨界點。獨立 agent 嘅能力已經好成熟:俾個 prompt 佢就做到嘢。但十幾個 agent 一齊做 project,冇 shared context 的話,每個 agent 都係重新發明車輪——佢唔知隔籬個 agent 啱啱解決咗邊個 bug,唔知個 config 係咪已經改過,唔知個 PR 係咪已經 merged。呢個唔係 prompting 問題,而係 infrastructure 問題。
## 集體潛意識:Shadow Brain 嘅共享記憶層
如果話每個 agent 有一個短期工作記憶(context window),咁 Shadow Brain 就係佢哋嘅長期集體潛意識。Shadow Brain 嘅做法好直接:將 agent 之間產生嘅關鍵資訊——log、decisions、patterns、failures——寫入一個共享嘅向量資料庫同 graph store,而唔係留喺 agent 嘅 ephemeral context 入面。
呢個唔係 caching,而係組織化嘅經驗累積。例如 agent A 發現某個 API endpoint 有 rate limit issue,佢將呢個 observation 寫入 Shadow Brain 之後,agent B 下次 call 同一個 API 之前會自動檢索到呢條經驗,自動加 retry logic。呢種「跨 agent 學習」唔需要任何人工干預,純粹靠共享記憶層自然發生。
關鍵係 Shadow Brain 唔係一個 passive storage,而係 active inference engine。佢唔只係儲起啲 data,而係會根據當前 agent 嘅 context 主動推測佢可能需要邊啲記憶,提前 retrieve 過去嘅經驗。呢種 predictive memory retrieval 先係多 agent 系統真正有生產力嘅原因——agent 唔需要知道自己需要搵咩記憶,記憶會自動搵返佢。
入面用嘅技術 stack 係 graph + vector hybrid:graph 保存關係(呢個 agent 改過呢個 file、呢個 decision 關聯呢個 outcome),vector 做模糊相似度搜尋(有個 agent 見過類似問題?搵出嚟)。兩個加埋,先做到「記憶唔只係搜到,而係有關聯脈絡」。
## 集體潛意識:Shadow Brain 嘅共享記憶層
如果話每個 agent 有一個短期工作記憶(context window),咁 Shadow Brain 就係佢哋嘅長期集體潛意識。Shadow Brain 嘅做法好直接:將 agent 之間產生嘅關鍵資訊——log、decisions、patterns、failures——寫入一個共享嘅向量資料庫同 graph store,而唔係留喺 agent 嘅 ephemeral context 入面。
呢個唔係 caching,而係組織化嘅經驗累積。例如 agent A 發現某個 API endpoint 有 rate limit issue,佢將呢個 observation 寫入 Shadow Brain 之後,agent B 下次 call 同一個 API 之前會自動檢索到呢條經驗,自動加 retry logic。呢種「跨 agent 學習」唔需要任何人工干預,純粹靠共享記憶層自然發生。
關鍵係 Shadow Brain 唔係一個 passive storage,而係 active inference engine。佢唔只係儲起啲 data,而係會根據當前 agent 嘅 context 主動推測佢可能需要邊啲記憶,提前 retrieve 過去嘅經驗。呢種 predictive memory retrieval 先係多 agent 系統真正有生產力嘅原因——agent 唔需要知道自己需要搵咩記憶,記憶會自動搵返佢。
入面用嘅技術 stack 係 graph + vector hybrid:graph 保存關係(呢個 agent 改過呢個 file、呢個 decision 關聯呢個 outcome),vector 做模糊相似度搜尋(有個 agent 見過類似問題?搵出嚟)。兩個加埋,先做到「記憶唔只係搜到,而係有關聯脈絡」。
## claudectl:Swarm 嘅神經系統同控制平面
Shared memory 只係 infrastructure 嘅一半。另一半係點樣 control 呢班 agent——點樣 dispatch、monitor、recover。呢度就係 claudectl 嘅角色。
Claudectl 係 swarm 嘅 control plane,類似 k8s 嘅 control plane 之於 containers。佢管理 agent 嘅 lifecycle:由 task dispatch、resource allocation、health check、到 failure recovery。但同傳統 orchestration 最唔同嘅係,claudectl 嘅 decision-making 本身都係 AI-driven——佢唔係行 static rules,而係根據當前 system state 同歷史數據動態決定點樣分配 agent。
例如一個複雜嘅 feature implementation:claudectl 會先分析任務結構,決定拆成幾多個 sub-task,每個 sub-task 用邊個 specialist agent,然後平行 dispatch。如果某個 agent 卡住咗(context window 爆咗、遇到 ambiguity、連續 fail),claudectl 唔係 hard crash,而係識得 reroute 去另一個 agent 或者調整 task scope。
更重要嘅係,claudectl 同 Shadow Brain 係 deep-integrated。Claudectl 唔只係睇住 agent 嘅 health,佢讀緊 Shadow Brain 嘅訊號——如果某個 agent 做緊嘅嘢同歷史 pattern 偏離太多,claudectl 會介入。呢種「collective subconscious → control plane → individual agents」嘅 feedback loop,係多 agent 系統由「幾個 script 各自行」進化到「真正 orchestrated swarm」嘅分野。
## Beads + arcrift:Graph-Based Issue Tracking 同 Task Lifecycle
Agent 做嘢唔係一次過嘅。一個 task 可能橫跨幾日、來回十幾次 iteration。點樣 track 呢啲 progress?點樣知道邊啲 decisions 已經做咗、邊啲 pending、邊啲做錯咗要 redo?呢個就係 Beads 同 arcrift 嘅領域。
Beads 嘅概念好優雅:每個 task 嘅 state 唔係 linear sequence,而係 graph。一個 task 可以 split 成多個 parallel strands,可以 merge、可以有 dependency、可以 rollback。每粒「bead」代表一個 atomic state——一個 decision、一個 file change、一個 test result——然後 beads 之間嘅 edges 代表 causal relationships。呢種 graph-based state representation 比傳統嘅 task queue 強大得多,因為佢 capture 到 real work 嘅非線性本質:agent 試緊 A path,發現唔 work,退回 branching point,試 B path,呢啲全部記錄喺 beads graph 入面。
Arcrift 就係負責做 beads 嘅 lifecycle management。佢管理 beads 嘅 creation、traversal、garbage collection。當 beads graph 太大(幾千粒 beads)嗰陣,arcrift 決定邊啲 beads 可以 archive、邊啲要 keep 作為 reference、邊啲要 merge 成 summary bead。呢種記憶壓縮機制防止咗「記憶 infrastructure 本身變成 performance bottleneck」嘅 paradox。
將呢三個 layers 疊起嚟:Shadow Brain 係 shared memory + inference,claudectl 係 orchestration + control,Beads + arcrift 係 state tracking + lifecycle。佢哋一齊形成咗一個完整嘅多 agent 記憶 infrastructure。
## 對你嘅實戰建議
如果你今日開始搞多 agent 系統,唔好一開始就諗 swarm intelligence 或者 emergent behavior。先解決基礎問題:
**第一,共享記憶要 infra-level,唔係 app-level。** 唔好喺 agent prompt 入面手動加啲「記得睇返之前嘅 conversation history」呢啲 hack。用 vector store + graph store 做底層 infrastructure,每個 agent 嘅 read/write 係 automatic,唔係 opt-in。
**第二,orchestration 要 adaptive,唔係 deterministic。** Agent 嘅行為係 probabilistic,你個 orchestration layer 都要係。Static DAG 唔 work——你需要一個 control plane 識得根據 real-time feedback 調整。
**第三,state tracking 要 graph-based,唔係 linear。** 真實開發工作係 branching 同 merging 嘅,唔係 sequential checklist。用 beads 或者類似嘅 graph structure 去 capture causality。
多 agent 系統嘅 bottleneck 永遠唔係 agent 嘅 intelligence,而係佢哋之間點樣 share context、點樣協調、點樣唔重複做同一件事。Shadow Brain、claudectl、Beads 呢條 stack 俾咗一個具體嘅 architectural pattern 去解決呢個問題。下一個 stage——真正嘅 agent collective intelligence——就係由呢啲 infrastructure 開始。