> ## Documentation Index
> Fetch the complete documentation index at: https://oma-codex-339-workspace-permissions.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# 更新记忆

> 通过 OMA API 更新记忆。

<Info>每个请求都必须发送 `?beta=true`。</Info>


## OpenAPI

````yaml /openapi/oma.zh.json post /v1/memory_stores/{memory_store_id}/memories/{memory_id}
openapi: 3.1.0
info:
  title: OMA API 参考
  version: 1.0.0
  description: Open Managed Agents 应用 API 参考。
servers:
  - url: http://localhost:38080
    description: 本地 OMA 服务器
security:
  - omaApiKey: []
  - omaBearer: []
paths:
  /v1/memory_stores/{memory_store_id}/memories/{memory_id}:
    post:
      summary: 更新记忆
      operationId: BetaUpdateMemory
      parameters:
        - name: beta
          in: query
          required: true
          description: 为此接口启用 Beta API 合同，必须为 `true`。
          schema:
            type: boolean
            enum:
              - true
        - name: anthropic-version
          in: header
          required: false
          schema:
            type: string
        - name: anthropic-beta
          in: header
          required: false
          schema:
            type: string
            items:
              type: string
            x-stainless-override-schema:
              x-stainless-param: betas
              x-stainless-extend-default: true
              type: array
              description: 用于指定一个或多个 Beta 版本的可选请求头。
              items:
                $ref: '#/components/schemas/AnthropicBeta'
            x-default: agent-memory-2026-07-22
        - name: memory_store_id
          in: path
          required: true
          schema:
            type: string
          description: 记忆存储标识符。
        - name: memory_id
          in: path
          required: true
          schema:
            type: string
            x-stainless-cli-data-alias: id
          description: 记忆标识符。
        - name: view
          in: query
          required: false
          schema:
            $ref: '#/components/schemas/BetaManagedAgentsMemoryView'
          description: view 的查询参数
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/BetaManagedAgentsUpdateMemoryParams'
      responses:
        '200':
          description: 请求成功。
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsMemory'
        '400':
          description: Invalid argument - 客户端指定了无效的参数
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '401':
          description: 未认证 - 请求没有有效的认证凭据
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '403':
          description: 权限被拒绝 - 调用方没有执行指定操作的权限
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '404':
          description: 未找到 - 请求的某个实体不存在
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '408':
          description: 超出截止时间 - 截止时间在操作完成之前已过期
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '409':
          description: 自定义错误状态
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '412':
          description: 前置条件不满足 - 由于系统未处于所需状态，操作被拒绝
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '413':
          description: Out of range - 尝试的操作超出了有效范围
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '429':
          description: 资源耗尽 - 某些资源已被耗尽（限流）
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '431':
          description: 请求头字段过大 - 请求元数据过大
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '499':
          description: Cancelled - 操作已被客户端取消
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '500':
          description: Internal - 内部服务器错误
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '501':
          description: 未实现 - 该操作未实现或不受支持
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '503':
          description: 不可用 - 服务当前不可用
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
        '504':
          description: 超时 - 上游服务未及时响应
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BetaManagedAgentsErrorResponse'
components:
  schemas:
    BetaManagedAgentsMemoryView:
      type: string
      description: >-
        选择服务器返回 `memory` 或 `memory_version` 的哪种投影。`basic` 返回 `content` 置为 `null`
        的对象；`full` 会填充 `content`。省略时默认值因端点而异：检索操作默认为 `full`；列表、创建和更新操作默认为
        `basic`。使用 `view=full` 进行列表查询时，`limit` 上限为 20。
      enum:
        - basic
        - full
    BetaManagedAgentsUpdateMemoryParams:
      description: >-
        更新记忆的请求参数。必须至少提供 `content` 或 `path` 之一。重命名到被另一个记忆占用的路径会返回
        `memory_path_conflict_error`（HTTP
        409）。重命名从不覆盖；请先删除或重命名占位记忆。如果所提供的所有字段都已与存储值一致，则该更新为无操作：返回 200
        和现有记忆，且不写入新版本。
      type: object
      additionalProperties: false
      properties:
        content:
          description: 记忆的新 UTF-8 文本内容。最大 100 kB（102,400 字节）。省略则保持内容不变（例如仅重命名的更新）。
          type: string
          nullable: true
        path:
          description: >-
            记忆的新路径（重命名）。必须以 `/` 开头，至少包含一个非空片段，且不超过 1,024 字节。不得包含空片段、`.` 或 `..`
            片段、控制字符或格式字符，且必须为 NFC 规范化。路径区分大小写。重命名后记忆的 `id` 保持不变。省略则路径不变。
          type: string
          minLength: 2
          maxLength: 1024
          nullable: true
        precondition:
          description: >-
            可选的乐观并发前置条件。提供时，仅当该记忆的当前状态匹配时才应用更新；不匹配时请求返回
            `memory_precondition_failed_error`（HTTP 409）。省略时，更新无条件应用。
          allOf:
            - $ref: '#/components/schemas/BetaManagedAgentsPrecondition'
    BetaManagedAgentsMemory:
      description: >-
        `memory` 对象：记忆存储中位于层级路径上的单个文本文档。`view=full` 时填充 `content`
        字段，`view=basic` 时为 `null`；`content_size_bytes` 和 `content_sha256`
        字段始终填充，以便同步客户端无需拉取内容即可比对差异。记忆以其 `mem_...` ID 寻址；路径是创建时的键，可通过更新修改。
      type: object
      additionalProperties: false
      required:
        - type
        - id
        - memory_store_id
        - path
        - content_size_bytes
        - content_sha256
        - memory_version_id
        - created_at
        - updated_at
      properties:
        type:
          type: string
          enum:
            - memory
        id:
          description: 此记忆的唯一标识符（`mem_...` 格式的值）。重命名后保持不变；读取、更新或删除该记忆时应使用此 ID 而非路径。
          type: string
        memory_store_id:
          description: 该记忆所属的记忆存储的 ID（`memstore_...` 格式的值）。
          type: string
        path:
          description: >-
            该记忆在存储内的层级路径，例如 `/projects/foo/notes.md`。始终以 `/`
            开头。路径区分大小写，且在同一存储内唯一。最大 1,024 字节。
          type: string
        content:
          description: >-
            记忆的 UTF-8 文本内容。`view=full` 时填充；`view=basic` 时为 `null`。最大 100
            kB（102,400 字节）。
          type: string
          nullable: true
        content_size_bytes:
          description: '`content` 的字节大小（UTF-8 明文长度）。无论 `view` 为何值，始终填充。'
          type: integer
          format: int32
        content_sha256:
          description: >-
            UTF-8 `content` 字节的小写十六进制 SHA-256 摘要（64
            个字符）。服务端不做任何规范化处理，因此客户端可在本地计算相同的哈希，用于过期检查，并作为更新时 `content_sha256`
            前置条件的值。无论 `view` 如何，此字段始终填充。
          type: string
        memory_version_id:
          description: >-
            表示此记忆当前内容的 `memory_version` 的 ID（`memver_...`
            值）。这是权威的头部指针；`memory_version` 对象不携带 `is_latest`
            标志，因此请改为与此字段比较。可通过列出记忆版本枚举完整历史。
          type: string
        created_at:
          description: 此记忆的创建时间，采用 RFC 3339 格式。
          allOf:
            - $ref: '#/components/schemas/BetaTimestamp'
        updated_at:
          description: >-
            该记忆最近一次修改的时间，采用 RFC 3339 格式。可将其用作低成本的时效性信号；如需了解是谁做出的修改，请通过列出记忆版本查询
            head 版本的 `created_by`。
          allOf:
            - $ref: '#/components/schemas/BetaTimestamp'
    BetaManagedAgentsErrorResponse:
      type: object
      required:
        - type
        - error
      properties:
        type:
          type: string
          enum:
            - error
          description: 错误响应始终为 "error"
        error:
          $ref: '#/components/schemas/BetaManagedAgentsError'
    BetaManagedAgentsPrecondition:
      description: >-
        更新得以应用所必须满足的可选条件。省略时更新无条件执行。它断言被更新记忆的当前状态。当更新修改 `path`
        时，前置条件仍指向该记忆的当前内容，而非目标路径。目前唯一支持的变体是 `content_sha256`。
      type: object
      discriminator:
        propertyName: type
        mapping:
          content_sha256:
            $ref: '#/components/schemas/BetaManagedAgentsContentSha256Precondition'
      oneOf:
        - $ref: '#/components/schemas/BetaManagedAgentsContentSha256Precondition'
    BetaTimestamp:
      description: RFC 3339 格式的时间戳
      type: string
      format: date-time
    BetaManagedAgentsError:
      discriminator:
        propertyName: type
        mapping:
          invalid_request_error:
            $ref: '#/components/schemas/BetaInvalidRequestError'
          authentication_error:
            $ref: '#/components/schemas/BetaAuthenticationError'
          billing_error:
            $ref: '#/components/schemas/BetaBillingError'
          permission_error:
            $ref: '#/components/schemas/BetaPermissionError'
          not_found_error:
            $ref: '#/components/schemas/BetaNotFoundError'
          rate_limit_error:
            $ref: '#/components/schemas/BetaRateLimitError'
          timeout_error:
            $ref: '#/components/schemas/BetaGatewayTimeoutError'
          api_error:
            $ref: '#/components/schemas/BetaAPIError'
          overloaded_error:
            $ref: '#/components/schemas/BetaOverloadedError'
          memory_precondition_failed_error:
            $ref: >-
              #/components/schemas/BetaManagedAgentsMemoryPreconditionFailedError
          memory_path_conflict_error:
            $ref: '#/components/schemas/BetaManagedAgentsMemoryPathConflictError'
          conflict_error:
            $ref: '#/components/schemas/BetaManagedAgentsConflictError'
      oneOf:
        - $ref: '#/components/schemas/BetaInvalidRequestError'
        - $ref: '#/components/schemas/BetaAuthenticationError'
        - $ref: '#/components/schemas/BetaBillingError'
        - $ref: '#/components/schemas/BetaPermissionError'
        - $ref: '#/components/schemas/BetaNotFoundError'
        - $ref: '#/components/schemas/BetaRateLimitError'
        - $ref: '#/components/schemas/BetaGatewayTimeoutError'
        - $ref: '#/components/schemas/BetaAPIError'
        - $ref: '#/components/schemas/BetaOverloadedError'
        - $ref: '#/components/schemas/BetaManagedAgentsMemoryPreconditionFailedError'
        - $ref: '#/components/schemas/BetaManagedAgentsMemoryPathConflictError'
        - $ref: '#/components/schemas/BetaManagedAgentsConflictError'
    BetaManagedAgentsContentSha256Precondition:
      description: >-
        乐观并发前置条件：仅当该记忆存储的 `content_sha256` 等于所提供的值时，更新才会应用。不匹配时，请求返回
        `memory_precondition_failed_error`（HTTP
        409）；请重新读取该记忆并基于最新状态重试。如果前置条件失败，但存储状态已与请求的 `content` 和 `path`
        完全一致，服务器将返回 200 而不是 409。
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - content_sha256
        content_sha256:
          description: >-
            所存储记忆的预期 `content_sha256`（64 个小写十六进制字符）。通常为先前读取或列表调用返回的
            `content_sha256`。由于服务端不做任何内容规范化处理，客户端也可以在本地将其计算为 UTF-8 内容字节的
            SHA-256。
          type: string
    BetaInvalidRequestError:
      properties:
        message:
          default: Invalid request
          title: 消息
          type: string
        type:
          const: invalid_request_error
          default: invalid_request_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: InvalidRequestError
      type: object
    BetaAuthenticationError:
      properties:
        message:
          default: Authentication error
          title: 消息
          type: string
        type:
          const: authentication_error
          default: authentication_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: AuthenticationError
      type: object
    BetaBillingError:
      properties:
        message:
          default: Billing error
          title: 消息
          type: string
        type:
          const: billing_error
          default: billing_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: BillingError
      type: object
    BetaPermissionError:
      properties:
        message:
          default: Permission denied
          title: 消息
          type: string
        type:
          const: permission_error
          default: permission_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: PermissionError
      type: object
    BetaNotFoundError:
      properties:
        message:
          default: Not found
          title: 消息
          type: string
        type:
          const: not_found_error
          default: not_found_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: NotFoundError
      type: object
    BetaRateLimitError:
      properties:
        message:
          default: Rate limited
          title: 消息
          type: string
        type:
          const: rate_limit_error
          default: rate_limit_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: RateLimitError
      type: object
    BetaGatewayTimeoutError:
      properties:
        message:
          default: Request timeout
          title: 消息
          type: string
        type:
          const: timeout_error
          default: timeout_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: GatewayTimeoutError
      type: object
    BetaAPIError:
      properties:
        message:
          default: Internal server error
          title: 消息
          type: string
        type:
          const: api_error
          default: api_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: APIError
      type: object
    BetaOverloadedError:
      properties:
        message:
          default: Overloaded
          title: 消息
          type: string
        type:
          const: overloaded_error
          default: overloaded_error
          title: 类型
          type: string
      required:
        - message
        - type
      title: OverloadedError
      type: object
    BetaManagedAgentsMemoryPreconditionFailedError:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - memory_precondition_failed_error
        message:
          type: string
    BetaManagedAgentsMemoryPathConflictError:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - memory_path_conflict_error
        message:
          type: string
        conflicting_path:
          type: string
        conflicting_memory_id:
          type: string
    BetaManagedAgentsConflictError:
      type: object
      additionalProperties: false
      required:
        - type
      properties:
        type:
          type: string
          enum:
            - conflict_error
        message:
          type: string
  securitySchemes:
    omaApiKey:
      type: apiKey
      in: header
      name: X-Api-Key
      description: OMA 工作区 API 密钥。
      x-default: sk-ant-local-default
    omaBearer:
      type: http
      scheme: bearer
      description: 以 Bearer 令牌形式发送的 OMA 工作区 API 密钥。

````