Commit ad40eb5
feat(memory):support self-host mem0 (#403)
This pull request improves support for both platform and self-hosted
Mem0 deployments in the long-term memory extension, making the API more
flexible and robust. The main changes include allowing users to specify
the Mem0 API type, updating endpoint handling in the client, and
enhancing search request capabilities.
**Mem0 API deployment flexibility and configuration:**
* The `Mem0LongTermMemory` builder and `Mem0Client` now accept an
`apiType` parameter, allowing users to specify `"platform"` (default) or
`"self-hosted"` deployments. Endpoints are selected accordingly, and
example code and documentation have been updated to reflect this.
[[1]](diffhunk://#diff-9cba458daeb3e8cf4c31784a4959c2943eea0a8a6a93a4de1fbe4f5eb140d7dbR68-R75)
[[2]](diffhunk://#diff-9cba458daeb3e8cf4c31784a4959c2943eea0a8a6a93a4de1fbe4f5eb140d7dbL100-R113)
[[3]](diffhunk://#diff-9cba458daeb3e8cf4c31784a4959c2943eea0a8a6a93a4de1fbe4f5eb140d7dbR260)
[[4]](diffhunk://#diff-9cba458daeb3e8cf4c31784a4959c2943eea0a8a6a93a4de1fbe4f5eb140d7dbR330-R341)
[[5]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aR33-R64)
[[6]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aL57-R95)
[[7]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aR110-R122)
[[8]](diffhunk://#diff-6b9103fbf3a240744117a2bf207e08f728ae356b07f26db47787eb2283beac2dL61-R64)
[[9]](diffhunk://#diff-4952aadfeff4e923a4f33c8f2e1f54fea0e151561103f782103707a676572d7eR34-R48)
[[10]](diffhunk://#diff-4952aadfeff4e923a4f33c8f2e1f54fea0e151561103f782103707a676572d7eR85-R93)
* The `Mem0Client` class now chooses the correct API endpoints for
memory add/search operations based on the `apiType`, supporting both
platform and self-hosted Mem0.
[[1]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aR33-R64)
[[2]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aL57-R95)
[[3]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aR110-R122)
[[4]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aL180-R230)
[[5]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aL203-R265)
**Robustness and compatibility improvements:**
* The `Mem0Client` search method now handles differences in response
format between platform and self-hosted Mem0. It parses results
accordingly to ensure compatibility.
[[1]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aL203-R265)
[[2]](diffhunk://#diff-8332bcfd89ba54150c52b48221dbd3f8f7c80198636a0a7ceeb5eb3e22e19e1aL221-R280)
* The `Mem0AddResponse` and `Mem0SearchResponse` classes now ignore
unknown JSON properties, increasing forward compatibility with future
API changes.
[[1]](diffhunk://#diff-e16424679ccb9aebbb4a66a2e19f617646a43edccabb49c31792aedd27f03e9cR18)
[[2]](diffhunk://#diff-e16424679ccb9aebbb4a66a2e19f617646a43edccabb49c31792aedd27f03e9cR35)
[[3]](diffhunk://#diff-3f16da56a4e77b05005e143f0c9319a486682653e632ae8e4522074d73666545R18)
[[4]](diffhunk://#diff-3f16da56a4e77b05005e143f0c9319a486682653e632ae8e4522074d73666545R32)
**Search request enhancements:**
* The `Mem0SearchRequest` class and its builder now support a `userId`
field, which is automatically added to filters for compatibility with
the v2 API.
[[1]](diffhunk://#diff-569eccfea80f2361d61a7b14915a655674edc419751dbb2cc6826baa575e93e1R81-R84)
[[2]](diffhunk://#diff-569eccfea80f2361d61a7b14915a655674edc419751dbb2cc6826baa575e93e1R182-R193)
[[3]](diffhunk://#diff-569eccfea80f2361d61a7b14915a655674edc419751dbb2cc6826baa575e93e1R216)
[[4]](diffhunk://#diff-569eccfea80f2361d61a7b14915a655674edc419751dbb2cc6826baa575e93e1L230-R255)
[[5]](diffhunk://#diff-569eccfea80f2361d61a7b14915a655674edc419751dbb2cc6826baa575e93e1R354-R357)
These changes make the Mem0 extension more flexible, easier to configure
for different deployment scenarios, and more robust to API
changes.Change-Id: If8c877e63f8d225d9e88e3830380ec855e7c9fd2
Co-developed-by: Aone Copilot <noreply@alibaba-inc.com>
## AgentScope-Java Version
[The version of AgentScope-Java you are working on, e.g. 1.0.4, check
your pom.xml dependency version or run `mvn dependency:tree | grep
agentscope-parent:pom`(only mac/linux)]
## Description
[Please describe the background, purpose, changes made, and how to test
this PR]
## Checklist
Please check the following items before code is ready to be reviewed.
- [ ] Code has been formatted with `mvn spotless:apply`
- [ ] All tests are passing (`mvn test`)
- [ ] Javadoc comments are complete and follow project conventions
- [ ] Related documentation has been updated (e.g. links, examples,
etc.)
- [ ] Code is ready for review
---------
Co-authored-by: Albumen Kevin <jhq0812@gmail.com>1 parent 32b2455 commit ad40eb5
12 files changed
Lines changed: 590 additions & 36 deletions
File tree
- agentscope-examples/advanced/src/main/java/io/agentscope/examples/advanced
- agentscope-extensions/agentscope-extensions-mem0/src
- main/java/io/agentscope/core/memory/mem0
- test/java/io/agentscope/core/memory/mem0
- docs
- en/task
- zh/task
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
| 82 | + | |
81 | 83 | | |
82 | 84 | | |
83 | 85 | | |
84 | 86 | | |
85 | | - | |
| 87 | + | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| |||
Lines changed: 19 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | | - | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
39 | 41 | | |
40 | 42 | | |
41 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| |||
75 | 79 | | |
76 | 80 | | |
77 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
78 | 95 | | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
18 | 19 | | |
19 | 20 | | |
20 | 21 | | |
| |||
31 | 32 | | |
32 | 33 | | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
Lines changed: 50 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
Lines changed: 82 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
33 | 42 | | |
34 | 43 | | |
35 | 44 | | |
36 | 45 | | |
37 | | - | |
38 | | - | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
39 | 54 | | |
40 | 55 | | |
41 | 56 | | |
42 | 57 | | |
43 | 58 | | |
| 59 | + | |
| 60 | + | |
44 | 61 | | |
45 | 62 | | |
46 | | - | |
| 63 | + | |
47 | 64 | | |
48 | 65 | | |
49 | 66 | | |
| |||
54 | 71 | | |
55 | 72 | | |
56 | 73 | | |
57 | | - | |
| 74 | + | |
58 | 75 | | |
59 | 76 | | |
60 | 77 | | |
61 | 78 | | |
62 | 79 | | |
63 | 80 | | |
64 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
65 | 95 | | |
66 | 96 | | |
67 | 97 | | |
| |||
76 | 106 | | |
77 | 107 | | |
78 | 108 | | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
79 | 122 | | |
80 | 123 | | |
81 | 124 | | |
| |||
129 | 172 | | |
130 | 173 | | |
131 | 174 | | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
132 | 181 | | |
133 | 182 | | |
134 | 183 | | |
| |||
177 | 226 | | |
178 | 227 | | |
179 | 228 | | |
180 | | - | |
| 229 | + | |
181 | 230 | | |
182 | 231 | | |
183 | 232 | | |
| |||
200 | 249 | | |
201 | 250 | | |
202 | 251 | | |
203 | | - | |
| 252 | + | |
204 | 253 | | |
205 | 254 | | |
206 | 255 | | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
218 | | - | |
219 | | - | |
220 | | - | |
221 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
222 | 283 | | |
223 | 284 | | |
224 | 285 | | |
| |||
Lines changed: 22 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
68 | 76 | | |
69 | 77 | | |
70 | 78 | | |
| |||
97 | 105 | | |
98 | 106 | | |
99 | 107 | | |
100 | | - | |
| 108 | + | |
| 109 | + | |
101 | 110 | | |
102 | 111 | | |
103 | 112 | | |
| |||
244 | 253 | | |
245 | 254 | | |
246 | 255 | | |
| 256 | + | |
247 | 257 | | |
248 | 258 | | |
249 | 259 | | |
| |||
313 | 323 | | |
314 | 324 | | |
315 | 325 | | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
316 | 337 | | |
317 | 338 | | |
318 | 339 | | |
| |||
0 commit comments