Skip to main content
Glama

openmem

个人多 Agent 的统一记忆中枢:一个 PostgreSQL 库,一处写、全体读。

其他 AI 通过 MCP 接入;人通过 Web 控制台检索、问答、治理记忆。

它解决什么

问题

openmem 的做法

记忆散落在多个 agent / 文件

统一进 memory_entries,带向量与元数据

标准问题每个 bot 都重推一遍

preset_tools 预生成答案,秒回且可保鲜

需要「像问本人一样」的综合回答

mh_ask:检索记忆 + 画像 → LLM 回答,带引用

Related MCP server: Cerefox

架构

MCP clients (Claude / Codex / bots / …)
        │
        ▼
   server.js  ──spawn──►  mem_core.py  ──►  PostgreSQL (openmem)
   :3466 MCP                    │
                                ├── Embeddings API(OpenAI 兼容)
                                └── Chat LLM API(OpenAI 兼容)
   web_server.py :3467  ────────┘
   (Web 控制台,复用同一内核)
  • server.js:MCP 层(stdio / Streamable HTTP),工具转发到 Python 内核

  • mem_core.py:业务内核 + CLI(写入、混合检索、咨询、预设工具、导入)

  • web_server.py + web_page.html:Web 控制台

  • cred_guard.py:写库前打码(防明文密钥进记忆)

数据表

表

用途

memory_entries

记忆正文 + embedding + pinned / superseded 链

memory_conflicts

治理待审冲突

preset_tools

预生成答案(prompt + 缓存 + 保鲜周期)

ask_log

咨询日志与引用

app_config

运行配置(persona / 模型 / key 等,覆盖环境变量默认值)

建库:

createdb openmem
psql openmem -f schema.sql

快速开始

1. 依赖

  • Node.js 18+

  • Python 3.10+:psycopg2-binary、requests(见 requirements.txt)

  • PostgreSQL 14+

  • OpenAI 兼容的 embeddings 与 chat 端点

npm install   # @modelcontextprotocol/sdk + zod(若未提供 package.json,按需安装)
python -m pip install -r requirements.txt

2. 配置

cp .env.example .env
# 编辑 .env:PG、LLM、embedding 等

进程启动时会自动读项目根目录的 .env(不要提交)。

可选本地文件(均 gitignore):

文件

用途

persona.local.txt

mh_ask 默认主人画像(Web 设置若已保存则以库为准)

cred_guard_local.py

短口令精确替换表(公开仓 cred_guard.py 默认空表)

3. 启动

# MCP over HTTP
node server.js --http 3466

# MCP over stdio
node server.js

# Web 控制台
python web_server.py --port 3467

MCP 接入

HTTP:

{ "mcpServers": { "openmem": { "url": "http://127.0.0.1:3466/mcp" } } }

stdio:

{ "mcpServers": { "openmem": { "command": "node", "args": ["./server.js"] } } }

MCP 工具

工具

作用

mh_write

写入记忆(source 必填;layer k/m)

mh_update

按 id 原地更新(保留 id,重算向量)

mh_search

混合检索(向量 + 元数据过滤)

mh_get

按 id 取单条

mh_service

服务台账按名查询(若已导入 agent-matrix)

mh_ask

AI 对 AI 咨询,答案带 REF 引用

mh_tool / mh_tools_list

预生成答案(秒回)

mh_status

健康与统计

建议优先级:标准问题 → mh_tool → 需要原始片段 → mh_search → 需要综合口吻 → mh_ask。

写入示例:

mh_write(content="…结论/坑…", source="<agent名>", layer="m",
         category="lessons", tags=["…"], confidence=0.8)

Web 控制台

默认 https://127.0.0.1:3467(无鉴权,勿对公网裸奔;2026-10-22 起单栈 https,证书 C:\D\opt\certs\localhost\,缺证书自动回落 http;curl 测试加 --ssl-no-revoke)。

页签

能力

检索

语义检索 + 高亮,可编辑/删除

浏览

分页 + 分类/来源过滤

问问

流式问答、引用卡片、历史

预设工具

查看/刷新缓存答案

入职包

导出新 agent 需要的钉住事实与工具清单

AI 设置

提示词 / 模型 / key(写入 app_config,即时生效)

主要 API:/api/stats /api/search /api/browse /api/ask_stream /api/tools /api/config /api/health 等。

CLI(不经 MCP)

python mem_core.py write --content "..." --source me --layer m --category lessons
python mem_core.py search --query "..." --top_k 5
python mem_core.py ask --query "..." --agent mybot
python mem_core.py status

辅助脚本

文件

用途

import_sources.py

从本地 markdown 目录批量导入(路径请按环境改)

import_agentmatrix.py

服务总表目录指纹同步导入

mcp_call.py

