Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/en/Agent Integration Guide/Portal User Guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,7 @@ read-only fields and shows a message when configuration is unavailable.
| Memories are visible and model settings are read-only | Have the host check that configuration management is enabled, the configuration store is writable, and the identity has permission to edit settings. HTTP enables configuration management automatically only for a declared fixed personal identity. A host can also configure its own storage and authorization. |

For more integration options, see the [Portal design](../../features/F05-personal-memory-portal.md#6-启动与打开页面).

## Browse experience memory

Pass `experience_space` in the JSON body of `POST /portal/api/launch` or as a keyword to the SDK Portal handle’s `launch_url`. Open the link and choose Memory Library → Experience Memory to search, filter by category and inspect read-only details. Links without a bound space retain the personal memory view.
6 changes: 5 additions & 1 deletion docs/features/F05-personal-memory-portal.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,11 @@ KV 模式指由键值存储保存记忆。它能通过相同的公开接口提
切换时侧边栏保持选中记忆仓库。
团队记忆使用 `memory_class=team_memory`,用户画像使用 `memory_class=user_profile`。
项目知识显示 `long_term_memory` 或 `project_memory` 分类中的语义记忆。
经验记忆使用 `memory_type=experience`。群体记录的列表和详情显示归属与标签,详情显示共享状态。
经验记忆使用 `memory_type=experience`。签发链接时指定 `experience_space`,原「经验记忆」分类改为展示该空间的有效经验,支持按正文和类别筛选、分页及只读详情。群体记录的列表和详情显示归属与标签,详情显示共享状态。

经验列表显示最近一次整理的任务归因次数,详情只显示个人评价。个人评价按当前用户、空间和经验保存,可修改或撤回,不参加检索或整理。
列表复用仓库搜索框、状态栏、筛选面板、批量选择、布局切换、分页与空态;来源及关联技能可打开 Portal 内只读视图并返回。列表在时间戳前显示三类任务反馈,尚无反馈的计数为零。列表只读取任务反馈计数;若条目在读取计数时已不可访问,显示“—”。有可读来源时,详情按复现记录展示相关任务与会话,按可读来源条目展示经验血缘,技能由同空间有效技能的 provenance 反查。

切换入口应用该入口的固定条件,并保留应用、Agent、项目、状态和文字条件。
重置清除附加条件并恢复有效状态,在「全部记忆」中也清除手动选择的分类和层级。
即使某一类型暂无记录,也保留当前视图。
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,8 @@ policy 或委托人事实。授予上界仅 ROOT 免除普通成员限制;ADMI
个人空间的唯一用户归属主体可点读本空间的系统经验。该例外仅适用于 `get`,且请求条目
和实际返回快照均按各自的真源类型、作者和空间进行判断。该例外排在委托判定之后,
适用的委托已声明时以委托结果为准。
Portal 经验详情先检查经验条目的读取权限,再按原任务的 Scope 检查内容 READ。
来源任务和会话仅在记录的组织、用户都与认证身份一致且来源鉴权通过时展示。
当前 `inspect/trace` 仍按 READ 判权,未应用该经验特例,也不经过经验检索 Selector;
有空间 READ 权限且知道条目 ID 的成员仍可经治理读取取得完整经验条目。这是直接读取
限制的现有覆盖缺口,不能把 `get/list` 的限制解释为所有查看入口均已收紧。
Expand Down
13 changes: 10 additions & 3 deletions docs/specs/S02-memory-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
| 项 | 值 |
|---|---|
| 关联模块 | jiuwen_memory/api/ |
| 最近一次修订日期 | 2026-11-28 |
| 最近一次修订日期 | 2026-11-30 |
| 关联特性补充 | docs/features/api/F04-memory-metadata-separation.md,docs/features/api/F05-http-memory-api-alignment.md,docs/features/api/F06-access-parameter-forwarding.md,docs/features/api/F07-access-surface-error-semantics.md,docs/features/api/F09-sdk-runtime-logging.md,docs/features/F05-personal-memory-portal.md |
| 关联特性文档 | docs/features/api/F01-memory-api-impl-design.md,docs/features/api/F02-write-infer-extract.md,docs/features/api/F03-batch-write-api.md,docs/features/api/F04-memory-metadata-separation.md,docs/features/api/F05-http-memory-api-alignment.md,docs/features/api/F06-access-parameter-forwarding.md,docs/features/api/F07-access-surface-error-semantics.md,docs/features/api/F09-sdk-runtime-logging.md,docs/features/api/F10-batch-update-api.md,docs/features/F01-system-spec-design.md,docs/features/construction/F02-dynamic-extraction-consolidation.md,docs/features/construction/F04-cc-memory-compat.md,docs/features/construction/F05-construction-spec-multimodal-design.md,docs/features/construction/F08-entity-schema-extension.md,docs/features/common/F01-memory-layer.md,docs/features/common/F03-scope-space-isolation.md,docs/features/common/F08-memory-tree.md,docs/features/common/F09-log-privacy.md,docs/features/retrieval/F03-metadata-filtering.md,docs/features/retrieval/F09-query-rewrite.md,docs/features/control/F04-permission-context-routing.md,docs/features/control/F05-cloud-engine-design.md,docs/features/config/F01-config-source.md,docs/features/control/F07-collective-memory-design.md,docs/features/construction/F13-dreaming.md,docs/features/ingest/F02-assets-ingestor-boundary.md、[F04 安全能力与设计决策](../features/common/F04-security-interfaces-and-encryption.md),docs/features/common/F11-new-trace.md,docs/features/control/F10-async-write-orchestration.md |

Expand Down Expand Up @@ -173,8 +173,15 @@ SDK 和 HTTP 共用定位顺序,优先使用文档根目录,其次使用实
| 纠正记忆 | `/v1/update` | `scope`、`unit_id`、`patch.content` | 新版 `MemoryUnit`,通过 `supersedes` 指向旧版 |
| 遗忘记忆 | `/v1/delete` | `selector.scope`、只含一个 ID 的 `selector.unit_ids`、`selector.mode: "forget"` | 已遗忘的 ID 数组 |
| 配置 | `/v1/read_config`、`/v1/save_config` | 见 HTTP 托管配置接口。跨进程共享页面为指定实例的请求附加 `instance_id` | 同上。跨进程共享页面用空请求体调用 `read_config` 时返回 `instances`、`default_instance_id` |
| HTTP 宿主取得页面链接 | `/portal/api/launch` | 使用原认证凭据,可带 `write_target`(`space`、`agent`、`session`) | `portal_url` |
| 浏览器兑换会话 | `/portal/api/bootstrap` | `token`,可选 `embedded` | 普通独立页面建立 HttpOnly Cookie。iframe 和跨进程共享页面返回 `session_token`。跨进程共享页面另返回 `shared: true` |
| 经验列表 | `/v1/experience_list` | 可选 `query`、`category`、`source`、`agent`、`project`、`lifecycle`、`offset`、`limit` | `available`、`items`、`count` 及筛选选项 |
| 经验详情 | `/v1/experience_get` | `unit_id` | 有效经验、反馈、可读的来源与关联技能 |
| 个人评价 | `/v1/experience_rate` | `unit_id`、`choice`(`helpful`、`neutral`、`harmful`、`clear`) | 任务反馈汇总及当前用户的评价 |
| HTTP 宿主取得页面链接 | `/portal/api/launch` | 使用原认证凭据,可带 `write_target`(`space`、`agent`、`session`)和 `experience_space` | `portal_url` |
| 浏览器兑换会话 | `/portal/api/bootstrap` | `token`,可选 `embedded` | 普通独立页面建立 HttpOnly Cookie。iframe、跨进程共享页面和绑定经验空间的页面返回 `session_token`。共享页面另返回 `shared: true`,绑定经验空间的页面另返回 `experience_bound: true` |

经验接口只接受 Portal 浏览器会话。宿主签发链接时绑定经验空间,显式提供的空间名最多 128 个字符,校验后去除首尾空白。组织取自认证身份,浏览器请求不能指定 Scope。
未绑定经验空间时,经验列表、详情和评价均返回 404。SDK 宿主可在 Portal 句柄的
`launch_url` 上传入 `experience_space`,Swarm Provider 会使用当前启用的经验空间。

页面从 `MemoryUnit.segments` 拼接正文,时间取 `temporal.t_ingest`。HTTP
`write_target` 由宿主提供,与认证身份合成完整写入范围,随会话绑定。独立访问可以
Expand Down
7 changes: 5 additions & 2 deletions docs/specs/S10-security.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ HTTP 启动先检查上述身份声明,再决定是否打开或创建配置库
授权只兑换一次,随后使用 1 小时有效的浏览器会话。使用 Cookie 时必须为 HttpOnly、
SameSite=Strict,路径限定为 `/v1/`。任意来源的宿主网页均可嵌入 Portal。
iframe 和跨进程共享页面兑换会话票据,经 `X-Memory-Portal-Session` 发送同源请求。
普通 iframe 的票据保存在页面内存中。
普通 iframe 的票据保存在页面内存中。宿主签发链接时可绑定经验空间,绑定后页面使用同一请求头,并在
当前浏览器历史条目中记录会话票据以支持刷新。经验请求使用认证组织和绑定的空间,仍检查记录的读取权限。
经验详情仅展示当前用户自己的来源任务和会话,并对每个来源 Scope 单独检查内容读取权限。
共享 Portal 的经验请求只由签发链接的 Provider 处理,来源注销或断开后返回 401。
跨进程共享页面的票据保存在当前浏览器历史条目的状态中,供刷新后继续使用,收到 401 后清除。
共享会话绑定记忆库和签发时的可信身份。该身份可操作具有相同认证主体、角色、凭据标识
和委托的在线实例。
Expand All @@ -71,7 +74,7 @@ iframe 和跨进程共享页面兑换会话票据,经 `X-Memory-Portal-Session
HTTP 的本机 Host 与 Origin 校验继续生效。
Portal 页面、浏览器会话请求和托管配置接口的响应使用 `Cache-Control: no-store`。
Portal 页面通过 `X-Memory-Portal-Browser: 1` 标记业务请求。此类请求必须有有效的浏览器
会话,只能调用个人记忆管理和模型配置所需的接口。会话失效返回 401,页面提示重新打开。
会话,只能调用个人记忆管理、经验记忆和模型配置所需的接口。会话失效返回 401,页面提示重新打开。
HTTP DEV 的直接 API 调用仍使用原认证规则。

SDK 每次请求重新取得并复核宿主的可信身份。HTTP 会话用原凭据重新认证,并保留原来的
Expand Down
4 changes: 4 additions & 0 deletions docs/zh/Agent接入指导/Portal使用指南.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,7 @@ curl -fsS "${portal_base_url}/portal/api/launch" \
| 能读记忆,模型设置却不可编辑 | 由宿主检查是否启用了配置管理、配置库位置是否可写,以及当前身份是否有配置权限。HTTP 自动启用配置管理需要声明固定个人身份,宿主也可以显式装配配置存储和授权。 |

更多接入选项见 [Portal 设计说明](../../features/F05-personal-memory-portal.md#6-启动与打开页面)。

## 查看空间中的经验记忆

在 HTTP 签发接口 `POST /portal/api/launch` 的 JSON 请求体中传入 `{"experience_space":"你的空间名"}`,或在 SDK Portal 的 `launch_url` 中传入同名关键字参数。打开返回的链接,选择「记忆仓库 → 经验记忆」,可搜索正文、按类别筛选,点击条目查看适用条件、所需能力和操作建议。普通链接沿用个人记忆范围。
88 changes: 88 additions & 0 deletions jiuwen_memory/api/memory_api_impl/query_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
from __future__ import annotations

import asyncio
import hashlib
import json
from collections.abc import Awaitable, Callable
from copy import deepcopy
from dataclasses import dataclass, replace
from datetime import UTC, datetime
from functools import partial
from pathlib import PurePosixPath
from typing import Any

from jiuwen_memory.api.collective import collective_coordinates, dimensions_of
Expand All @@ -27,6 +29,7 @@
PermissionDeniedError,
ValidationError,
)
from jiuwen_memory.common.experience import UtilityStore
from jiuwen_memory.common.log import get_logger, metadata_for_log, redact_for_log
from jiuwen_memory.common.plaintext import PlaintextDataError
from jiuwen_memory.common.security import principal, space_predicates
Expand All @@ -49,6 +52,7 @@
FilterOp,
HierarchyKind,
HierarchyRole,
LifecycleState,
MemoryUnit,
Scope,
and_merge,
Expand Down Expand Up @@ -171,6 +175,14 @@ def _copy_search_extensions(extensions: dict[str, Any]) -> dict[str, Any]:
return deepcopy(extensions, memo)


def _is_active_experience(unit: MemoryUnit, scope: Scope) -> bool:
return (
unit.scope == scope
and unit.lifecycle is LifecycleState.ACTIVE
and unit.system_metadata.get("memory_type") == "experience"
)


class QueryOpsMixin:
"""Data-plane read/update/delete/evolve after PEP."""

Expand Down Expand Up @@ -969,6 +981,82 @@ def _list_scope(
result.items = visible
return result

def experience_task_sources(self, unit_id, scope, *, security):
"""Disclose only the current user's authorized session and task references."""
unit = self.get(unit_id, scope, security=security)
actor = security.auth.actor
if not actor.user or actor.org != scope.org or not _is_active_experience(unit, scope):
return []
sources = {}
store = UtilityStore(self._engine.kv)
for coordinates, key, event in store.reproduction_sources(scope, unit_id):
org, space, user, agent, session = coordinates
if (org, user) != (actor.org, actor.user):
continue
target = Scope(org=org, space=space, user=user, agent=agent, session=session)
try:
self._authorize(security, target, Action.READ, "experience_source")
except (NotFoundError, PermissionDeniedError):
continue
ref = (session, key.trajectory_id)
if ref not in sources or key.revision > sources[ref]["revision"]:
sources[ref] = {
"session": session, "task": key.trajectory_id, "revision": key.revision,
"agent": agent, "outcome": event.get("outcome", ""),
"occurred_at": event.get("occurred_at", ""),
}
return [sources[ref] for ref in sorted(sources)]

def experience_counts(
self, unit_id: str, scope: Scope, *, security: RequestSecurityContext,
) -> tuple[MemoryUnit, dict]:
"""Read the authorized experience and its aggregate task feedback."""
unit = self.get(unit_id, scope, security=security)
actor = security.auth.actor
if scope.org != actor.org or not scope.space or not _is_active_experience(unit, scope):
raise NotFoundError("memory_unit", unit_id)
stats = UtilityStore(self._engine.kv).load_stats(scope, unit_id)
counts = {
"helpful": sum(stats.helpful.values()) if stats else 0,
"neutral": stats.neutral if stats else 0,
"harmful": sum(stats.harmful.values()) if stats else 0,
}
return unit, counts

def experience_feedback(
self, unit_id: str, scope: Scope, *, security: RequestSecurityContext,
choice: str = "read",
) -> tuple[MemoryUnit, dict]:
"""Read an authorized experience and its stats; optionally replace my own assessment."""
unit, counts = self.experience_counts(unit_id, scope, security=security)
if choice not in ("read", "clear", "helpful", "neutral", "harmful"):
raise ValidationError("invalid personal experience feedback")
actor = security.auth.actor
kv = self._engine.kv
feedback = {"counts": counts, "can_rate": bool(actor.user), "mine": None}
if not actor.user:
if choice != "read":
raise PermissionDeniedError(message="personal feedback requires a user")
return unit, feedback
owner = Scope(org=actor.org, user=actor.user)
target = json.dumps([actor.org, actor.user, scope.space, unit_id]).encode()
key = str(PurePosixPath("/experience/personal-rating", hashlib.sha256(target).hexdigest()))
if choice == "clear":
kv.delete(owner, key)
elif choice == "read":
try:
feedback["mine"] = kv.get(owner, key).decode("ascii")
except NotFoundError:
pass
else:
value = choice.encode("ascii")
try:
kv.insert(owner, key, value)
except ConflictError:
kv.update(owner, key, value)
feedback["mine"] = choice
return unit, feedback

def get(
self,
unit_id: str,
Expand Down
Loading
Loading