Amber Hunter

# amber-hunter — AI 第二大脑 Skill

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "Amber Hunter" with this command: npx skills add ankechenlab-node/amber-hunter

amber-hunter — AI 第二大脑 Skill

What It Is

amber-hunter 是运行在本地(port 18998)的 FastAPI 服务,为 Claude Code 提供长期记忆能力和知识自动编译能力。

核心能力矩阵:

能力说明引入版本
记忆胶囊持久化存储 AI 工作产生的想法/决策/上下文v1.0
混合搜索LanceDB 向量 + 关键词联合检索v1.2.27
意图预测根据 session 内容预测下一步最可能的需求v1.2.27
DID E2E 加密设备绑定加密,云端隐私保护v1.2.24
知识编译器同类胶囊自动编译成 wiki 概念页v1.2.38

启动

cd ~/.openclaw/skills/amber-hunter
python3 amber_hunter.py
# 或后台运行
python3 amber_hunter.py &

服务启动时:

  1. 自动初始化 SQLite 数据库(memory.db
  2. 启动编译 daemon(每 6 小时扫描一次覆盖缺口)
  3. 冷启动编译(启动时如果有覆盖缺口,立即触发一次)

认证

操作认证方式
所有外部请求Bearer Token(从 /token 获取,写入 ~/.openclaw/token
/token, /bind-apikey, /master-password强制 localhost 检查
Bearer Token 调用Authorization: Bearer <token> Header 中传递

Token 获取流程(首次设置):

# 1. 启动服务
python3 amber_hunter.py

# 2. 从本地获取 token(仅 localhost 可访问)
curl http://localhost:18998/token
# 返回: {"token": "xxx"}

# 3. 写入本地配置
echo "Bearer xxx" > ~/.openclaw/token

API 端点总览

无需认证(localhost)

端点方法说明
GET /statusGET服务状态、版本、平台、胶囊数
GET /tokenGET读取本地 API Token
POST /bind-apikeyPOST更新 Huper 云端 API Key(存 Keychain)
POST /master-passwordPOST设置 master_password(Keychain)

核心 — 胶囊管理(Bearer Token)

端点方法说明
/capsulesGET列出胶囊(支持 category_path 过滤 + 分页 limit
/capsulesPOST创建胶囊
/capsules/{id}GET获取单个胶囊详情
/capsules/{id}PATCH更新胶囊
/capsules/{id}DELETE删除胶囊

核心 — 记忆召回(Bearer Token)

端点方法说明
/recallGET混合搜索(向量+关键词+LanceDB,rerank)
/rerankPOST强制 LLM 重排候选记忆
/classifyGET关键词+LLM fallback 分类
/extractPOST从文本中提取记忆(LLM 驱动)
/ingestPOSTAI 主动写入记忆(→ 入库或审阅队列)

/recall 参数:

参数类型默认说明
qstring必填查询文本
rerankboolfalse是否启用 LLM rerank (deprecated, use rerank_engine)
rerank_enginestring"auto"重排序引擎:auto | model | llm | none
hydeboolfalse是否启用 HyDE(假设性答案增强检索)v1.2.41
multi_hopboolfalse是否启用多跳检索 v1.2.41
limitint3返回数量
category_pathstring""MFS路径过滤
use_insightsbooltrue是否优先返回 insight 缓存
citationint01=返回 embedding 裁剪的片段

/recall 响应新增字段(v1.2.41):

字段类型说明
rerank_time_msfloatreranker 耗时(毫秒)
hyde_time_msfloatHyDE 生成耗时(毫秒)
retrieval_hopsint检索跳数(multi_hop 启用时 > 1)

/recall/evaluate 端点(v1.2.41):

端点方法说明
/recall/evaluatePOSTRAG 评测(RAGAS + NDCG@5)

/recall/evaluate 请求体:

{"queries": [{"q": "...", "expected_capsule_ids": ["..."]}]}

/recall/evaluate 响应:

{
  "ragas_scores": {"faithfulness": 0.x, "answer_relevancy": 0.x, "context_precision": 0.x},
  "ndcg_at_5": 0.x,
  "evaluated_at": "...",
  "total_queries": 2
}

/ingest 参数:

参数类型说明
contentstring记忆内容
tagsstring标签(逗号分隔)
session_keystring来源 session
auto_reviewbooltrue=直接入库,false=进审阅队列

审阅队列(Bearer Token)

端点方法说明
/queueGET列出待审阅记忆
/queue/{qid}/approvePOST批准写入胶囊
/queue/{qid}/rejectPOST拒绝
/queue/{qid}/editPOST修改后批准

知识编译器 v1.2.38+(Bearer Token)

端点方法说明
/conceptsGET列出所有已编译概念页(?limit=50&offset=0 分页)
/concepts/{path}GET获取指定 path 的 wiki 内容
/admin/compilePOST手动触发编译(?path= 指定路径)
/admin/compile/statusGETdaemon 状态 + 覆盖缺口列表 + 健康指标(alert/crashes/success_count)

编译触发条件:

条件说明
胶囊数比上次编译时多 ≥100增量触发
超过 6 小时未编译定时触发

覆盖缺口: 有 ≥3 个胶囊但无 concept page 的 category_path。

管理操作(Bearer Token + localhost)

端点方法说明
/admin/backfill-pathsPOST批量修复缺失的 category_path
/admin/reindex-vectorsPOST重建 LanceDB 向量索引
/admin/trainPOST触发 embedding 模型训练
/admin/train/statusGET训练状态
/admin/train/scoreGET模型评分
/admin/train/tagsGET标签统计
/admin/generate-insightsPOST手动生成 insights(按 path)
/statsGET系统统计
/admin/exportGET导出备份

DID E2E 加密(Bearer Token)

端点方法说明
/did/setupPOST初始化 DID(生成密钥对,存 Keychain)
/did/statusGETDID 初始化状态
/did/register-devicePOST注册设备到 DID 网络
/did/auth/challengePOST获取 auth challenge
/did/auth/sign-challengePOST签名 challenge,完成认证

WAL(Write-Ahead Log)

端点方法说明
/wal/statusGETWAL 状态
/wal/entriesGET读取 WAL 条目
/wal/gcPOST触发 WAL GC

Session 上下文

端点方法说明
/session/summaryGET当前 session 记忆摘要
/session/filesGET当前 session 相关文件列表
/session/preloadGET预加载 context(供 Claude Code 使用)
/freezeGET/POST冻结当前 session 上下文

Profile

端点方法说明
/profileGET完整用户 profile
/profile/{section}GET/PUT读取/更新 profile 章节
/profile/buildPOST触发 profile 自动构建

Corrections(记忆纠错)

端点方法说明
/corrections/statsGET纠错统计
/corrections/suggestionsGET纠错建议
/corrections/applyPOST应用纠错规则

工具类

端点方法说明
GET /GET根路径,返回欢迎信息
GET /patternsGET当前系统运作的 Pattern 列表
POST /mcpPOSTMCP(Model Context Protocol)接口

数据模型

capsules 表

CREATE TABLE capsules (
    id              TEXT PRIMARY KEY,     -- 唯一 ID (secrets.token_hex)
    memo            TEXT,                 -- 记忆摘要
    content         TEXT,                  -- 完整内容
    category_path   TEXT,                  -- 分类路径,如 "dev/python"
    tags            TEXT,                  -- 逗号分隔标签
    hotness_score   REAL DEFAULT 0,        -- 热度分
    hit_count       INTEGER DEFAULT 0,     -- 被 recall 命中的次数
    session_id      TEXT,                  -- 来源 session
    encrypted       INTEGER DEFAULT 0,     -- 是否加密
    vector_id       TEXT,                  -- LanceDB 向量 ID
    synced          INTEGER DEFAULT 0,    -- 是否已同步云端
    created_at      REAL,                  -- unix timestamp
    updated_at      REAL,
    content_hash    TEXT                   -- 去重用
)

insights 表(v1.2.17+)

CREATE TABLE insights (
    id              TEXT PRIMARY KEY,
    capsule_ids     TEXT,          -- JSON array
    summary         TEXT,           -- 纯文本摘要
    path            TEXT,           -- category_path
    concept_slug    TEXT,           -- slug化 path (v1.2.38+)
    wiki_content    TEXT,           -- 完整 markdown (v1.2.38+)
    hotness_score   REAL DEFAULT 0,
    created_at      REAL,
    updated_at      REAL
)

memory_queue 表

CREATE TABLE memory_queue (
    id          TEXT PRIMARY KEY,
    content     TEXT,
    tags        TEXT,
    session_id  TEXT,
    source      TEXT DEFAULT 'ingest',
    created_at  REAL
)

配置

配置文件:~/.openclaw/skills/amber-hunter/config.json

{
  "auto_sync": true,
  "sync_interval_seconds": 300,
  "embed_model": "BAAI/bge-m3",
  "vector_dim": 1024,
  "rerank_model": "BAAI/bge-reranker-v2-m3",
  "llm_model": "gpt-4o-mini",
  "huper_api_key": "sk-...",
  "key_source": "pbkdf2",
  "compile_interval_hours": 6.0,
  "compile_capsule_threshold": 100
}

关键行为

胶囊创建时的 category_path 推断

/ingest/capsules POST 会自动从内容中推断 category_path:

推理依据:content + tags → LLM 分类
兜底:category_path = "general/default"

/recall 混合评分公式

final_score = 0.35 * norm_lance + 0.25 * norm_kw + 0.20 * recency + 0.20 * hotness
  • LanceDB 向量相似度(归一化)
  • 关键词 overlap 分
  • 近期性(7天衰减)
  • 热度分

wikilinks 注入策略(Knowledge Compiler)

LLM 生成 wikilinks 不稳定(max_tokens=600 时 Related Capsules 部分常被截断)。 最终策略:代码事后注入

wikilinks = " ".join(f"[[{cid}:{short_label}]]" for cid in capsule_ids)
wiki_content = wiki_content.rstrip() + f"\n\n### Related Capsules\n{wikilinks}"

Cold Start 行为

服务启动时:

  1. 如果有覆盖缺口,立即触发一次 _run_batch_compile()
  2. 如果 auto_train 启用,触发 embedding 模型训练

使用示例

创建记忆

curl -X POST http://localhost:18998/ingest \
  -H "Authorization: Bearer $(cat ~/.openclaw/token)" \
  -H "Content-Type: application/json" \
  -d '{"content": "修了一个版本号测试过时的问题", "tags": "amber-hunter,bugfix"}'

召回记忆

curl "http://localhost:18998/recall?query=amber-hunter版本号问题&rerank=true" \
  -H "Authorization: Bearer $(cat ~/.openclaw/token)"

手动触发知识编译

# 编译指定 path
curl -X POST "http://localhost:18998/admin/compile?path=knowledge/devops" \
  -H "Authorization: Bearer $(cat ~/.openclaw/token)"

# 查看 daemon 状态和缺口
curl "http://localhost:18998/admin/compile/status" \
  -H "Authorization: Bearer $(cat ~/.openclaw/token)"

获取已编译的概念页

# 列出所有概念页
curl "http://localhost:18998/concepts" \
  -H "Authorization: Bearer $(cat ~/.openclaw/token)"

# 获取指定概念页
curl "http://localhost:18998/concepts/knowledge/devops" \
  -H "Authorization: Bearer $(cat ~/.openclaw/token)"

已知限制

  1. Bearer Token 存在磁盘~/.openclaw/token 是明文,localhost 以外不安全
  2. 向量索引重建昂贵/admin/reindex-vectors 在大量胶囊时耗时较长
  3. Wiki 编译器依赖 LLM:LLM 不可用时 compile_concept_page 返回 None
  4. DID 注册需要 Huper 云端:本地 DID setup 后还需要云端注册才生效

相关文件

amber-hunter/
├── amber_hunter.py      # FastAPI 主文件,所有端点
├── core/
│   ├── db.py            # SQLite 数据层
│   ├── wiki_compiler.py # 知识编译器(v1.2.38)
│   └── llm.py           # LLM 调用封装
├── tests/
│   └── test_api/
│       └── test_status.py  # 状态 API 测试
├── config.json          # 配置文件
└── SKILL.md             # 本文档

适用场景

用 amber-hunter 当:

  • 需要 AI 在长时间对话中保持"记忆"
  • 需要从历史胶囊中检索相关经验
  • 需要将多个相关记忆自动组织成概念页
  • 需要加密存储敏感记忆到云端

不用 amber-hunter 当:

  • 简单 KV 存储(用文件或 SQLite 直接写)
  • 需要服务端部署(它是纯本地服务)
  • 需要多人实时协作(它是单人设计)

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

Context Brief

Persistent context survival for OpenClaw. Writes file-based anchors to memory/anchors/ to preserve critical context across sessions. Reads MEMORY.md and dail...

Registry SourceRecently Updated
2670Profile unavailable
Security

SPIRIT State Sync

State Preservation & Identity Resurrection Infrastructure Tool (SPIRIT). Preserves AI agent identity, memory, and projects to a private Git repository. NEW:...

Registry SourceRecently Updated
7610Profile unavailable
General

PPQ.AI Private Mode

Install PPQ.AI Private Mode for end-to-end encrypted AI inference in OpenClaw

Registry SourceRecently Updated
3080Profile unavailable
General

Memory Auto Archive

Automatically archives daily chat logs with keyword highlights and optional AI summaries into organized memory files without manual setup.

Registry SourceRecently Updated
2820Profile unavailable