POST /memory

按层写入一条记忆条目。

POST /cells/{cellID}/memory

认证

Authorization: Bearer $TOKEN

请求参数

请求体(JSON)

字段类型必填说明
layerstring✅目标层。可写层:about_me / agent_memory / consensus
kindstring✅记忆类别:preference / fact / constraint / instruction / correction / convention / lesson
contentstring✅记忆内容文本
namespacestring否命名空间。agent_memory 层必填,其他层可选
keystring否去重键。相同 (layer, namespace, actor, key) 会覆盖已有条目

请求示例

保存一条个人偏好到 about_me 层:

curl -X POST "http://localhost:9091/cells/dept-legal/memory" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "layer": "about_me",
    "kind": "preference",
    "content": "我喜欢使用 Vim 键位的编辑器"
  }'

保存一条角色记忆到 agent_memory 层(须指定 namespace):

curl -X POST "http://localhost:9091/cells/dept-legal/memory" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "layer": "agent_memory",
    "kind": "fact",
    "content": "项目使用 Go 1.22 + PostgreSQL 16",
    "namespace": "agent-coder",
    "key": "tech-stack"
  }'

响应

成功(201 Created)

{
  "id": "mem-abc123",
  "layer": "about_me",
  "kind": "preference"
}

响应字段

字段类型说明
idstring新建条目的唯一 ID
layerstring写入的目标层
kindstring记忆类别

错误码

错误HTTP 状态码说明
ErrLayerNotWritable400目标层不可写。environment(宿主感知器产出)、session、working 是运行时态,不接受人工写入
ErrLayerShared400consensus 层是部门/Cell 级共识,不能携带 actor(个人归属)
ErrLayerNamespaceRequired400agent_memory 层必须指定 namespace。空 namespace 会导致写入成功但永不被召回
ErrUnknownLayer400不认识的层名。通常意味着客户端版本过期
ErrKindRequired400kind 字段为空。kind 是记忆系统多张表的索引键,不可省略
ErrContentQualityRejected400内容未通过质量门控(拦截引擎状态前缀如 PLAN_STATE: 等)
ErrThreatPatternDetected400内容命中威胁模式扫描(凭据泄漏正则 + invisible unicode)

注意事项


相关端点