命令行调用 MCP 工具

audit_*.py

一次性审计/聚类辅助

配置优先级

对 AI 问答相关项(模型、key、persona 等):

数据库 app_config  >  环境变量 / .env  >  代码默认值

安全

  • 密钥只放 .env 或服务环境变量,不要写进源码或提交 git

  • cred_guard 是写入时的尽力打码,不能替代密钥治理

  • Web / MCP 默认无鉴权:本机或反向代理 + 认证后再暴露

License

按你的仓库选择(例如 MIT)。

Available Tools

9 tools
mh_askA

AI 对 AI 咨询:像直接问老大陈丹本人一样提问,openmem 基于全部记忆给出完整、准确、口语化的答案(走 litellm GwV4F,数秒级,较慢)。只在 mh_tool 里没有对应成品答案、且问题需要理解+综合时才用:要标准答案走 mh_tool(秒回),要原始记忆片段走 mh_search(更快)。

Inputs: query (required), agent.

mh_getA

按 id 取单条记忆完整内容。

Inputs: id (required).

mh_serviceA

查本机 nssm 服务台账:按服务名返回该服务的启动参数/端口/路径等配置明细(不走语义检索,按名精确匹配)。不知道确切名字就先不传 name,会列出全部服务名。

Inputs: name.

mh_statusB

openmem 健康状态:总条数/钉住数/归档数/待审冲突/工具数/咨询次数。

Inputs: no named parameters.

mh_toolA

【首选 · 秒回】调用预生成答案工具:标准化提示词 + 后台已备好最新最准的答案,不走 LLM、几乎零等待。凡「老大是什么人 / 偏好习惯 / 铁律清单 / 本机环境 / 服务与端口 / 12 bot 花名册 / 项目索引 / openmem 使用手册」这类标准问题一律先用这个,别用 mh_search 现搜、更别凭印象猜。不知道有哪些成品答案就先调 mh_tools_list(一次看清全部 + 新鲜度)。

Inputs: name (required), force_refresh.

mh_tools_listB

列出全部预生成答案工具及答案新鲜度。

Inputs: no named parameters.

mh_updateA

按 id 原地更新一条记忆(改错字、补内容、转 pinned、换 category 都用这个)。只改传了的字段,未传的保持不动;改了 content 会自动重算向量与 hash。保留 id,不打断 superseded_by / 冲突记录引用链——优于"删了重写"。改内容前建议先 mh_get 看一眼原文。

Inputs: id (required), tags, layer, pinned, +4 more.

mh_writeC

写入一条记忆/知识到老大的统一记忆中枢(openmem)。source 必填=写入方 agent 名。layer: k=知识 m=记忆。category: rules/facts/projects/lessons/knowledge/archive/verification/services/capabilities/misc(或项目名如 dsh / agents-to-feishu)。重要结论不写入=任务不算完成。

Inputs: source (required), content (required), tags, layer, +3 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A3.8/5.0

    Scored across 9 tools

    Disambiguation4/5

    The tools have distinct purposes, and the descriptions explicitly separate raw memory search (mh_search), synthesized answers (mh_ask), and pre-generated answers (mh_tool). Some risk remains because these three query-ish tools overlap in intent, but the guardrails in the descriptions are strong enough to guide selection.

    Naming Consistency4/5

    All tool names use the consistent lowercase mh_ prefix and mostly follow a verb-based pattern like write, update, search, get, ask, and status. The noun-style exceptions mh_service, mh_tool, and mh_tools_list are minor deviations, and tools_list also reverses the expected order slightly.

    Tool Count5/5

    Nine tools is well-scoped for a memory hub: core memory operations (write/get/search/update), specialized lookups (service/tool), and meta/status tools are all represented. Each tool has a clear role and none feel redundant.

    Completeness4/5

    The surface covers create, read, update, query, status, and specialized lookup workflows well. There is no explicit delete or conflict-resolution tool even though mh_status surfaces pending conflicts, but this may be intentional and can be worked around via archive/update and category changes.

    Maintenance

    ActivityMaintained
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables AI agents to store, retrieve, and manage contextual knowledge across sessions using semantic search with PostgreSQL and vector embeddings. Supports memory relationships, clustering, multi-agent isolation, and intelligent caching for persistent conversational context.
      62 npm
      50
      MIT
    • A
      license
      Not graded
      quality
      D
      maintenance
      Persistent, semantically-searchable memory for AI agents using local PostgreSQL, pgvector, and Ollama embeddings, exposed via MCP with hybrid retrieval, knowledge graph, and auto-recall hook.
      2 npm
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Provides persistent, scoped shared memory for collaborating AI agents, with tools for storing observations, semantic recall, and handoff workflows. Backed by PostgreSQL and exposed through MCP.
      1
      Apache 2.0