一、GBrain是什么:解决AI Agent的无状态困境
I. What is GBrain: Solving the Stateless Dilemma of AI Agents
2026年4月,Y Combinator CEO Garry Tan宣布开源其个人知识系统GBrain,他在X上写道:"我希望所有人都能拥有自己的'个人迷你AGI'。"这个项目在GitHub上线后迅速获得超过5000颗星,成为技术社区热议的话题。
In April 2026, Y Combinator CEO Garry Tan open-sourced his personal knowledge system GBrain, writing on X: "I want everyone to have their own 'personal mini-AGI'." The project quickly gained over 5,000 stars on GitHub, becoming a hot topic in the tech community.
传统的AI智能体(Agent)面临一个核心问题:**无状态困境(Stateless Dilemma)**——每次会话结束后,所有上下文信息都被清零。用户不得不重复输入背景信息,Agent无法积累知识。这就像一个每次见面都失忆的朋友,关系永远无法深入。
Traditional AI agents face a core problem: the **Stateless Dilemma** — every session clears all context. Users must repeatedly input background information, and agents cannot accumulate knowledge. It's like a friend who forgets everything each time you meet.
GBrain的核心设计正是解决这个问题:让Agent经历**读取—对话—写入**的闭环。当有新信号进入系统(邮件、会议录音、推文、日历变动),Agent会先查询已有知识库理解上下文,生成回应后将新知识写回数据库。Tan称之为"**大脑-Agent循环**",这个循环每转一圈,Agent就比上一圈更懂你。
GBrain's core design solves this: letting agents experience a **Read—Respond—Write** loop. When new signals arrive (emails, meeting recordings, tweets, calendar changes), the agent first queries the knowledge base, generates a response, then writes new knowledge back. Tan calls this the **"Brain-Agent Loop"** — each rotation makes the agent smarter than the last.
"让AI成为你的外部大脑,而不是另一个聊天机器人。"
"Make AI your external brain, not another chatbot."
— Garry Tan
二、系统架构解析
II. System Architecture Analysis
2.1 整体架构
2.1 Overall Architecture
┌──────────────────┐ ┌───────────────┐ ┌──────────────────┐
│ Brain Repo │ │ GBrain │ │ AI Agent │
│ (git) │ │ (retrieval) │ │ (read/write) │
│ │ │ │ │ │
│ markdown files │───▶│ Postgres + │◀───│ skills define │
│ = source of │ │ pgvector │ │ HOW to use the │
│ truth │ │ │ │ brain │
│ │◀───│ hybrid │ │ │
│ human can │ │ search │ │ entity detect │
│ always read │ │ (vector + │ │ enrich │
│ & edit │ │ keyword + │ │ ingest │
│ │ │ RRF) │ │ brief │
└──────────────────┘ └───────────────┘ └──────────────────┘
GBrain采用三层架构设计:
GBrain uses a three-layer architecture:
- Brain Repo:Git仓库存储Markdown文件,是知识的真相来源。人类可以随时读取和编辑。
- Brain Repo: Git repository storing Markdown files as the source of truth. Humans can read and edit anytime.
- GBrain Engine:检索层,基于Postgres+pgvector,提供混合搜索能力。
- GBrain Engine: Retrieval layer based on Postgres+pgvector with hybrid search capabilities.
- AI Agent:通过Skills定义的行为模式读写知识库。
- AI Agent: Reads and writes knowledge base through behavior patterns defined in Skills.
2.2 核心知识模型:Compiled Truth + Timeline
2.2 Core Knowledge Model: Compiled Truth + Timeline
GBrain的知识模型来自Andrej Karpathy的LLM Wiki设计,核心是"上线/下线"分离结构。每个页面遵循统一格式:
GBrain's knowledge model comes from Andrej Karpathy's LLM Wiki design, with a core "Above/Below the Line" separation. Each page follows a unified format:
---
type: person
title: Pedro Franceschi
tags: [yc-alum, founder, ai]
---
# Pedro Franceschi
## State
Current CEO of Brex, based in San Francisco.
Previously co-founded Pagar.me (acquired 2016).
Board member at River AI since 2024.
## Assessment
Strong technical background (coded since 14).
Network: YC, fintech, Brazil startup scene.
Key relationship: [Harley Finkelstein](../people/harley-finkelstein.md).
## Open Threads
- [ ] Follow up on River AI board seat context
- [ ] Check if still involved with any Brazil investments
---
## Timeline
**2026-04-05** | Meeting — Discussed River AI strategy...
**2025-12-15** | Email — Shared Brex Q4 update...
**2024-03-20** | News — Joined River AI board...
上线(Above the Line)包含:
Above the Line contains:
- State:当前状态,最新信息,会被Agent自动重写
- State: Current status, latest info, auto-rewritten by agent
- Assessment:你的判断和评估
- Assessment: Your judgment and evaluation
- Open Threads:待办事项、开放问题
- Open Threads: TODOs, open questions
下线(Below the Line)包含:
Below the Line contains:
- Timeline:append-only的原始证据,每次更新只追加不修改
- Timeline: Append-only original evidence, never modified on updates
这种设计解决了知识管理的核心矛盾:知识会过时,证据不会。如果一个人明天离职,State要改,但Timeline里的"2026-04-05讨论了River AI策略"永远是对的。
This design solves the core contradiction in knowledge management: knowledge becomes outdated, evidence doesn't. If someone leaves tomorrow, State changes, but "2026-04-05 discussed River AI strategy" in Timeline is always true.
三、核心技术实现
III. Core Technical Implementation
3.1 PGLite:零配置的嵌入式Postgres
3.1 PGLite: Zero-Config Embedded Postgres
GBrain默认使用PGLite,这是一个通过WebAssembly运行的嵌入式Postgres 17.5数据库。核心优势:
GBrain defaults to PGLite, an embedded Postgres 17.5 running via WebAssembly. Core advantages:
- **无需Docker或云服务**:一条命令即可初始化完整数据库
- **No Docker or cloud needed**: One command initializes a complete database
- **2秒初始化**:官方声称数据库就绪时间约2秒
- **2-second initialization**: Database ready in ~2 seconds
- **完整Postgres能力**:含pgvector、混合搜索、37个操作
- **Full Postgres capabilities**: pgvector, hybrid search, 37 operations
- **可扩展迁移**:数据量大后可迁移至Supabase托管版本
- **Scalable migration**: Can migrate to Supabase when data grows
3.2 混合搜索与RRF融合
3.2 Hybrid Search and RRF Fusion
Query: "when should you ignore conventional wisdom?"
│
▼ Multi-query expansion (Claude Haiku)
"contrarian thinking startups", "going against the crowd"
│
▼─────────────┬─────────────▼
▼ ▼
Vector Keyword
(HNSW (tsvector
cosine) ts_rank)
▼ ▼
└──────────────┬─────────────┘
▼
RRF Fusion: score = Σ(1/(60 + rank))
│
▼
4-Layer Dedup
1. Best chunk per page
2. Cosine similarity > 0.85
3. Type diversity (60% cap)
4. Per-page chunk cap
│
▼
Results
RRF(Reciprocal Rank Fusion,倒数排序融合)的公式为:
RRF (Reciprocal Rank Fusion) formula:
RRFscore(d) = Σ(1/(k + r(d)))
其中k=60是平滑参数,r(d)是文档在列表中的排名。RRF的优势在于不需要对不同检索的得分进行归一化,直接根据排名计算。
Where k=60 is the smoothing parameter, r(d) is the document's rank. RRF's advantage is not needing score normalization across different retrievals.
纯关键词搜索会漏掉概念性匹配(如"无视常规做法"搜不到"天才的公交车票理论"),纯向量搜索在精确短语上表现差。RRF融合两者兼顾,多查询扩展则覆盖你没想到的表达方式。
Pure keyword search misses conceptual matches (e.g., "ignore conventional wisdom" won't find "The Bus Ticket Theory of Genius"), while pure vector search struggles with exact phrases. RRF fusion captures both, and multi-query expansion covers phrasings you didn't consider.
3.3 数据库Schema设计
3.3 Database Schema Design
GBrain使用10张核心表:
GBrain uses 10 core tables:
- pages:核心内容表,slug/type/title/compiled_truth/timeline
- content_chunks:分块内容+向量嵌入(1536维)
- links:页面间交叉引用(knows/invested_in/works_at等)
- tags:多对多标签关联
- timeline_entries:结构化时间线事件
- page_versions:Compiled Truth快照历史
- raw_data:外部API原始数据
- files:Supabase Storage二进制附件
- ingest_log:导入/摄取审计日志
- config:知识库级配置
3.4 三种分块策略
3.4 Three Chunking Strategies
| 策略 | Strategy | 适用场景 | Use Case |
|---|---|---|---|
| Recursive | Timeline/批量导入 | 5级分隔符,300词分块,50词重叠 | 5-level delimiters, 300-word chunks, 50-word overlap |
| Semantic | Compiled Truth | 句子级嵌入+余弦相似度找主题边界 | Sentence-level embedding + cosine similarity for topic boundaries |
| LLM-guided | 高价值内容 | Haiku识别128词窗口的主题转换 | Haiku identifies topic shifts in 128-word windows |
四、创新点分析
IV. Innovation Analysis
4.1 梦境循环(Dream Cycle)机制
4.1 Dream Cycle Mechanism
"Agent在我睡觉的时候运行。梦境循环会扫描当天每一段对话,充实缺失的实体信息,修复损坏的引用,合并冗余记忆。我早上醒来,大脑已经比我睡着前更聪明了。"
"The agent runs while I sleep. Dream Cycle scans every conversation from the day, enriches missing entities, fixes broken citations, consolidates redundant memories. I wake up and the brain is smarter than when I went to sleep."
— Garry Tan
梦境循环是GBrain最富创意的机制。通过定时任务实现:
Dream Cycle is GBrain's most creative mechanism, implemented via scheduled tasks:
- 扫描当天所有对话记录
- Scan all conversation records from the day
- 识别并充实缺失的实体信息
- Identify and enrich missing entity information
- 修复断开的交叉引用
- Fix broken cross-references
- 合并冗余记忆
- Consolidate redundant memories
4.2 Memex愿景的实现
4.2 Memex Vision Implementation
Tan在SKILLPACK文档中提到灵感来源:Vannevar Bush 1945年在《大西洋月刊》发表的经典论文《As We May Think》中描述的Memex设想。关键区别在于:
Tan mentions the inspiration in SKILLPACK: Vannevar Bush's 1945 Atlantic article describing the Memex concept. Key difference:
- Bush的Memex:被动的,需用户手动建立关联
- Bush's Memex: Passive, requires manual association
- GBrain:主动的,Agent自动检测实体、创建交叉引用
- GBrain: Proactive, agent automatically detects entities and creates cross-references
"你不需要去建造Memex,Memex自己会建造自己。"
"You don't have to build the Memex, the Memex builds itself."
— Garry Tan
4.3 Fat Skills, Thin Harness哲学
4.3 Fat Skills, Thin Harness Philosophy
GBrain的核心哲学是"智能在文档里,不在代码里":
GBrain's core philosophy is "intelligence in documents, not code":
- 工具(thin harness):CLI/MCP封装37个操作,不含业务逻辑
- Tools (thin harness): CLI/MCP with 37 operations, no business logic
- 技能(fat skills):Markdown文件定义Agent行为模式
- Skills (fat skills): Markdown files defining agent behavior patterns
这种设计的优势是:**Agent行为可以像代码一样版本控制,同时又具备自然语言的灵活性**。
This design's advantage: **Agent behavior can be version-controlled like code while retaining natural language flexibility**.
五、与一人公司方案对比(2026-04-29深度更新)
V. Comparison with Our One-Person Company Solution (Updated 2026-04-29)
5.1 知识图谱实现对比
5.1 Knowledge Graph Implementation Comparison
gbrain的实现:零LLM调用的实体关系提取(正则+模式匹配)。五种关系类型:attended、works_at、invested_in、founded、advises。页面角色先验推断,实时协调(编辑时同步更新图谱)。
gbrain's approach: Zero-LLM entity extraction using regex + pattern matching. Five relationship types. Page-role priors inference, real-time reconciliation.
我们方案:knowledge_graph尚未完全实现,需要参考gbrain建立基础。
Our approach: knowledge_graph not yet fully implemented, needs to reference gbrain.
- 优先实现基于规则的实体识别(人名、公司名、项目名)
- 定义关系类型体系(与llm-wiki类似:引用、矛盾、补充、升级)
- 实现自动链接和反向链接维护
5.2 混合搜索Pipeline对比
5.2 Hybrid Search Pipeline Comparison
gbrain的20层搜索Pipeline:意图分类→多查询扩展→向量+关键词→RRF→重新排名→编译truth提升→反向链接提升→去重
gbrain's 20-layer pipeline: Intent classification → Multi-query expansion → Vector+Keyword → RRF → Re-ranking → Compiled truth boost → Backlink boost → Dedup
- 引入意图分类(entity query vs. general query vs. temporal query)
- 实现关键词+向量双轨检索
- 添加编译truth提升层
- 建立评测基准
5.3 Skillify vs. Phase迭代
5.3 Skillify vs. Phase Iteration
gbrain的skillify 10步审计清单确保技能可持续:scaffold→write→check→verify。检查项包括:测试存在、trigger定义、resolver可达性、MECE、DRY。
gbrain's skillify 10-step audit checklist ensures skills are sustainable: scaffold→write→check→verify. Items include: test existence, trigger definition, resolver reachability, MECE, DRY.
- Phase完成后进行self-review检查
- 检查清单:功能完整性、与其他Phase重叠、文档齐全性
5.4 signal-detector vs. heartbeat
5.4 signal-detector vs. heartbeat
gbrain的signal-detector:每次消息触发,并行运行廉价模型,捕获原始思维和实体提及,大脑自动复合。
gbrain's signal-detector: Fires on every message, runs cheap model in parallel, captures original thinking and entity mentions, brain compounds automatically.
- 每次对话后自动提取关键信息
- 自动检测遗忘点(agent提到某事但未记录)
- 在非对话时间(cron)进行整合和丰富
5.5 Thin Harness, Fat Skills的直接应用
5.5 Direct Application of Thin Harness, Fat Skills
这是对我们最有直接指导意义的设计哲学。harness应该保持极简(约200行),只做运行模型、文件读写、上下文管理、安全。skills应该极尽详细,每个skill是完整的markdown procedure,包含判断标准、流程、与其他skill的链接。
This is the most directly instructive design philosophy for us. Harness should be ultra-thin (~200 lines), only running models, file I/O, context management, security. Skills should be extremely detailed, each skill is a complete markdown procedure with judgment criteria, processes, and links to other skills.
- P0:借鉴Compiled Truth + Timeline格式,重构MEMORY.md结构
- P0:实现基础的knowledge_graph(图谱初版)
- P0:实现基础的双轨检索(关键词+向量)
- P1:引入signal-detector思路:每次对话后自动提取关键信息
- P1:实现skillify风格的审计检查表
- P2:引入意图分类到搜索流程
5.6 持久记忆重于即时检索
5.6 Persistent Memory > Instant Retrieval
传统RAG(检索增强生成)是"即时拼凑"模式,每次查询都从大量文档中检索相关内容。而GBrain代表的是"全职研究馆员"模式:Agent持续维护一个编译后的知识库。
Traditional RAG is "on-the-fly assembly", retrieving from many documents each query. GBrain represents the "full-time librarian" model: agents continuously maintain a compiled knowledge base.
| 维度 | Dimension | RAG | GBrain |
|---|---|---|---|
| 知识处理时机 | Processing time | 查询时(每次重新处理) | 摄入时(只处理一次) |
| 交叉引用 | Cross-references | 每次查询临时发现 | 预先构建并维护 |
| 知识积累 | Knowledge accumulation | 无 | 复利式增长 |
| 维护者 | Maintainer | 系统黑箱 | LLM(透明) |
| 知识组织 | Knowledge org | 原始文档 | Compiled Truth |
| 检索方式 | Retrieval | 每次即时检索 | 预编译+按需检索 |
| 上下文 | Context | 会话级 | 持久累积 |
| 可追溯性 | Traceability | 低 | 高(Timeline) |
5.7 实体中心的设计思维
5.7 Entity-Centric Design Thinking
GBrain以**实体(人/公司/概念/项目)**为中心组织知识,而非以时间或文档为中心。这带来几个优势:
GBrain organizes knowledge around **entities (people/companies/concepts/projects)**, not time or documents. Advantages:
- 每次交互都能积累到正确的实体
- Each interaction accumulates to the right entity
- 关系查询变得自然(如"谁同时认识Pedro和Diana")
- Relationship queries become natural (e.g., "Who knows both Pedro and Diana")
- 知识复用效率高
- High knowledge reuse efficiency
5.3 人机协同的平衡
5.3 Human-AI Collaboration Balance
GBrain强调"人类永远赢":你可以直接编辑任何Markdown文件,gbrain sync会自动索引变更。这解决了AI知识库的信任问题——用户始终保持对知识的最终控制权。
GBrain emphasizes "human always wins": you can directly edit any Markdown file, and gbrain sync auto-indexes changes. This solves the trust problem in AI knowledge bases—users maintain final control.
六、争议与思考
VI. Controversies and Reflections
开发者社区对GBrain也有一些质疑:
Developers have raised some concerns about GBrain:
- 确定性vs灵活性:编译真相重写、梦境循环等核心功能是Markdown中的Agent指令,而非确定性代码实现
- Determinism vs Flexibility: Core features like Compiled Truth rewriting and Dream Cycle are agent instructions in Markdown, not deterministic code
- 稳定性挑战:高度依赖LLM理解自然语言指令,一致性和稳定性存在挑战
- Stability challenges: High dependency on LLM understanding natural language instructions raises consistency concerns
- 模型依赖:文档明确指出需要Claude Opus 4.6或GPT-5.4 Thinking等顶级模型
- Model dependency: Documentation clearly states need for top-tier models like Claude Opus 4.6 or GPT-5.4 Thinking
但这也代表了一种新趋势:随着LLM能力提升,"通过自然语言取代部分硬编码逻辑"可能成为常态。
But this also represents a new trend: as LLM capabilities improve, "replacing hardcoded logic with natural language" may become the norm.