关于 mif-tools
mif-tools 是用于转换、验证和检查 AI Agent 记忆的命令行工具与库,采用厂商中立的 MIF 格式。它支持多种记忆导出格式,并提供 MCP 服务用于导入和导出记忆。
主要功能
- 01在 MIF、mem0、CrewAI、LangChain、通用 JSON 和 Markdown 间转换
- 02自动识别支持的输入格式
- 03验证和检查记忆文档
- 04保留可选元数据与厂商扩展
- 05提供 Python 和 TypeScript 包及命令行工具
适用场景
- 01在不同 Agent 记忆提供方之间迁移记忆
- 02将记忆导出转换为 Obsidian 或 Letta 可用的 Markdown
- 03根据 MIF 规范检查记忆文档
MCP 相关
可选的 MCP 服务向 MCP 客户端提供导出、导入、验证、检查记忆及列出格式的工具。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。
详细介绍
记忆交换格式(MIF)
你的 AI Agent 在系统 A 中积累了 6 个月的记忆。你想试试系统 B。没有 MIF,所有记忆都会丢失。有了 MIF:
pip install mif-tools
mif convert mem0_export.json --to shodh -o memories.mif.json
完成。你的记忆可以自由迁移。
什么是 MIF?
一种与供应商无关的 AI Agent 记忆 JSON 封装格式。就像联系人用的 vCard 或事件用的 iCalendar——采用精简的架构,让记忆可以在不同供应商之间迁移而不会丢失数据。
只需 3 个必填字段。
{
"mif_version": "2.0",
"memories": [
{
"id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890",
"content": "User prefers dark mode across all applications",
"created_at": "2026-01-15T10:30:00Z"
}
]
}
其他所有内容——记忆类型、标签、实体、嵌入、知识图谱、供应商扩展——都是可选的。有的就添加,没有的就忽略。
安装
# Python
pip install mif-tools # core (zero dependencies)
pip install mif-tools[validate] # with JSON Schema validation
pip install mif-tools[mcp] # with MCP server
# Node.js / TypeScript
npm install @varunshodh/mif-tools
在不同格式之间转换
# mem0 → MIF
mif convert mem0_export.json --from mem0 -o memories.mif.json
# MIF → Markdown (Obsidian/Letta style)
mif convert memories.mif.json --to markdown -o memories.md
# Auto-detect source format
mif convert any_memory_file.json -o output.mif.json
# Inspect any memory file
mif inspect memories.json
# Validate MIF document
mif validate memories.mif.json
Python API
from mif import load, dump, convert, MifDocument, Memory
# Load from any format (auto-detects mem0, markdown, generic JSON, MIF)
doc = load(open("mem0_export.json").read())
print(f"{len(doc.memories)} memories loaded")
# Convert between formats in one line
markdown = convert(data, from_format="mem0", to_format="markdown")
# Create memories from scratch
doc = MifDocument(memories=[
Memory(
id="123e4567-e89b-12d3-a456-426614174000",
content="User prefers dark mode",
created_at="2026-01-15T10:30:00Z",
memory_type="observation",
tags=["preferences", "ui"],
)
])
print(dump(doc)) # MIF v2 JSON
# Deep validation (UUIDs, references, timestamps, embedding dimensions)
from mif import validate_deep
ok, warnings = validate_deep(open("export.mif.json").read())
将 MIF 添加到你的 MCP 服务(10 行)
from mif import load, dump
# Export handler
def export_memories(user_id: str) -> str:
memories = my_storage.get_all(user_id)
return dump(memories)
# Import handler — auto-detects mem0, markdown, generic JSON, MIF
def import_memories(data: str) -> dict:
doc = load(data)
for mem in doc.memories:
my_storage.save(mem.id, mem.content, mem.created_at)
return {"memories_imported": len(doc.memories)}
支持的格式
| 格式 | ID | 自动检测 | 描述 |
|---|---|---|---|
| MIF v2 | shodh | JSON 中包含 "mif_version" | 原生格式,可无损往返转换 |
| mem0 | mem0 | 包含 "memory" 字段的 JSON 数组 | mem0 记忆导出 |
| CrewAI | crewai | 包含 "task_description" 的 JSON 数组 | CrewAI LTMSQLiteStorage 导出 |
| LangChain | langchain | 包含 "namespace" + "value" 的 JSON 数组 | LangChain/LangMem Item 格式 |
| 通用 JSON | generic | 包含 "content" 字段的 JSON 数组 | 任意 JSON 记忆数组 |
| Markdown | markdown | 以 --- 开头 | YAML frontmatter(Letta/Obsidian 风格) |
完整规范
MIF 支持用于丰富记忆数据的可选字段:
- 记忆类型 —
observation、decision、learning、error、context、conversation及自定义类型 - 实体引用 — 包含类型和置信度的命名实体
- 嵌入 — 模型名称、维度、向量(可复用或重新生成)
- 知识图谱 — 带置信度分数的实体和关系
- 供应商扩展 — 在往返转换中保留系统专属元数据
- 隐私 — PII 检测和脱敏标记
完整规范:spec/mif-v2.md | JSON Schema:schema/mif-v2.schema.json
MCP 服务
向任何兼容 MCP 的 AI 客户端提供 MIF 工具:
pip install mif-tools[mcp]
mif mcp
工具:export_memories、import_memories、validate_memories、inspect_memories、list_formats
适配器和实现
| 系统 | 状态 | 类型 |
|---|---|---|
| shodh-memory | 生产可用 | 内置 HTTP API(/api/export/mif、/api/import/mif) |
| mif-tools (PyPI) | 生产可用 | 带 CLI 和 MCP 服务的 Python 包 |
| @varunshodh/mif-tools (npm) | 生产可用 | 带 CLI 的 TypeScript/Node.js 包 |
| mem0 | 适配器已就绪 | Python + npm |
| CrewAI | 适配器已就绪 | Python + npm |
| LangChain | 适配器已就绪 | Python + npm |
| 通用 JSON | 适配器已就绪 | Python + npm |
| Markdown(YAML frontmatter) | 适配器已就绪 | Python + npm |
设计原则
- 精简 — 3 个必填字段,其他均为可选项。
- 可扩展 — 往返转换时,必须保留未知字段和厂商扩展。
- 厂商中立 — 此架构不会偏向任何实现。
- 向前兼容 — 导入器必须忽略未知字段。
贡献
欢迎为任何记忆系统实现适配器。请参阅 CONTRIBUTING.md。
相关链接
- 文档 — 完整文档站点
- MCP SEP #2342 — 面向 Model Context Protocol 的原始提案
- tower-mcp #531 — tower-mcp 中的跟踪问题
- shodh-memory — 参考实现(Rust)
- PyPI 上的 mif-tools — Python 包
- npm 上的 @varunshodh/mif-tools — npm 包
许可证
Apache 2.0
评论
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。