API 参考
全部 6 个 MCP 工具的完整参数文档。
learn
记录陈述性经验(事实、策略、教训、观察)。
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
insight |
string | 是 | — | 经验文本(1-300 字符,自动截断) |
context |
string | 否 | "" |
JSON 上下文,包含 params/spatial/robot/task 分区 |
collection |
string | 否 | "default" |
用于分组记忆的逻辑命名空间 |
session_id |
string | 否 | null |
关联到一个会话(来自 start_session) |
返回值
成功:
{
"status": "created",
"memory_id": 42,
"auto_inferred": {
"category": "observation",
"confidence": 0.85,
"tags": ["observation", "pattern"],
"scope_files": []
}
}
检测到重复:
{
"status": "duplicate",
"method": "jaccard",
"existing_id": 15,
"similarity": 0.78
}
自动分类类别
| 类别 | 触发模式 | 衰减 | 示例 |
|---|---|---|---|
constraint |
"must always", "never", "forbidden" | 无(受保护) | "抓取力不得超过 15N" |
preference |
"prefer X over Y", "recommended to use" | 正常 | "优先从左侧接近" |
worldview |
"X is better than Y", "from now on" | 正常 | "ONNX 对小模型比 Ollama 更快" |
tradeoff |
"tradeoff", "pros and cons", "vs" | 正常 | "速度与精度:实时场景使用 10Hz" |
root_cause |
"caused by", "because", "root cause" | 正常 | "故障由传感器漂移引起" |
decision |
"chose", "decided", "instead of" | 正常 | "为了简化选择 PID 而非 MPC" |
pattern |
"every time", "whenever", "recurring" | 正常 | "每当湿度 > 80%,抓取就会失败" |
postmortem |
"lesson", "postmortem" | 无(受保护) | "教训:新会话前务必先校准" |
gotcha |
"gotcha", "pitfall", "trap" | 无(受保护) | "陷阱:仿真中未检查关节限位" |
observation |
"found that", "discovered", "noticed" | 正常 | "发现红色杯子需要更大的力" |
code |
(默认兜底) | 正常 | 一般性技术笔记 |
去重管道
第 1 层:精确匹配 → content_hash SHA-256 + memory_exists()
第 2 层:Jaccard > 0.70 → FTS5 候选 + token 重叠
第 3 层:Cosine > 0.85 → 向量相似度(需嵌入器可用)
recall
使用 BM25 + 向量混合搜索检索相关经验。
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
query |
string | 是 | — | 搜索查询(自然语言) |
collection |
string | 否 | "default" |
搜索的集合 |
n |
int | 否 | 5 |
返回结果数(1-100) |
min_confidence |
float | 否 | 0.3 |
最低置信度阈值(0.0-1.0) |
session_id |
string | 否 | null |
过滤到特定 episode |
context_filter |
string | 否 | null |
JSON 结构化过滤器(见下文) |
spatial_sort |
string | 否 | null |
JSON 空间排序(见下文) |
返回值
{
"memories": [
{
"id": 1,
"content": "grip_force=12.5N optimal for cylindrical objects",
"human_summary": "grip_force=12.5N optimal...",
"type": "fact",
"perception_type": null,
"session_id": "abc-123",
"category": "observation",
"confidence": 0.85,
"context": "{...}",
"params": {"grip_force": {"value": 12.5}},
"spatial": {"object_position": [1.3, 0.7, 0.42]},
"robot": {"type": "UR5e"},
"task": {"success": true},
"_rrf_score": 1.0,
"created_at": "2026-03-09T10:30:00"
}
],
"total": 1,
"mode": "hybrid",
"query_ms": 8.2
}
搜索模式
| 模式 | 触发条件 | 管道 |
|---|---|---|
hybrid |
嵌入器可用且两者均返回结果 | BM25 + Vec → RRF 融合 |
bm25_only |
嵌入器不可用或向量搜索返回空 | 仅 BM25 |
vec_only |
BM25 返回空(罕见) | 仅向量 |
context_filter 语法
JSON 对象,键为 context JSON 中的点路径:
// 等值匹配
{"task.success": true}
// 范围运算符
{"params.force.value": {"$lt": 15.0}}
{"params.force.value": {"$gte": 10.0, "$lte": 20.0}}
// 组合(AND 逻辑)
{"task.success": true, "robot.type": "UR5e"}
| 运算符 | 含义 |
|---|---|
| (无) | 精确相等 |
$lt |
小于 |
$lte |
小于等于 |
$gt |
大于 |
$gte |
大于等于 |
$ne |
不等于 |
限制:每次查询最多 10 个过滤条件。
spatial_sort 语法
{
"field": "spatial.object_position",
"target": [1.3, 0.7, 0.42],
"max_distance": 0.1
}
field:context JSON 中坐标数组的点路径target:参考位置(任意维度)max_distance:可选截断距离(欧几里得距离)
来源加权
来自真实世界数据的记忆相比仿真数据获得 1.5 倍权重提升。通过 context.env.sim_or_real == "real" 检测。
save_perception
存储感知/轨迹/力数据(程序性记忆)。
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
description |
string | 是 | — | 人类可读的描述(至少 5 个字符) |
perception_type |
string | 否 | "visual" |
可选值:visual、tactile、auditory、proprioceptive、procedural |
data |
string | 否 | null |
JSON 传感器数据(动作、轨迹、读数) |
metadata |
string | 否 | null |
JSON 元数据(格式、采样率、单位) |
collection |
string | 否 | "default" |
集合命名空间 |
session_id |
string | 否 | null |
关联到会话 |
返回值
{
"memory_id": 42,
"perception_type": "procedural",
"collection": "default",
"has_embedding": true
}
感知类型
| 类型 | 用途 | 典型数据 |
|---|---|---|
visual |
摄像头、场景描述 | 图像特征、目标检测结果 |
tactile |
力/扭矩传感器 | 接触事件、抓取力读数 |
auditory |
声音、语音 | 音频特征、指令转录 |
proprioceptive |
关节状态、位姿 | 关节角度、速度、末端执行器位姿 |
procedural |
动作序列 | 采样轨迹、分步计划 |
forget
软删除错误的记忆。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
memory_id |
int | 是 | 要删除的记忆 ID(必须 > 0) |
reason |
string | 是 | 删除原因说明 |
返回值
{
"status": "forgotten",
"memory_id": 3,
"content": "grip_force=15N optimal...",
"reason": "Sensor calibration error"
}
记忆被软删除(状态 → invalidated),而非物理移除。这样可以保留审计跟踪记录。
update
修改已有记忆的内容。
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
memory_id |
int | 是 | — | 记忆 ID(必须 > 0) |
new_content |
string | 是 | — | 更新后的内容(1-300 字符) |
context |
string | 否 | "" |
更新后的上下文 JSON |
返回值
{
"status": "updated",
"memory_id": 1,
"old_content": "grip_force=12.5N optimal...",
"new_content": "grip_force=11.0N optimal (recalibrated)...",
"auto_inferred": {
"category": "observation",
"confidence": 0.85
}
}
更新会自动: - 重新运行自动分类 - 重新生成嵌入向量 - 重新推断语义标签
start_session
开始一个新的 episode。
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
collection |
string | 否 | "default" |
集合命名空间 |
context |
string | 否 | null |
Episode 上下文 JSON(机器人、环境、任务) |
返回值
{
"session_id": "550e8400-e29b-41d4-a716-446655440000",
"collection": "default",
"active_memories_count": 42
}
end_session
结束一个 episode —— 触发时间衰减、合并和主动召回。
参数
| 参数 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
session_id |
string | 是 | — | 来自 start_session 的会话 ID |
outcome_score |
float | 否 | null |
Episode 成功评分(0.0-1.0) |
返回值
{
"status": "ended",
"session_id": "550e8400-...",
"summary": {
"memory_count": 15,
"by_type": {"fact": 12, "perception": 3},
"by_category": {"observation": 8, "pattern": 3}
},
"decayed_count": 42,
"consolidated": {
"merged_groups": 2,
"superseded_count": 3,
"compression_ratio": 0.2,
"avg_similarity": 0.65
},
"related_memories": [
{"id": 5, "content": "Similar experience from session X", "_rrf_score": 0.89}
]
}
合并规则
- 仅当会话拥有 >= 3 条可合并记忆时触发
- 受保护的类别不会被合并:
constraint、postmortem、gotcha - 高置信度记忆(>= 0.95)不会被合并
- 感知记忆(type=
perception)不会被合并 - 使用 Jaccard 相似度 > 0.50 阈值
- 保留置信度最高的记忆(平局时:最高访问次数,再平局则取最新的)
时间衰减公式
confidence_new = confidence × (1 - decay_rate) ^ days_since_last_access
- 默认
decay_rate:0.01(每天 1%) - 仅在
days_since_last_access > 1.0时应用 - 仅在
confidence > 0.05时应用 - 基准时间:
last_accessed(由recall命中时更新),回退到created_at