feat(memory-gateway): 引入 Memory Gateway 配置、凭据存储和服务编排
* 新增 MemoryGatewayConfig 和 MemoryConfig dataclass,用于配置管理。 * 实现 MemoryGatewayUserCredential 和 MemoryGatewayCredentialStore,用于处理用户凭据。 * 创建 MemoryGatewayService,用于管理与 Memory Gateway 的交互。 * 开发用于记忆设置的 JSON 配置文件。 * 增强单元测试,覆盖新功能,包括凭据存储和服务行为。 * 更新 entrypoint 和实例创建脚本,以初始化 Memory Gateway 用户存储。
This commit is contained in:
@ -35,19 +35,23 @@ Curated memory 始终启用:每轮仍会冻结并注入 `MEMORY.md` / `USER.md
|
||||
每轮先调用 `/memories/search`,正常完成后调用一次 `/memories/add`,成功后再调用
|
||||
一次 `/memories/flush`。两套存储不会互相同步、覆盖或去重。
|
||||
|
||||
完整配置示例:
|
||||
共享 Gateway 配置放在:
|
||||
|
||||
```text
|
||||
app-instance/backend/memory/config.json
|
||||
```
|
||||
|
||||
当前默认内容:
|
||||
|
||||
```json
|
||||
{
|
||||
"memory": {
|
||||
"mode": "hybrid",
|
||||
"gateway": {
|
||||
"baseUrl": "http://127.0.0.1:8010",
|
||||
"userId": "gateway_test_user",
|
||||
"userKey": "uk_xxx",
|
||||
"baseUrl": "http://172.19.207.37:8010",
|
||||
"appId": "default",
|
||||
"projectId": "default",
|
||||
"scope": ["current_chat", "resources"],
|
||||
"scope": ["current_chat", "resources", "all_user_memory"],
|
||||
"topK": 8,
|
||||
"timeoutSeconds": 10
|
||||
}
|
||||
@ -55,10 +59,28 @@ Curated memory 始终启用:每轮仍会冻结并注入 `MEMORY.md` / `USER.md
|
||||
}
|
||||
```
|
||||
|
||||
- `memory` 整段缺失时,默认采用隐式 `hybrid`;Gateway 凭证不完整会告警并只运行 curated memory。
|
||||
- 显式配置 `"mode": "hybrid"` 时,`baseUrl`、`userId` 和 `userKey` 缺失会导致启动失败。
|
||||
- 配置 `"mode": "curated"` 可关闭 Gateway,curated memory 行为不变。
|
||||
每个实例自己的 Gateway 用户凭证放在:
|
||||
|
||||
```text
|
||||
/root/.beaver/memory_gateway_users.json
|
||||
```
|
||||
|
||||
格式示例:
|
||||
|
||||
```json
|
||||
{
|
||||
"users": {
|
||||
"tom": {
|
||||
"userId": "tom",
|
||||
"userKey": "uk_xxx"
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
- 前端 `POST /api/auth/register` 会用 Beaver 登录用户名调用 Gateway `POST /users`,并把返回的 `userId/userKey` 写入实例凭证文件。
|
||||
- REST `/api/chat` 和 WebSocket `/ws/...` 只使用登录 token 解析出的 Beaver 用户名来选择 Gateway 凭证,请求体里的 `user_id` 不参与 Gateway 身份选择。
|
||||
- 某个登录用户还没有 Gateway 凭证时,这一轮只走 curated memory,不会报 chat 级错误。
|
||||
- `BEAVER_MEMORY_CONFIG_PATH` 可覆盖共享 memory 配置路径,`BEAVER_MEMORY_GATEWAY_USERS_PATH` 可覆盖实例凭证路径。
|
||||
- `userKey` 是密钥,不应写入日志、状态响应或提交到版本库。
|
||||
- 容器访问宿主机 Gateway 时不能使用容器内的 `127.0.0.1`。应让 Gateway 监听
|
||||
`0.0.0.0`,并把 `baseUrl` 配成该 Docker 网络的宿主机网关地址。
|
||||
- 修改 memory 配置后需要重启 runtime,因为 Gateway 服务在 `EngineLoader` 启动时创建。
|
||||
- 修改共享 memory 配置后需要重启 runtime,因为 Gateway 相关对象在 `EngineLoader` 启动时装配。
|
||||
|
||||
Reference in New Issue
Block a user