System Architecture

Hindsight 架构讲解

Hermes Agent 长期记忆系统的完整拆解:架构分层、数据流、进程拓扑、配置方案。

local_external · naemon · PG 18.1

什么是 Hindsight?

Hindsight 是 Hermes Agent 的长期记忆系统。它让 AI agent 在会话之间记住你是谁、你的偏好、项目决策、技术环境——而不是每次重置都从头认识你。

三种核心操作:

架构分层

从 Hermes Agent 到底层数据库,共 6 层,以朱砂 / 陶土 / 墨色 交替区分层级:

三种核心操作

📥 retain — 存储

  • Agent 调 hindsight_retain 或自动 sync_turn
  • 内容入异步写者队列(单线程串行)
  • Hindsight API 接收 → LLM 提取结构化事实
  • 实体存入知识图谱(PG)
  • 文本向量化 → vector store

🔍 recall — 检索

  • Agent 调 hindsight_recall
  • Hindsight API 执行 3 路检索:
  • ① 语义搜索(向量相似度)
  • ② 关键词匹配(FTS5)
  • ③ 实体图遍历(知识图谱)
  • Reranker 重排序 → Top-N 返回

🧠 reflect — 反思

  • Agent 调 hindsight_reflect
  • Hindsight recall 获取所有相关记忆
  • LLM 跨记忆推理
  • 返回有结构的合成回答

🔄 自动预取(prefetch)

  • 每轮对话前 MemoryManager 自动调用
  • 以用户最新消息为查询后台 recall
  • 结果注入系统提示,无需手动调 tool
  • 可配置 auto_recall=true/false

会话生命周期

完整交互时序

本地进程拓扑

Mac mini 上的实际运行状态:

1
Hindsight Daemon
PID 95629 · :9177
1
PostgreSQL 18.1
pg0 管理 · 5433
14
连接池
daemon → PG
11 MB
数据库大小
hindsight 库
⚠️ 沉淀 之前有个废弃实例(redis-dembed- / 5432,0 连接)已清理。当前只有 hindsight-embed-hermes (5433) 在运行。

关键发现:

配置方案

// ~/.hermes/hindsight/config.json
{
  "mode":          "local_external",
  "api_url":       "http://localhost:9177",
  "recall_budget": "mid",
  "auto_recall":   true,
  "auto_retain":   true,
  "retain_async":  true,
  "retain_every_n_turns": 1,
  "memory_mode":   "hybrid"
}
模式行为适合
context 🧠 自动 prefetch + 系统提示注入,不暴露 tool 想自动获取但不想手动调 tool
tools 🔧 只暴露 tool schemas,不自动注入上下文 精确控制,只在需要时调 tool
hybrid ◀ prefetch 注入系统提示 + tools 可用 当前设置:自动获取 + 按需精细检索

三种工作模式

模式客户端需要什么适用场景
cloud hindsight_client (HTTP) API key + cloud URL 轻量,不占本地资源
local_embedded HindsightEmbedded ~200MB 模型 + LLM key 全本地,无外部依赖
local_external ◀ hindsight_client (HTTP) 已有 daemon + PG 当前:daemon 先起,Hermes 连接

📚 扩展阅读

plugins/memory/hindsight/__init__.py 在 Hermes 源码中——1760 行的完整实现。