Skip to content

Commit 76d7801

Browse files
committed
update agentloop memory
Change-Id: I482efb8dc24199091960a981202158eedd17972d Co-developed-by: Claude <noreply@anthropic.com>
1 parent ec522f0 commit 76d7801

6 files changed

Lines changed: 460 additions & 7 deletions

File tree

start-mcp-aliyun-agentloop-memory/publish.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Edition: 3.0.0
22
Type: Project
33
Name: mcp-agentloop-memory
4-
Version: Dev
4+
Version: dev.0.10
55
Provider:
66
- 阿里云 # 取值内容参考:https://api.devsapp.cn/v3/common/args.html
77
Description: AgentLoop Memory MCP Server
@@ -45,4 +45,4 @@ Parameters:
4545
name: AliyunFCDefaultRole
4646
service: FC
4747
authorities:
48-
- AliyunCMSFullAccess
48+
- AliyunCloudMonitorFullAccess
Lines changed: 186 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,187 @@
1-
# start-application-cap 帮助文档
21

3-
CAP应用示例模版
2+
> 注:当前项目为 Serverless Devs 应用,由于应用中会存在需要初始化才可运行的变量(例如应用部署地区、函数名等等),所以**不推荐**直接 Clone 本仓库到本地进行部署或直接复制 s.yaml 使用,**强烈推荐**通过 `s init ${模版名称}` 的方法或应用中心进行初始化,详情可参考[部署 & 体验](#部署--体验)
3+
4+
# mcp-agentloop-memory 帮助文档
5+
6+
<description>
7+
8+
AgentLoop Memory MCP Server
9+
10+
</description>
11+
12+
13+
## 资源准备
14+
15+
使用该项目,您需要有开通以下服务并拥有对应权限:
16+
17+
<service>
18+
19+
20+
21+
| 服务/业务 | 权限 | 相关文档 |
22+
| --- | --- | --- |
23+
| 函数计算 | AliyunFCFullAccess | [帮助文档](https://help.aliyun.com/product/2508973.html) [计费文档](https://help.aliyun.com/document_detail/2512928.html) |
24+
25+
</service>
26+
27+
<remark>
28+
29+
30+
31+
</remark>
32+
33+
<disclaimers>
34+
35+
36+
37+
</disclaimers>
38+
39+
## 部署 & 体验
40+
41+
<appcenter>
42+
43+
- :fire: 通过 [云原生应用开发平台 CAP](https://functionai.console.aliyun.com/template-detail?template=mcp-agentloop-memory)[![Deploy with Severless Devs](https://img.alicdn.com/imgextra/i1/O1CN01w5RFbX1v45s8TIXPz_!!6000000006118-55-tps-95-28.svg)](https://functionai.console.aliyun.com/template-detail?template=mcp-agentloop-memory) 该应用。
44+
45+
</appcenter>
46+
<deploy>
47+
48+
49+
</deploy>
50+
51+
## 案例介绍
52+
53+
<appdetail id="flushContent">
54+
55+
### alibabacloud-agentloop-memory-mcp-server
56+
57+
阿里云 AgentLoop MemoryStore 的 MCP Server 实现,为 AI Agent 提供长期记忆管理能力,支持通过 MCP 协议(SSE 传输)进行记忆的增删改查和语义搜索。
58+
59+
#### AgentLoop MemoryStore
60+
61+
[AgentLoop MemoryStore](https://www.alibabacloud.com/) 是阿里云提供的全托管 AI Agent 长期记忆服务。它为 AI Agent 提供智能记忆层,使其能够跨会话记住用户偏好、持续学习并实现个性化交互,适用于智能客服、个人助理、教育辅导等场景。
62+
63+
**核心特性:**
64+
65+
- **多维度记忆**:自动从对话中提取用户偏好、事实陈述、会话摘要等结构化记忆,支持自定义提取策略
66+
- **分层检索**:L1 混合检索 → L2 Rerank 精排 → L3 Agentic Search,兼顾召回广度与精度
67+
- **异步提取**:记忆处理异步执行,不阻塞 Agent 主流程,支持弹性扩缩容
68+
- **全托管**:无需搭建向量数据库或维护存储实例,开通即用
69+
- **可观测**:内置监控大盘,覆盖检索延迟、Token 消耗、存储量等核心指标
70+
71+
本案例将 AgentLoop MemoryStore 封装为标准 [MCP](https://modelcontextprotocol.io/) Server,支持 Cursor、Claude Desktop 等 MCP 客户端直接接入。
72+
73+
74+
#### 安装
75+
76+
```bash
77+
pip install alibabacloud-agentloop-memory-mcp-server
78+
```
79+
80+
#### 快速开始
81+
82+
##### 1. 配置环境变量
83+
84+
```bash
85+
export ALIBABA_CLOUD_ACCESS_KEY_ID=your_access_key_id
86+
export ALIBABA_CLOUD_ACCESS_KEY_SECRET=your_access_key_secret
87+
export ALIBABA_CLOUD_REGION_ID=cn-hangzhou
88+
export ALIBABA_CLOUD_WORKSPACE=your_workspace_name
89+
export ALIBABA_CLOUD_MEMORY_STORE=your_memory_store_name
90+
```
91+
92+
##### 2. 启动服务
93+
94+
```bash
95+
# 使用 python -m 启动
96+
python -m mcp_server_agentloop_memory
97+
98+
# 或使用命令行入口
99+
alibabacloud-agentloop-memory-mcp-server
100+
101+
# 指定参数启动
102+
python -m mcp_server_agentloop_memory \
103+
--access-key-id <your_ak_id> \
104+
--access-key-secret <your_ak_secret> \
105+
--region-id cn-hangzhou \
106+
--workspace <workspace_name> \
107+
--memory-store <memory_store_name> \
108+
--port 8080
109+
```
110+
111+
##### 3. 连接 MCP Client
112+
113+
服务启动后,MCP Client 通过 SSE 连接:
114+
115+
```
116+
GET http://localhost:8080/mcp/{client_name}/sse/{user_id}
117+
```
118+
119+
- `client_name`:客户端标识(如 `cursor``my-agent`),映射为 `agent_id`
120+
- `user_id`:用户标识,用于隔离不同用户的记忆数据
121+
122+
#### CLI 参数
123+
124+
| 参数 | 环境变量 | 默认值 | 说明 |
125+
|------|---------|--------|------|
126+
| `--access-key-id` | `ALIBABA_CLOUD_ACCESS_KEY_ID` | - | 阿里云 AccessKey ID |
127+
| `--access-key-secret` | `ALIBABA_CLOUD_ACCESS_KEY_SECRET` | - | 阿里云 AccessKey Secret |
128+
| `--region-id` | `ALIBABA_CLOUD_REGION_ID` | `cn-hangzhou` | 阿里云区域 |
129+
| `--workspace` | `ALIBABA_CLOUD_WORKSPACE` | - | Workspace 名称 |
130+
| `--memory-store` | `ALIBABA_CLOUD_MEMORY_STORE` | - | Memory Store 名称 |
131+
| `--host` | - | `0.0.0.0` | 监听地址 |
132+
| `--port` | - | `8080` | 监听端口 |
133+
| `--log-level` | - | `INFO` | 日志级别 |
134+
135+
#### MCP Tools
136+
137+
| 工具名 | 参数 | 说明 |
138+
|--------|------|------|
139+
| `add_memories` | `text: str` | 添加记忆。当用户分享个人信息、偏好或要求记住某些内容时调用 |
140+
| `search_memory` | `query: str` | 语义搜索记忆。用户提问时自动调用,返回按相关度排序的记忆 |
141+
| `list_memories` || 列出当前用户的所有记忆 |
142+
| `delete_memories` | `memory_ids: list[str]` | 按 ID 删除指定记忆 |
143+
| `delete_all_memories` || 删除当前用户的所有记忆 |
144+
145+
#### 权限要求
146+
147+
需要阿里云 RAM 用户具有 AgentLoop MemoryStore 相关 API 的访问权限。获取和管理 AccessKey 请参考[阿里云 AccessKey 管理](https://help.aliyun.com/document_detail/53045.html)
148+
149+
#### 开发
150+
151+
```bash
152+
# 安装开发依赖
153+
pip install -e ".[dev]"
154+
155+
# 运行测试(需要配置环境变量)
156+
pytest tests/ -v
157+
```
158+
159+
160+
161+
162+
</appdetail>
163+
164+
165+
166+
167+
168+
169+
170+
## 使用流程
171+
172+
<usedetail id="flushContent">
173+
174+
部署完成拿到 URL 后,准备好支持 SSE 的 MCP Client,通过 SSETransport 进行连接。
175+
176+
</usedetail>
177+
178+
## 二次开发指南
179+
180+
<development id="flushContent">
181+
</development>
182+
183+
184+
185+
186+
187+
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
alibabacloud-agentloop-memory-mcp-server==0.1.0
1+
alibabacloud-agentloop-memory-mcp-server==0.1.3
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"tools": [
3+
{
4+
"inputSchema": {
5+
"type": "object",
6+
"title": "add_memoriesArguments",
7+
"properties": {
8+
"text": {
9+
"description": "The text content to store as a memory. This can be personal info, preferences, or anything the user wants to remember.",
10+
"title": "Text",
11+
"type": "string"
12+
}
13+
},
14+
"required": [
15+
"text"
16+
]
17+
},
18+
"name": "add_memories",
19+
"description": "Add a new memory. Called when the user shares personal info, preferences, or asks you to remember something.\n\n ## 功能概述\n\n 将用户提供的文本内容存储为新的记忆。系统会自动对文本进行推理提取(infer=True),从中识别出关键信息并存储。\n\n ## 使用场景\n\n - 当用户分享个人信息时(如姓名、职业、兴趣爱好等)\n - 当用户明确要求「记住这个」时\n - 当用户表达偏好或习惯时\n\n ## 返回数据结构\n\n 返回的结果包含:\n - request_id: 请求唯一标识\n - results: 记忆存储结果列表,每项包含 event_id、message、status\n\n ## 使用示例\n\n - \"记住我喜欢喝咖啡\"\n - \"我的名字是张三\"\n - \"我对花生过敏\"\n\n Args:\n text: 要存储为记忆的文本内容\n\n Returns:\n 包含 request_id 和 results 列表的 JSON 字符串\n "
20+
},
21+
{
22+
"inputSchema": {
23+
"type": "object",
24+
"title": "search_memoryArguments",
25+
"properties": {
26+
"query": {
27+
"description": "The search query to find relevant memories.",
28+
"title": "Query",
29+
"type": "string"
30+
}
31+
},
32+
"required": [
33+
"query"
34+
]
35+
},
36+
"name": "search_memory",
37+
"description": "Search through stored memories. Called whenever the user asks anything.\n\n ## 功能概述\n\n 通过语义搜索查找与查询内容相关的记忆,返回最相关的记忆条目以及相关的关系图谱数据。\n\n ## 使用场景\n\n - 当用户提问时,搜索相关记忆以提供个性化回答\n - 当需要回忆用户之前提到的偏好或信息时\n - 当需要获取用户的历史上下文时\n\n ## 返回数据结构\n\n 返回的结果包含:\n - results: 记忆列表,每项包含 id、memory、score、user_id、agent_id、created_at、updated_at、hash、metadata\n - relations: 关系图谱列表,每项包含 source、relationship、destination\n\n ## 使用示例\n\n - \"我之前说过我喜欢什么?\"\n - \"我的饮食偏好是什么?\"\n - \"你还记得我的名字吗?\"\n\n Args:\n query: 用于搜索记忆的查询文本\n\n Returns:\n 包含 results 和 relations 的 JSON 字符串\n "
38+
},
39+
{
40+
"inputSchema": {
41+
"type": "object",
42+
"title": "list_memoriesArguments",
43+
"properties": {},
44+
"required": []
45+
},
46+
"name": "list_memories",
47+
"description": "List all memories for the current user.\n\n ## 功能概述\n\n 列出当前用户的所有已存储记忆,不需要任何查询参数。用户身份通过 SSE 连接的 URL 路径自动注入。\n\n ## 使用场景\n\n - 当用户想查看所有已存储的记忆时\n - 当需要展示记忆概览时\n - 当用户问「你都记住了什么」时\n\n ## 返回数据结构\n\n 返回的结果包含:\n - results: 记忆列表,每项包含 id、memory、score、user_id、agent_id、created_at、updated_at、hash、metadata\n\n ## 使用示例\n\n - \"你都记住了哪些关于我的信息?\"\n - \"列出所有记忆\"\n - \"展示我的记忆列表\"\n\n Returns:\n 包含 results 列表的 JSON 字符串\n "
48+
},
49+
{
50+
"inputSchema": {
51+
"type": "object",
52+
"title": "delete_memoriesArguments",
53+
"properties": {
54+
"memory_ids": {
55+
"description": "List of memory IDs to delete.",
56+
"title": "Memory Ids",
57+
"type": "array",
58+
"items": {
59+
"type": "string"
60+
}
61+
}
62+
},
63+
"required": [
64+
"memory_ids"
65+
]
66+
},
67+
"name": "delete_memories",
68+
"description": "Delete specific memories by their IDs.\n\n ## 功能概述\n\n 根据记忆 ID 列表批量删除指定的记忆条目。支持一次删除多条记忆,并返回删除结果统计。\n\n ## 使用场景\n\n - 当用户要求删除某条特定记忆时\n - 当用户要求忘记某些信息时\n - 当需要清理过时或错误的记忆时\n\n ## 返回数据结构\n\n 返回删除结果的文本描述,包含:\n - 成功删除的数量\n - 如有错误,附带错误详情\n\n ## 使用示例\n\n - \"删除这条记忆:abc123\"\n - \"忘记我之前说的那个偏好\"\n\n Args:\n memory_ids: 要删除的记忆 ID 列表\n\n Returns:\n 删除操作的结果描述字符串\n "
69+
},
70+
{
71+
"inputSchema": {
72+
"type": "object",
73+
"title": "delete_all_memoriesArguments",
74+
"properties": {},
75+
"required": []
76+
},
77+
"name": "delete_all_memories",
78+
"description": "Delete all memories for the current user.\n\n ## 功能概述\n\n 删除当前用户的所有记忆数据。这是一个不可逆操作,执行后用户的全部记忆将被永久清除。\n\n ## 使用场景\n\n - 当用户明确要求清除所有记忆时\n - 当用户要求「忘记关于我的一切」时\n - 当需要重置用户记忆状态时\n\n ## 返回数据结构\n\n 返回操作结果的文本描述\n\n ## 使用示例\n\n - \"清除你记住的所有关于我的信息\"\n - \"忘记关于我的一切\"\n - \"删除所有记忆\"\n\n Returns:\n 操作结果的描述字符串\n "
79+
}
80+
]
81+
}

0 commit comments

Comments
 (0)