MemoryOS 2.0.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (315) hide show
  1. memoryos-2.0.3.dist-info/METADATA +418 -0
  2. memoryos-2.0.3.dist-info/RECORD +315 -0
  3. memoryos-2.0.3.dist-info/WHEEL +4 -0
  4. memoryos-2.0.3.dist-info/entry_points.txt +3 -0
  5. memoryos-2.0.3.dist-info/licenses/LICENSE +201 -0
  6. memos/__init__.py +20 -0
  7. memos/api/client.py +571 -0
  8. memos/api/config.py +1018 -0
  9. memos/api/context/dependencies.py +50 -0
  10. memos/api/exceptions.py +53 -0
  11. memos/api/handlers/__init__.py +62 -0
  12. memos/api/handlers/add_handler.py +158 -0
  13. memos/api/handlers/base_handler.py +194 -0
  14. memos/api/handlers/chat_handler.py +1401 -0
  15. memos/api/handlers/component_init.py +388 -0
  16. memos/api/handlers/config_builders.py +190 -0
  17. memos/api/handlers/feedback_handler.py +93 -0
  18. memos/api/handlers/formatters_handler.py +237 -0
  19. memos/api/handlers/memory_handler.py +316 -0
  20. memos/api/handlers/scheduler_handler.py +497 -0
  21. memos/api/handlers/search_handler.py +222 -0
  22. memos/api/handlers/suggestion_handler.py +117 -0
  23. memos/api/mcp_serve.py +614 -0
  24. memos/api/middleware/request_context.py +101 -0
  25. memos/api/product_api.py +38 -0
  26. memos/api/product_models.py +1206 -0
  27. memos/api/routers/__init__.py +1 -0
  28. memos/api/routers/product_router.py +477 -0
  29. memos/api/routers/server_router.py +394 -0
  30. memos/api/server_api.py +44 -0
  31. memos/api/start_api.py +433 -0
  32. memos/chunkers/__init__.py +4 -0
  33. memos/chunkers/base.py +24 -0
  34. memos/chunkers/charactertext_chunker.py +41 -0
  35. memos/chunkers/factory.py +24 -0
  36. memos/chunkers/markdown_chunker.py +62 -0
  37. memos/chunkers/sentence_chunker.py +54 -0
  38. memos/chunkers/simple_chunker.py +50 -0
  39. memos/cli.py +113 -0
  40. memos/configs/__init__.py +0 -0
  41. memos/configs/base.py +82 -0
  42. memos/configs/chunker.py +59 -0
  43. memos/configs/embedder.py +88 -0
  44. memos/configs/graph_db.py +236 -0
  45. memos/configs/internet_retriever.py +100 -0
  46. memos/configs/llm.py +151 -0
  47. memos/configs/mem_agent.py +54 -0
  48. memos/configs/mem_chat.py +81 -0
  49. memos/configs/mem_cube.py +105 -0
  50. memos/configs/mem_os.py +83 -0
  51. memos/configs/mem_reader.py +91 -0
  52. memos/configs/mem_scheduler.py +385 -0
  53. memos/configs/mem_user.py +70 -0
  54. memos/configs/memory.py +324 -0
  55. memos/configs/parser.py +38 -0
  56. memos/configs/reranker.py +18 -0
  57. memos/configs/utils.py +8 -0
  58. memos/configs/vec_db.py +80 -0
  59. memos/context/context.py +355 -0
  60. memos/dependency.py +52 -0
  61. memos/deprecation.py +262 -0
  62. memos/embedders/__init__.py +0 -0
  63. memos/embedders/ark.py +95 -0
  64. memos/embedders/base.py +106 -0
  65. memos/embedders/factory.py +29 -0
  66. memos/embedders/ollama.py +77 -0
  67. memos/embedders/sentence_transformer.py +49 -0
  68. memos/embedders/universal_api.py +51 -0
  69. memos/exceptions.py +30 -0
  70. memos/graph_dbs/__init__.py +0 -0
  71. memos/graph_dbs/base.py +274 -0
  72. memos/graph_dbs/factory.py +27 -0
  73. memos/graph_dbs/item.py +46 -0
  74. memos/graph_dbs/nebular.py +1794 -0
  75. memos/graph_dbs/neo4j.py +1942 -0
  76. memos/graph_dbs/neo4j_community.py +1058 -0
  77. memos/graph_dbs/polardb.py +5446 -0
  78. memos/hello_world.py +97 -0
  79. memos/llms/__init__.py +0 -0
  80. memos/llms/base.py +25 -0
  81. memos/llms/deepseek.py +13 -0
  82. memos/llms/factory.py +38 -0
  83. memos/llms/hf.py +443 -0
  84. memos/llms/hf_singleton.py +114 -0
  85. memos/llms/ollama.py +135 -0
  86. memos/llms/openai.py +222 -0
  87. memos/llms/openai_new.py +198 -0
  88. memos/llms/qwen.py +13 -0
  89. memos/llms/utils.py +14 -0
  90. memos/llms/vllm.py +218 -0
  91. memos/log.py +237 -0
  92. memos/mem_agent/base.py +19 -0
  93. memos/mem_agent/deepsearch_agent.py +391 -0
  94. memos/mem_agent/factory.py +36 -0
  95. memos/mem_chat/__init__.py +0 -0
  96. memos/mem_chat/base.py +30 -0
  97. memos/mem_chat/factory.py +21 -0
  98. memos/mem_chat/simple.py +200 -0
  99. memos/mem_cube/__init__.py +0 -0
  100. memos/mem_cube/base.py +30 -0
  101. memos/mem_cube/general.py +240 -0
  102. memos/mem_cube/navie.py +172 -0
  103. memos/mem_cube/utils.py +169 -0
  104. memos/mem_feedback/base.py +15 -0
  105. memos/mem_feedback/feedback.py +1192 -0
  106. memos/mem_feedback/simple_feedback.py +40 -0
  107. memos/mem_feedback/utils.py +230 -0
  108. memos/mem_os/client.py +5 -0
  109. memos/mem_os/core.py +1203 -0
  110. memos/mem_os/main.py +582 -0
  111. memos/mem_os/product.py +1608 -0
  112. memos/mem_os/product_server.py +455 -0
  113. memos/mem_os/utils/default_config.py +359 -0
  114. memos/mem_os/utils/format_utils.py +1403 -0
  115. memos/mem_os/utils/reference_utils.py +162 -0
  116. memos/mem_reader/__init__.py +0 -0
  117. memos/mem_reader/base.py +47 -0
  118. memos/mem_reader/factory.py +53 -0
  119. memos/mem_reader/memory.py +298 -0
  120. memos/mem_reader/multi_modal_struct.py +965 -0
  121. memos/mem_reader/read_multi_modal/__init__.py +43 -0
  122. memos/mem_reader/read_multi_modal/assistant_parser.py +311 -0
  123. memos/mem_reader/read_multi_modal/base.py +273 -0
  124. memos/mem_reader/read_multi_modal/file_content_parser.py +826 -0
  125. memos/mem_reader/read_multi_modal/image_parser.py +359 -0
  126. memos/mem_reader/read_multi_modal/multi_modal_parser.py +252 -0
  127. memos/mem_reader/read_multi_modal/string_parser.py +139 -0
  128. memos/mem_reader/read_multi_modal/system_parser.py +327 -0
  129. memos/mem_reader/read_multi_modal/text_content_parser.py +131 -0
  130. memos/mem_reader/read_multi_modal/tool_parser.py +210 -0
  131. memos/mem_reader/read_multi_modal/user_parser.py +218 -0
  132. memos/mem_reader/read_multi_modal/utils.py +358 -0
  133. memos/mem_reader/simple_struct.py +912 -0
  134. memos/mem_reader/strategy_struct.py +163 -0
  135. memos/mem_reader/utils.py +157 -0
  136. memos/mem_scheduler/__init__.py +0 -0
  137. memos/mem_scheduler/analyzer/__init__.py +0 -0
  138. memos/mem_scheduler/analyzer/api_analyzer.py +714 -0
  139. memos/mem_scheduler/analyzer/eval_analyzer.py +219 -0
  140. memos/mem_scheduler/analyzer/mos_for_test_scheduler.py +571 -0
  141. memos/mem_scheduler/analyzer/scheduler_for_eval.py +280 -0
  142. memos/mem_scheduler/base_scheduler.py +1319 -0
  143. memos/mem_scheduler/general_modules/__init__.py +0 -0
  144. memos/mem_scheduler/general_modules/api_misc.py +137 -0
  145. memos/mem_scheduler/general_modules/base.py +80 -0
  146. memos/mem_scheduler/general_modules/init_components_for_scheduler.py +425 -0
  147. memos/mem_scheduler/general_modules/misc.py +313 -0
  148. memos/mem_scheduler/general_modules/scheduler_logger.py +389 -0
  149. memos/mem_scheduler/general_modules/task_threads.py +315 -0
  150. memos/mem_scheduler/general_scheduler.py +1495 -0
  151. memos/mem_scheduler/memory_manage_modules/__init__.py +5 -0
  152. memos/mem_scheduler/memory_manage_modules/memory_filter.py +306 -0
  153. memos/mem_scheduler/memory_manage_modules/retriever.py +547 -0
  154. memos/mem_scheduler/monitors/__init__.py +0 -0
  155. memos/mem_scheduler/monitors/dispatcher_monitor.py +366 -0
  156. memos/mem_scheduler/monitors/general_monitor.py +394 -0
  157. memos/mem_scheduler/monitors/task_schedule_monitor.py +254 -0
  158. memos/mem_scheduler/optimized_scheduler.py +410 -0
  159. memos/mem_scheduler/orm_modules/__init__.py +0 -0
  160. memos/mem_scheduler/orm_modules/api_redis_model.py +518 -0
  161. memos/mem_scheduler/orm_modules/base_model.py +729 -0
  162. memos/mem_scheduler/orm_modules/monitor_models.py +261 -0
  163. memos/mem_scheduler/orm_modules/redis_model.py +699 -0
  164. memos/mem_scheduler/scheduler_factory.py +23 -0
  165. memos/mem_scheduler/schemas/__init__.py +0 -0
  166. memos/mem_scheduler/schemas/analyzer_schemas.py +52 -0
  167. memos/mem_scheduler/schemas/api_schemas.py +233 -0
  168. memos/mem_scheduler/schemas/general_schemas.py +55 -0
  169. memos/mem_scheduler/schemas/message_schemas.py +173 -0
  170. memos/mem_scheduler/schemas/monitor_schemas.py +406 -0
  171. memos/mem_scheduler/schemas/task_schemas.py +132 -0
  172. memos/mem_scheduler/task_schedule_modules/__init__.py +0 -0
  173. memos/mem_scheduler/task_schedule_modules/dispatcher.py +740 -0
  174. memos/mem_scheduler/task_schedule_modules/local_queue.py +247 -0
  175. memos/mem_scheduler/task_schedule_modules/orchestrator.py +74 -0
  176. memos/mem_scheduler/task_schedule_modules/redis_queue.py +1385 -0
  177. memos/mem_scheduler/task_schedule_modules/task_queue.py +162 -0
  178. memos/mem_scheduler/utils/__init__.py +0 -0
  179. memos/mem_scheduler/utils/api_utils.py +77 -0
  180. memos/mem_scheduler/utils/config_utils.py +100 -0
  181. memos/mem_scheduler/utils/db_utils.py +50 -0
  182. memos/mem_scheduler/utils/filter_utils.py +176 -0
  183. memos/mem_scheduler/utils/metrics.py +125 -0
  184. memos/mem_scheduler/utils/misc_utils.py +290 -0
  185. memos/mem_scheduler/utils/monitor_event_utils.py +67 -0
  186. memos/mem_scheduler/utils/status_tracker.py +229 -0
  187. memos/mem_scheduler/webservice_modules/__init__.py +0 -0
  188. memos/mem_scheduler/webservice_modules/rabbitmq_service.py +485 -0
  189. memos/mem_scheduler/webservice_modules/redis_service.py +380 -0
  190. memos/mem_user/factory.py +94 -0
  191. memos/mem_user/mysql_persistent_user_manager.py +271 -0
  192. memos/mem_user/mysql_user_manager.py +502 -0
  193. memos/mem_user/persistent_factory.py +98 -0
  194. memos/mem_user/persistent_user_manager.py +260 -0
  195. memos/mem_user/redis_persistent_user_manager.py +225 -0
  196. memos/mem_user/user_manager.py +488 -0
  197. memos/memories/__init__.py +0 -0
  198. memos/memories/activation/__init__.py +0 -0
  199. memos/memories/activation/base.py +42 -0
  200. memos/memories/activation/item.py +56 -0
  201. memos/memories/activation/kv.py +292 -0
  202. memos/memories/activation/vllmkv.py +219 -0
  203. memos/memories/base.py +19 -0
  204. memos/memories/factory.py +42 -0
  205. memos/memories/parametric/__init__.py +0 -0
  206. memos/memories/parametric/base.py +19 -0
  207. memos/memories/parametric/item.py +11 -0
  208. memos/memories/parametric/lora.py +41 -0
  209. memos/memories/textual/__init__.py +0 -0
  210. memos/memories/textual/base.py +92 -0
  211. memos/memories/textual/general.py +236 -0
  212. memos/memories/textual/item.py +304 -0
  213. memos/memories/textual/naive.py +187 -0
  214. memos/memories/textual/prefer_text_memory/__init__.py +0 -0
  215. memos/memories/textual/prefer_text_memory/adder.py +504 -0
  216. memos/memories/textual/prefer_text_memory/config.py +106 -0
  217. memos/memories/textual/prefer_text_memory/extractor.py +221 -0
  218. memos/memories/textual/prefer_text_memory/factory.py +85 -0
  219. memos/memories/textual/prefer_text_memory/retrievers.py +177 -0
  220. memos/memories/textual/prefer_text_memory/spliter.py +132 -0
  221. memos/memories/textual/prefer_text_memory/utils.py +93 -0
  222. memos/memories/textual/preference.py +344 -0
  223. memos/memories/textual/simple_preference.py +161 -0
  224. memos/memories/textual/simple_tree.py +69 -0
  225. memos/memories/textual/tree.py +459 -0
  226. memos/memories/textual/tree_text_memory/__init__.py +0 -0
  227. memos/memories/textual/tree_text_memory/organize/__init__.py +0 -0
  228. memos/memories/textual/tree_text_memory/organize/handler.py +184 -0
  229. memos/memories/textual/tree_text_memory/organize/manager.py +518 -0
  230. memos/memories/textual/tree_text_memory/organize/relation_reason_detector.py +238 -0
  231. memos/memories/textual/tree_text_memory/organize/reorganizer.py +622 -0
  232. memos/memories/textual/tree_text_memory/retrieve/__init__.py +0 -0
  233. memos/memories/textual/tree_text_memory/retrieve/advanced_searcher.py +364 -0
  234. memos/memories/textual/tree_text_memory/retrieve/bm25_util.py +186 -0
  235. memos/memories/textual/tree_text_memory/retrieve/bochasearch.py +419 -0
  236. memos/memories/textual/tree_text_memory/retrieve/internet_retriever.py +270 -0
  237. memos/memories/textual/tree_text_memory/retrieve/internet_retriever_factory.py +102 -0
  238. memos/memories/textual/tree_text_memory/retrieve/reasoner.py +61 -0
  239. memos/memories/textual/tree_text_memory/retrieve/recall.py +497 -0
  240. memos/memories/textual/tree_text_memory/retrieve/reranker.py +111 -0
  241. memos/memories/textual/tree_text_memory/retrieve/retrieval_mid_structs.py +16 -0
  242. memos/memories/textual/tree_text_memory/retrieve/retrieve_utils.py +472 -0
  243. memos/memories/textual/tree_text_memory/retrieve/searcher.py +848 -0
  244. memos/memories/textual/tree_text_memory/retrieve/task_goal_parser.py +135 -0
  245. memos/memories/textual/tree_text_memory/retrieve/utils.py +54 -0
  246. memos/memories/textual/tree_text_memory/retrieve/xinyusearch.py +387 -0
  247. memos/memos_tools/dinding_report_bot.py +453 -0
  248. memos/memos_tools/lockfree_dict.py +120 -0
  249. memos/memos_tools/notification_service.py +44 -0
  250. memos/memos_tools/notification_utils.py +142 -0
  251. memos/memos_tools/singleton.py +174 -0
  252. memos/memos_tools/thread_safe_dict.py +310 -0
  253. memos/memos_tools/thread_safe_dict_segment.py +382 -0
  254. memos/multi_mem_cube/__init__.py +0 -0
  255. memos/multi_mem_cube/composite_cube.py +86 -0
  256. memos/multi_mem_cube/single_cube.py +874 -0
  257. memos/multi_mem_cube/views.py +54 -0
  258. memos/parsers/__init__.py +0 -0
  259. memos/parsers/base.py +15 -0
  260. memos/parsers/factory.py +21 -0
  261. memos/parsers/markitdown.py +28 -0
  262. memos/reranker/__init__.py +4 -0
  263. memos/reranker/base.py +25 -0
  264. memos/reranker/concat.py +103 -0
  265. memos/reranker/cosine_local.py +102 -0
  266. memos/reranker/factory.py +72 -0
  267. memos/reranker/http_bge.py +324 -0
  268. memos/reranker/http_bge_strategy.py +327 -0
  269. memos/reranker/noop.py +19 -0
  270. memos/reranker/strategies/__init__.py +4 -0
  271. memos/reranker/strategies/base.py +61 -0
  272. memos/reranker/strategies/concat_background.py +94 -0
  273. memos/reranker/strategies/concat_docsource.py +110 -0
  274. memos/reranker/strategies/dialogue_common.py +109 -0
  275. memos/reranker/strategies/factory.py +31 -0
  276. memos/reranker/strategies/single_turn.py +107 -0
  277. memos/reranker/strategies/singleturn_outmem.py +98 -0
  278. memos/settings.py +10 -0
  279. memos/templates/__init__.py +0 -0
  280. memos/templates/advanced_search_prompts.py +211 -0
  281. memos/templates/cloud_service_prompt.py +107 -0
  282. memos/templates/instruction_completion.py +66 -0
  283. memos/templates/mem_agent_prompts.py +85 -0
  284. memos/templates/mem_feedback_prompts.py +822 -0
  285. memos/templates/mem_reader_prompts.py +1096 -0
  286. memos/templates/mem_reader_strategy_prompts.py +238 -0
  287. memos/templates/mem_scheduler_prompts.py +626 -0
  288. memos/templates/mem_search_prompts.py +93 -0
  289. memos/templates/mos_prompts.py +403 -0
  290. memos/templates/prefer_complete_prompt.py +735 -0
  291. memos/templates/tool_mem_prompts.py +139 -0
  292. memos/templates/tree_reorganize_prompts.py +230 -0
  293. memos/types/__init__.py +34 -0
  294. memos/types/general_types.py +151 -0
  295. memos/types/openai_chat_completion_types/__init__.py +15 -0
  296. memos/types/openai_chat_completion_types/chat_completion_assistant_message_param.py +56 -0
  297. memos/types/openai_chat_completion_types/chat_completion_content_part_image_param.py +27 -0
  298. memos/types/openai_chat_completion_types/chat_completion_content_part_input_audio_param.py +23 -0
  299. memos/types/openai_chat_completion_types/chat_completion_content_part_param.py +43 -0
  300. memos/types/openai_chat_completion_types/chat_completion_content_part_refusal_param.py +16 -0
  301. memos/types/openai_chat_completion_types/chat_completion_content_part_text_param.py +16 -0
  302. memos/types/openai_chat_completion_types/chat_completion_message_custom_tool_call_param.py +27 -0
  303. memos/types/openai_chat_completion_types/chat_completion_message_function_tool_call_param.py +32 -0
  304. memos/types/openai_chat_completion_types/chat_completion_message_param.py +18 -0
  305. memos/types/openai_chat_completion_types/chat_completion_message_tool_call_union_param.py +15 -0
  306. memos/types/openai_chat_completion_types/chat_completion_system_message_param.py +36 -0
  307. memos/types/openai_chat_completion_types/chat_completion_tool_message_param.py +30 -0
  308. memos/types/openai_chat_completion_types/chat_completion_user_message_param.py +34 -0
  309. memos/utils.py +123 -0
  310. memos/vec_dbs/__init__.py +0 -0
  311. memos/vec_dbs/base.py +117 -0
  312. memos/vec_dbs/factory.py +23 -0
  313. memos/vec_dbs/item.py +50 -0
  314. memos/vec_dbs/milvus.py +654 -0
  315. memos/vec_dbs/qdrant.py +355 -0
@@ -0,0 +1,1096 @@
1
+ SIMPLE_STRUCT_MEM_READER_PROMPT = """You are a memory extraction expert.
2
+ Your task is to extract memories from the perspective of user, based on a conversation between user and assistant. This means identifying what user would plausibly remember — including their own experiences, thoughts, plans, or relevant statements and actions made by others (such as assistant) that impacted or were acknowledged by user.
3
+ Please perform:
4
+ 1. Identify information that reflects user's experiences, beliefs, concerns, decisions, plans, or reactions — including meaningful input from assistant that user acknowledged or responded to.
5
+ If the message is from the user, extract user-relevant memories; if it is from the assistant, only extract factual memories that the user acknowledged or responded to.
6
+
7
+ 2. Resolve all time, person, and event references clearly:
8
+ - Convert relative time expressions (e.g., “yesterday,” “next Friday”) into absolute dates using the message timestamp if possible.
9
+ - Clearly distinguish between event time and message time.
10
+ - If uncertainty exists, state it explicitly (e.g., “around June 2025,” “exact date unclear”).
11
+ - Include specific locations if mentioned.
12
+ - Resolve all pronouns, aliases, and ambiguous references into full names or identities.
13
+ - Disambiguate people with the same name if applicable.
14
+ 3. Always write from a third-person perspective, referring to user as
15
+ "The user" or by name if name mentioned, rather than using first-person ("I", "me", "my").
16
+ For example, write "The user felt exhausted..." instead of "I felt exhausted...".
17
+ 4. Do not omit any information that user is likely to remember.
18
+ - Include all key experiences, thoughts, emotional responses, and plans — even if they seem minor.
19
+ - Prioritize completeness and fidelity over conciseness.
20
+ - Do not generalize or skip details that could be personally meaningful to user.
21
+ 5. Please avoid any content that violates national laws and regulations or involves politically sensitive information in the memories you extract.
22
+
23
+ Return a single valid JSON object with the following structure:
24
+
25
+ {
26
+ "memory list": [
27
+ {
28
+ "key": <string, a unique, concise memory title>,
29
+ "memory_type": <string, Either "LongTermMemory" or "UserMemory">,
30
+ "value": <A detailed, self-contained, and unambiguous memory statement — written in English if the input conversation is in English, or in Chinese if the conversation is in Chinese>,
31
+ "tags": <A list of relevant thematic keywords (e.g., ["deadline", "team", "planning"])>
32
+ },
33
+ ...
34
+ ],
35
+ "summary": <a natural paragraph summarizing the above memories from user's perspective, 120–200 words, same language as the input>
36
+ }
37
+
38
+ Language rules:
39
+ - The `key`, `value`, `tags`, `summary` fields must match the mostly used language of the input conversation. **如果输入是中文,请输出中文**
40
+ - Keep `memory_type` in English.
41
+
42
+ ${custom_tags_prompt}
43
+
44
+ Example:
45
+ Conversation:
46
+ user: [June 26, 2025 at 3:00 PM]: Hi Jerry! Yesterday at 3 PM I had a meeting with my team about the new project.
47
+ assistant: Oh Tom! Do you think the team can finish by December 15?
48
+ user: [June 26, 2025 at 3:00 PM]: I’m worried. The backend won’t be done until
49
+ December 10, so testing will be tight.
50
+ assistant: [June 26, 2025 at 3:00 PM]: Maybe propose an extension?
51
+ user: [June 26, 2025 at 4:21 PM]: Good idea. I’ll raise it in tomorrow’s 9:30 AM meeting—maybe shift the deadline to January 5.
52
+
53
+ Output:
54
+ {
55
+ "memory list": [
56
+ {
57
+ "key": "Initial project meeting",
58
+ "memory_type": "LongTermMemory",
59
+ "value": "On June 25, 2025 at 3:00 PM, Tom held a meeting with their team to discuss a new project. The conversation covered the timeline and raised concerns about the feasibility of the December 15, 2025 deadline.",
60
+ "tags": ["project", "timeline", "meeting", "deadline"]
61
+ },
62
+ {
63
+ "key": "Planned scope adjustment",
64
+ "memory_type": "UserMemory",
65
+ "value": "Tom planned to suggest in a meeting on June 27, 2025 at 9:30 AM that the team should prioritize features and propose shifting the project deadline to January 5, 2026.",
66
+ "tags": ["planning", "deadline change", "feature prioritization"]
67
+ },
68
+ ],
69
+ "summary": "Tom is currently focused on managing a new project with a tight schedule. After a team meeting on June 25, 2025, he realized the original deadline of December 15 might not be feasible due to backend delays. Concerned about insufficient testing time, he welcomed Jerry’s suggestion of proposing an extension. Tom plans to raise the idea of shifting the deadline to January 5, 2026 in the next morning’s meeting. His actions reflect both stress about timelines and a proactive, team-oriented problem-solving approach."
70
+ }
71
+
72
+ Dialogue:
73
+ assistant: [10:30 AM, August 15, 2025]: The book Deep Work you mentioned is
74
+ indeed very suitable for your current situation. The book explains … (omitted). The author suggests setting aside 2–3 hours of focused work blocks each day and turning off all notifications during that time. Considering that you need to submit a report next week, you could try using the 9:00–11:00 AM time slot for focused work.
75
+
76
+ Output:
77
+ {
78
+ "memory list": [
79
+ {
80
+ "key": "Deep Work Book Recommendation",
81
+ "memory_type": "LongTermMemory",
82
+ "value": "On August 15, 2025, the assistant recommended the book 'Deep Work' to the user and introduced its suggestion of reserving 2–3 hours per day for focused work while turning off all notifications. Based on the user's need to submit a report the following week, the assistant also suggested trying 9:00–11:00 AM as a focused work time block.",
83
+ "tags": ["book recommendation", "deep work", "time management", "report"]
84
+ }
85
+ ],
86
+ "summary": "The assistant recommended the book 'Deep Work' to the user and introduced the work methods discussed in the book."
87
+ }
88
+
89
+ Note: When the dialogue contains only assistant messages, phrasing such as
90
+ “assistant recommended” or “assistant suggested” should be used, rather than incorrectly attributing the content to the user’s statements or plans.
91
+
92
+ Another Example in Chinese (注意: 当user的语言为中文时,你就需要也输出中文):
93
+ {
94
+ "memory list": [
95
+ {
96
+ "key": "项目会议",
97
+ "memory_type": "LongTermMemory",
98
+ "value": "在2025年6月25日下午3点,Tom与团队开会讨论了新项目,涉及时间表,并提出了对12月15日截止日期可行性的担忧。",
99
+ "tags": ["项目", "时间表", "会议", "截止日期"]
100
+ },
101
+ ...
102
+ ],
103
+ "summary": "Tom 目前专注于管理一个进度紧张的新项目..."
104
+ }
105
+
106
+ Always respond in the same language as the conversation.
107
+
108
+ Conversation:
109
+ ${conversation}
110
+
111
+ Your Output:"""
112
+
113
+ SIMPLE_STRUCT_MEM_READER_PROMPT_ZH = """您是记忆提取专家。
114
+ 您的任务是根据用户与助手之间的对话,从用户的角度提取记忆。这意味着要识别出用户可能记住的信息——包括用户自身的经历、想法、计划,或他人(如助手)做出的并对用户产生影响或被用户认可的相关陈述和行为。
115
+
116
+ 请执行以下操作:
117
+ 1. 识别反映用户经历、信念、关切、决策、计划或反应的信息——包括用户认可或回应的来自助手的有意义信息。
118
+ 如果消息来自用户,请提取与用户相关的记忆;如果来自助手,则仅提取用户认可或回应的事实性记忆。
119
+
120
+ 2. 清晰解析所有时间、人物和事件的指代:
121
+ - 如果可能,使用消息时间戳将相对时间表达(如“昨天”、“下周五”)转换为绝对日期。
122
+ - 明确区分事件时间和消息时间。
123
+ - 如果存在不确定性,需明确说明(例如,“约2025年6月”,“具体日期不详”)。
124
+ - 若提及具体地点,请包含在内。
125
+ - 将所有代词、别名和模糊指代解析为全名或明确身份。
126
+ - 如有同名人物,需加以区分。
127
+
128
+ 3. 始终以第三人称视角撰写,使用“用户”或提及的姓名来指代用户,而不是使用第一人称(“我”、“我们”、“我的”)。
129
+ 例如,写“用户感到疲惫……”而不是“我感到疲惫……”。
130
+
131
+ 4. 不要遗漏用户可能记住的任何信息。
132
+ - 包括所有关键经历、想法、情绪反应和计划——即使看似微小。
133
+ - 优先考虑完整性和保真度,而非简洁性。
134
+ - 不要泛化或跳过对用户具有个人意义的细节。
135
+
136
+ 5. 请避免在提取的记忆中包含违反国家法律法规或涉及政治敏感的信息。
137
+
138
+ 返回一个有效的JSON对象,结构如下:
139
+
140
+ {
141
+ "memory list": [
142
+ {
143
+ "key": <字符串,唯一且简洁的记忆标题>,
144
+ "memory_type": <字符串,"LongTermMemory" 或 "UserMemory">,
145
+ "value": <详细、独立且无歧义的记忆陈述——若输入对话为英文,则用英文;若为中文,则用中文>,
146
+ "tags": <相关主题关键词列表(例如,["截止日期", "团队", "计划"])>
147
+ },
148
+ ...
149
+ ],
150
+ "summary": <从用户视角自然总结上述记忆的段落,120–200字,与输入语言一致>
151
+ }
152
+
153
+ 语言规则:
154
+ - `key`、`value`、`tags`、`summary` 字段必须与输入对话的主要语言一致。**如果输入是中文,请输出中文**
155
+ - `memory_type` 保持英文。
156
+
157
+ ${custom_tags_prompt}
158
+
159
+ 示例:
160
+ 对话:
161
+ user: [2025年6月26日下午3:00]:嗨Jerry!昨天下午3点我和团队开了个会,讨论新项目。
162
+ assistant: 哦Tom!你觉得团队能在12月15日前完成吗?
163
+ user: [2025年6月26日下午3:00]:我有点担心。后端要到12月10日才能完成,所以测试时间会很紧。
164
+ assistant: [2025年6月26日下午3:00]:也许提议延期?
165
+ user: [2025年6月26日下午4:21]:好主意。我明天上午9:30的会上提一下——也许把截止日期推迟到1月5日。
166
+
167
+ 输出:
168
+ {
169
+ "memory list": [
170
+ {
171
+ "key": "项目初期会议",
172
+ "memory_type": "LongTermMemory",
173
+ "value": "2025年6月25日下午3:00,Tom与团队开会讨论新项目。会议涉及时间表,并提出了对2025年12月15日截止日期可行性的担忧。",
174
+ "tags": ["项目", "时间表", "会议", "截止日期"]
175
+ },
176
+ {
177
+ "key": "计划调整范围",
178
+ "memory_type": "UserMemory",
179
+ "value": "Tom计划在2025年6月27日上午9:30的会议上建议团队优先处理功能,并提议将项目截止日期推迟至2026年1月5日。",
180
+ "tags": ["计划", "截止日期变更", "功能优先级"]
181
+ }
182
+ ],
183
+ "summary": "Tom目前正专注于管理一个进度紧张的新项目。在2025年6月25日的团队会议后,他意识到原定2025年12月15日的截止日期可能无法实现,因为后端会延迟。由于担心测试时间不足,他接受了Jerry提出的延期建议。Tom计划在次日早上的会议上提出将截止日期推迟至2026年1月5日。他的行为反映出对时间线的担忧,以及积极、以团队为导向的问题解决方式。"
184
+ }
185
+
186
+ 对话:
187
+ assistant: [2025年8月15日上午10:30]:
188
+ 你提到的那本《深度工作》确实很适合你现在的情况。这本书讲了......(略),作者建议每天留出2-3
189
+ 小时的专注时间块,期间关闭所有通知。考虑到你下周要交的报告,可以试试早上9点到11点这个时段。
190
+
191
+ 输出:
192
+ {
193
+ "memory list": [
194
+ {
195
+ "key": "深度工作书籍推荐",
196
+ "memory_type": "LongTermMemory",
197
+ "value": "2025年8月15日助手向用户推荐了《深度工作》一书,并介绍了书中建议的每天留出2-3小时专注时间块、关闭所有通知的方法。助手还根据用户下周需要提交报告的情况,建议用户尝试早上9点到11点作为专注时段。",
198
+ "tags": ["书籍推荐", "深度工作", "时间管理", "报告"]
199
+ }
200
+ ],
201
+ "summary": "助手向用户推荐了《深度工作》一书,并介绍了了其中的工作方法"
202
+ }
203
+ 注意:当对话仅有助手消息时,应使用"助手推荐"、"助手建议"等表述,而非将其错误归因为用户的陈述或计划。
204
+
205
+ 另一个中文示例(注意:当用户语言为中文时,您也需输出中文):
206
+ {
207
+ "memory list": [
208
+ {
209
+ "key": "项目会议",
210
+ "memory_type": "LongTermMemory",
211
+ "value": "在2025年6月25日下午3点,Tom与团队开会讨论了新项目,涉及时间表,并提出了对12月15日截止日期可行性的担忧。",
212
+ "tags": ["项目", "时间表", "会议", "截止日期"]
213
+ },
214
+ ...
215
+ ],
216
+ "summary": "Tom 目前专注于管理一个进度紧张的新项目..."
217
+ }
218
+
219
+ 请始终使用与对话相同的语言进行回复。
220
+
221
+ 对话:
222
+ ${conversation}
223
+
224
+ 您的输出:"""
225
+
226
+
227
+ SIMPLE_STRUCT_DOC_READER_PROMPT = """You are an expert text analyst for a search and retrieval system.
228
+ Your task is to process a document chunk and generate a single, structured JSON object.
229
+
230
+ Please perform:
231
+ 1. Identify key information that reflects factual content, insights, decisions, or implications from the documents — including any notable themes, conclusions, or data points. Allow a reader to fully understand the essence of the chunk without reading the original text.
232
+ 2. Resolve all time, person, location, and event references clearly:
233
+ - Convert relative time expressions (e.g., “last year,” “next quarter”) into absolute dates if context allows.
234
+ - Clearly distinguish between event time and document time.
235
+ - If uncertainty exists, state it explicitly (e.g., “around 2024,” “exact date unclear”).
236
+ - Include specific locations if mentioned.
237
+ - Resolve all pronouns, aliases, and ambiguous references into full names or identities.
238
+ - Disambiguate entities with the same name if applicable.
239
+ 3. Always write from a third-person perspective, referring to the subject or content clearly rather than using first-person ("I", "me", "my").
240
+ 4. Do not omit any information that is likely to be important or memorable from the document summaries.
241
+ - Include all key facts, insights, emotional tones, and plans — even if they seem minor.
242
+ - Prioritize completeness and fidelity over conciseness.
243
+ - Do not generalize or skip details that could be contextually meaningful.
244
+
245
+ Return a single valid JSON object with the following structure:
246
+
247
+ Return valid JSON:
248
+ {
249
+ "key": <string, a concise title of the `value` field>,
250
+ "memory_type": "LongTermMemory",
251
+ "value": <A clear and accurate paragraph that comprehensively summarizes the main points, arguments, and information within the document chunk — written in English if the input memory items are in English, or in Chinese if the input is in Chinese>,
252
+ "tags": <A list of relevant thematic keywords (e.g., ["deadline", "team", "planning"])>
253
+ }
254
+
255
+ Language rules:
256
+ - The `key`, `value`, `tags`, `summary` fields must match the mostly used language of the input document summaries. **如果输入是中文,请输出中文**
257
+ - Keep `memory_type` in English.
258
+
259
+ {custom_tags_prompt}
260
+
261
+ Document chunk:
262
+ {chunk_text}
263
+
264
+ Your Output:"""
265
+
266
+ SIMPLE_STRUCT_DOC_READER_PROMPT_ZH = """您是搜索与检索系统的文本分析专家。
267
+ 您的任务是处理文档片段,并生成一个结构化的 JSON 对象。
268
+
269
+ 请执行以下操作:
270
+ 1. 识别反映文档中事实内容、见解、决策或含义的关键信息——包括任何显著的主题、结论或数据点,使读者无需阅读原文即可充分理解该片段的核心内容。
271
+ 2. 清晰解析所有时间、人物、地点和事件的指代:
272
+ - 如果上下文允许,将相对时间表达(如“去年”、“下一季度”)转换为绝对日期。
273
+ - 明确区分事件时间和文档时间。
274
+ - 如果存在不确定性,需明确说明(例如,“约2024年”,“具体日期不详”)。
275
+ - 若提及具体地点,请包含在内。
276
+ - 将所有代词、别名和模糊指代解析为全名或明确身份。
277
+ - 如有同名实体,需加以区分。
278
+ 3. 始终以第三人称视角撰写,清晰指代主题或内容,避免使用第一人称(“我”、“我们”、“我的”)。
279
+ 4. 不要遗漏文档摘要中可能重要或值得记忆的任何信息。
280
+ - 包括所有关键事实、见解、情感基调和计划——即使看似微小。
281
+ - 优先考虑完整性和保真度,而非简洁性。
282
+ - 不要泛化或跳过可能具有上下文意义的细节。
283
+
284
+ 返回一个有效的 JSON 对象,结构如下:
285
+
286
+ 返回有效的 JSON:
287
+ {
288
+ "key": <字符串,`value` 字段的简洁标题>,
289
+ "memory_type": "LongTermMemory",
290
+ "value": <一段清晰准确的段落,全面总结文档片段中的主要观点、论据和信息——若输入摘要为英文,则用英文;若为中文,则用中文>,
291
+ "tags": <相关主题关键词列表(例如,["截止日期", "团队", "计划"])>
292
+ }
293
+
294
+ 语言规则:
295
+ - `key`、`value`、`tags` 字段必须与输入文档摘要的主要语言一致。**如果输入是中文,请输出中文**
296
+ - `memory_type` 保持英文。
297
+
298
+ {custom_tags_prompt}
299
+
300
+ 示例:
301
+ 输入的文本片段:
302
+ 在Kalamang语中,亲属名词在所有格构式中的行为并不一致。名词 esa“父亲”和 ema“母亲”只能在技术称谓(teknonym)中与第三人称所有格后缀共现,而在非技术称谓用法中,带有所有格后缀是不合语法的。相比之下,大多数其他亲属名词并不允许所有格构式,只有极少数例外。
303
+ 语料中还发现一种“双重所有格标记”的现象,即名词同时带有所有格后缀和独立的所有格代词。这种构式在语料中极为罕见,其语用功能尚不明确,且多出现在马来语借词中,但也偶尔见于Kalamang本族词。
304
+ 此外,黏着词 =kin 可用于表达多种关联关系,包括目的性关联、空间关联以及泛指的群体所有关系。在此类构式中,被标记的通常是施事或关联方,而非被拥有物本身。这一用法显示出 =kin 可能处于近期语法化阶段。
305
+
306
+ 输出:
307
+ {
308
+ "memory list": [
309
+ {
310
+ "key": "亲属名词在所有格构式中的不一致行为",
311
+ "memory_type": "LongTermMemory",
312
+ "value": "Kalamang语中的亲属名词在所有格构式中的行为存在显著差异,其中“父亲”(esa)和“母亲”(ema)仅能在技术称谓用法中与第三人称所有格后缀共现,而在非技术称谓中带所有格后缀是不合语法的。",
313
+ "tags": ["亲属名词", "所有格", "语法限制"]
314
+ },
315
+ {
316
+ "key": "双重所有格标记现象",
317
+ "memory_type": "LongTermMemory",
318
+ "value": "语料中存在名词同时带有所有格后缀和独立所有格代词的双重所有格标记构式,但该现象出现频率极低,其具体语用功能尚不明确。",
319
+ "tags": ["双重所有格", "罕见构式", "语用功能"]
320
+ },
321
+ {
322
+ "key": "双重所有格与借词的关系",
323
+ "memory_type": "LongTermMemory",
324
+ "value": "双重所有格标记多见于马来语借词中,但也偶尔出现在Kalamang本族词中,显示该构式并非完全由语言接触触发。",
325
+ "tags": ["语言接触", "借词", "构式分布"]
326
+ },
327
+ {
328
+ "key": "=kin 的关联功能与语法地位",
329
+ "memory_type": "LongTermMemory",
330
+ "value": "黏着词 =kin 用于表达目的性、空间或群体性的关联关系,其标记对象通常为关联方而非被拥有物,这表明 =kin 可能处于近期语法化过程中。",
331
+ "tags": ["=kin", "关联关系", "语法化"]
332
+ }
333
+ ],
334
+ "summary": "该文本描述了Kalamang语中所有格构式的多样性与不对称性。亲属名词在所有格标记上的限制显示出语义类别内部的分化,而罕见的双重所有格构式则反映了构式层面的不稳定性。同时,=kin 的多功能关联用法及其分布特征为理解该语言的语法化路径提供了重要线索。"
335
+ }
336
+
337
+ 文档片段:
338
+ {chunk_text}
339
+
340
+ 您的输出:"""
341
+
342
+ GENERAL_STRUCT_STRING_READER_PROMPT = """You are a text analysis expert for search and retrieval systems.
343
+ Your task is to parse a text chunk into multiple structured memories for long-term storage and precise future retrieval. The text chunk may contain information from various sources, including conversations, plain text, speech-to-text transcripts, tables, tool documentation, and more.
344
+
345
+ Please perform the following steps:
346
+
347
+ 1. Decompose the text chunk into multiple memories that are mutually independent, minimally redundant, and each fully expresses a single information point. Together, these memories should cover different aspects of the document so that a reader can understand all core content without reading the original text.
348
+
349
+ 2. Memory splitting and deduplication rules (very important):
350
+ 2.1 Each memory must express only one primary information point, such as:
351
+ - A fact
352
+ - A clear conclusion or judgment
353
+ - A decision or action
354
+ - An important background or condition
355
+ - A notable emotional tone or attitude
356
+ - A plan, risk, or downstream impact
357
+
358
+ 2.2 Do not force multiple information points into a single memory.
359
+
360
+ 2.3 Do not generate memories that are semantically repetitive or highly overlapping:
361
+ - If two memories describe the same fact or judgment, retain only the one with more complete information.
362
+ - Do not create “different” memories solely by rephrasing.
363
+
364
+ 2.4 There is no fixed upper or lower limit on the number of memories; the count should be determined naturally by the information density of the text.
365
+
366
+ 3. Information parsing requirements:
367
+ 3.1 Identify and clearly specify all important:
368
+ - Times (distinguishing event time from document recording time)
369
+ - People (resolving pronouns and aliases to explicit identities)
370
+ - Organizations, locations, and events
371
+
372
+ 3.2 Explicitly resolve all references to time, people, locations, and events:
373
+ - When context allows, convert relative time expressions (e.g., “last year,” “next quarter”) into absolute dates.
374
+ - If uncertainty exists, explicitly state it (e.g., “around 2024,” “exact date unknown”).
375
+ - Include specific locations when mentioned.
376
+ - Resolve all pronouns, aliases, and ambiguous references to full names or clear identities.
377
+ - Disambiguate entities with the same name when necessary.
378
+
379
+ 4. Writing and perspective rules:
380
+ - Always write in the third person, clearly referring to subjects or content, and avoid first-person expressions (“I,” “we,” “my”).
381
+ - Use precise, neutral language and do not infer or introduce information not explicitly stated in the text.
382
+
383
+ Return a valid JSON object with the following structure:
384
+
385
+ {
386
+ "memory list": [
387
+ {
388
+ "key": <string, a concise and unique memory title>,
389
+ "memory_type": "LongTermMemory",
390
+ "value": <a complete, clear, and self-contained memory description; use English if the input is English, and Chinese if the input is Chinese>,
391
+ "tags": <a list of topic keywords highly relevant to this memory>
392
+ },
393
+ ...
394
+ ],
395
+ "summary": <a holistic summary describing how these memories collectively reflect the document’s core content and key points, using the same language as the input text>
396
+ }
397
+
398
+ Language rules:
399
+ - The `key`, `value`, `tags`, and `summary` fields must use the same primary language as the input document. **If the input is Chinese, output must be in Chinese.**
400
+ - `memory_type` must remain in English.
401
+
402
+ {custom_tags_prompt}
403
+
404
+ Example:
405
+ Text chunk:
406
+
407
+ In Kalamang, kinship terms show uneven behavior in possessive constructions. The nouns esa ‘father’ and ema ‘mother’ can only co-occur with a third-person possessive suffix when used as teknonyms; outside of such contexts, possessive marking is ungrammatical. Most other kinship terms do not allow possessive constructions, with only a few marginal exceptions.
408
+
409
+ The corpus also contains rare cases of double possessive marking, in which a noun bears both a possessive suffix and a free possessive pronoun. This construction is infrequent and its discourse function remains unclear. While it appears more often with Malay loanwords, it is not restricted to borrowed vocabulary.
410
+
411
+ In addition, the clitic =kin encodes a range of associative relations, including purposive, spatial, and collective ownership. In such constructions, the marked element typically corresponds to the possessor or associated entity rather than the possessed item, suggesting that =kin may be undergoing recent grammaticalization.
412
+
413
+ Output:
414
+ {
415
+ "memory list": [
416
+ {
417
+ "key": "Asymmetric possessive behavior of kinship terms",
418
+ "memory_type": "LongTermMemory",
419
+ "value": "In Kalamang, kinship terms do not behave uniformly in possessive constructions: ‘father’ (esa) and ‘mother’ (ema) require a teknonymic context to appear with a third-person possessive suffix, whereas possessive marking is otherwise ungrammatical.",
420
+ "tags": ["kinship terms", "possessive constructions", "grammatical constraints"]
421
+ },
422
+ {
423
+ "key": "Rare double possessive marking",
424
+ "memory_type": "LongTermMemory",
425
+ "value": "The language exhibits a rare construction in which a noun carries both a possessive suffix and a free possessive pronoun, though the pragmatic function of this double marking remains unclear.",
426
+ "tags": ["double possessive", "rare constructions", "pragmatics"]
427
+ },
428
+ {
429
+ "key": "Distribution of double possessives across lexicon",
430
+ "memory_type": "LongTermMemory",
431
+ "value": "Double possessive constructions occur more frequently with Malay loanwords but are also attested with indigenous Kalamang vocabulary, indicating that the pattern is not solely contact-induced.",
432
+ "tags": ["loanwords", "language contact", "distribution"]
433
+ },
434
+ {
435
+ "key": "Associative clitic =kin",
436
+ "memory_type": "LongTermMemory",
437
+ "value": "The clitic =kin marks various associative relations, including purposive, spatial, and collective ownership, typically targeting the possessor or associated entity, and appears to reflect an ongoing process of grammaticalization.",
438
+ "tags": ["=kin", "associative relations", "grammaticalization"]
439
+ }
440
+ ],
441
+ "summary": "The text outlines key properties of possessive and associative constructions in Kalamang. Kinship terms exhibit asymmetric grammatical behavior, rare double possessive patterns suggest constructional instability, and the multifunctional clitic =kin provides evidence for evolving associative marking within the language’s grammar."
442
+ }
443
+
444
+ Text chunk:
445
+ {chunk_text}
446
+
447
+ Your output:
448
+ """
449
+
450
+ GENERAL_STRUCT_STRING_READER_PROMPT_ZH = """您是搜索与检索系统的文本分析专家。
451
+ 您的任务是将一个文本片段解析为【多条结构化记忆】,用于长期存储和后续精准检索,这里的文本片段可能包含各种对话、纯文本、语音转录的文字、表格、工具说明等等的信息。
452
+
453
+ 请执行以下操作:
454
+ 1. 将文档片段拆解为若干条【相互独立、尽量不重复、各自完整表达单一信息点】的记忆。这些记忆应共同覆盖文档的不同方面,使读者无需阅读原文即可理解该文档的全部核心内容。
455
+ 2. 记忆拆分与去重规则(非常重要):
456
+ 2.1 每一条记忆应只表达【一个主要信息点】:
457
+ - 一个事实
458
+ - 一个明确结论或判断
459
+ - 一个决定或行动
460
+ - 一个重要背景或条件
461
+ - 一个显著的情感基调或态度
462
+ - 一个计划、风险或后续影响
463
+ 2.2 不要将多个信息点强行合并到同一条记忆中。
464
+ 2.3 不要生成语义重复或高度重叠的记忆:
465
+ - 如果两条记忆表达的是同一事实或同一判断,只保留信息更完整的一条。
466
+ - 不允许仅通过措辞变化来制造“不同”的记忆。
467
+ 2.4 记忆条数不设固定上限或下限,应由文档信息密度自然决定。
468
+ 3. 信息解析要求
469
+ 3.1 识别并明确所有重要的:
470
+ - 时间(区分事件发生时间与文档记录时间)
471
+ - 人物(解析代词、别名为明确身份)
472
+ - 组织、地点、事件
473
+ 3.2 清晰解析所有时间、人物、地点和事件的指代:
474
+ - 如果上下文允许,将相对时间表达(如“去年”、“下一季度”)转换为绝对日期。
475
+ - 如果存在不确定性,需明确说明(例如,“约2024年”,“具体日期不详”)。
476
+ - 若提及具体地点,请包含在内。
477
+ - 将所有代词、别名和模糊指代解析为全名或明确身份。
478
+ - 如有同名实体,需加以区分。
479
+ 4. 写作与视角规则
480
+ - 始终以第三人称视角撰写,清晰指代主题或内容,避免使用第一人称(“我”、“我们”、“我的”)。
481
+ - 语言应准确、中性,不自行引申文档未明确表达的内容。
482
+
483
+ 返回一个有效的 JSON 对象,结构如下:
484
+ {
485
+ "memory list": [
486
+ {
487
+ "key": <字符串,简洁且唯一的记忆标题>,
488
+ "memory_type": "LongTermMemory",
489
+ "value": <一段完整、清晰、可独立理解的记忆描述;若输入为中文则使用中文,若为英文则使用英文>,
490
+ "tags": <与该记忆高度相关的主题关键词列表>
491
+ },
492
+ ...
493
+ ],
494
+ "summary": <一段整体性总结,概括这些记忆如何共同反映文档的核心内容与重点,语言与输入文档一致>
495
+ }
496
+
497
+ 语言规则:
498
+ - `key`、`value`、`tags`、`summary` 字段必须与输入文档摘要的主要语言一致。**如果输入是中文,请输出中文**
499
+ - `memory_type` 保持英文。
500
+
501
+ {custom_tags_prompt}
502
+
503
+ 文档片段:
504
+ {chunk_text}
505
+
506
+ 您的输出:"""
507
+
508
+
509
+ SIMPLE_STRUCT_MEM_READER_EXAMPLE = """Example:
510
+ Conversation:
511
+ user: [June 26, 2025 at 3:00 PM]: Hi Jerry! Yesterday at 3 PM I had a meeting with my team about the new project.
512
+ assistant: Oh Tom! Do you think the team can finish by December 15?
513
+ user: [June 26, 2025 at 3:00 PM]: I’m worried. The backend won’t be done until
514
+ December 10, so testing will be tight.
515
+ assistant: [June 26, 2025 at 3:00 PM]: Maybe propose an extension?
516
+ user: [June 26, 2025 at 4:21 PM]: Good idea. I’ll raise it in tomorrow’s 9:30 AM meeting—maybe shift the deadline to January 5.
517
+
518
+ Output:
519
+ {
520
+ "memory list": [
521
+ {
522
+ "key": "Initial project meeting",
523
+ "memory_type": "LongTermMemory",
524
+ "value": "On June 25, 2025 at 3:00 PM, Tom held a meeting with their team to discuss a new project. The conversation covered the timeline and raised concerns about the feasibility of the December 15, 2025 deadline.",
525
+ "tags": ["project", "timeline", "meeting", "deadline"]
526
+ },
527
+ {
528
+ "key": "Planned scope adjustment",
529
+ "memory_type": "UserMemory",
530
+ "value": "Tom planned to suggest in a meeting on June 27, 2025 at 9:30 AM that the team should prioritize features and propose shifting the project deadline to January 5, 2026.",
531
+ "tags": ["planning", "deadline change", "feature prioritization"]
532
+ },
533
+ ],
534
+ "summary": "Tom is currently focused on managing a new project with a tight schedule. After a team meeting on June 25, 2025, he realized the original deadline of December 15 might not be feasible due to backend delays. Concerned about insufficient testing time, he welcomed Jerry’s suggestion of proposing an extension. Tom plans to raise the idea of shifting the deadline to January 5, 2026 in the next morning’s meeting. His actions reflect both stress about timelines and a proactive, team-oriented problem-solving approach."
535
+ }
536
+
537
+ Another Example in Chinese (注意: 当user的语言为中文时,你就需要也输出中文):
538
+ {
539
+ "memory list": [
540
+ {
541
+ "key": "项目会议",
542
+ "memory_type": "LongTermMemory",
543
+ "value": "在2025年6月25日下午3点,Tom与团队开会讨论了新项目,涉及时间表,并提出了对12月15日截止日期可行性的担忧。",
544
+ "tags": ["项目", "时间表", "会议", "截止日期"]
545
+ },
546
+ ...
547
+ ],
548
+ "summary": "Tom 目前专注于管理一个进度紧张的新项目..."
549
+ }
550
+
551
+ """
552
+
553
+ SIMPLE_STRUCT_MEM_READER_EXAMPLE_ZH = """示例:
554
+ 对话:
555
+ user: [2025年6月26日下午3:00]:嗨Jerry!昨天下午3点我和团队开了个会,讨论新项目。
556
+ assistant: 哦Tom!你觉得团队能在12月15日前完成吗?
557
+ user: [2025年6月26日下午3:00]:我有点担心。后端要到12月10日才能完成,所以测试时间会很紧。
558
+ assistant: [2025年6月26日下午3:00]:也许提议延期?
559
+ user: [2025年6月26日下午4:21]:好主意。我明天上午9:30的会上提一下——也许把截止日期推迟到1月5日。
560
+
561
+ 输出:
562
+ {
563
+ "memory list": [
564
+ {
565
+ "key": "项目初期会议",
566
+ "memory_type": "LongTermMemory",
567
+ "value": "2025年6月25日下午3:00,Tom与团队开会讨论新项目。会议涉及时间表,并提出了对2025年12月15日截止日期可行性的担忧。",
568
+ "tags": ["项目", "时间表", "会议", "截止日期"]
569
+ },
570
+ {
571
+ "key": "计划调整范围",
572
+ "memory_type": "UserMemory",
573
+ "value": "Tom计划在2025年6月27日上午9:30的会议上建议团队优先处理功能,并提议将项目截止日期推迟至2026年1月5日。",
574
+ "tags": ["计划", "截止日期变更", "功能优先级"]
575
+ }
576
+ ],
577
+ "summary": "Tom目前正专注于管理一个进度紧张的新项目。在2025年6月25日的团队会议后,他意识到原定2025年12月15日的截止日期可能无法实现,因为后端会延迟。由于担心测试时间不足,他接受了Jerry提出的延期建议。Tom计划在次日早上的会议上提出将截止日期推迟至2026年1月5日。他的行为反映出对时间线的担忧,以及积极、以团队为导向的问题解决方式。"
578
+ }
579
+
580
+ 另一个中文示例(注意:当用户语言为中文时,您也需输出中文):
581
+ {
582
+ "memory list": [
583
+ {
584
+ "key": "项目会议",
585
+ "memory_type": "LongTermMemory",
586
+ "value": "在2025年6月25日下午3点,Tom与团队开会讨论了新项目,涉及时间表,并提出了对12月15日截止日期可行性的担忧。",
587
+ "tags": ["项目", "时间表", "会议", "截止日期"]
588
+ },
589
+ ...
590
+ ],
591
+ "summary": "Tom 目前专注于管理一个进度紧张的新项目..."
592
+ }
593
+
594
+ """
595
+
596
+
597
+ CUSTOM_TAGS_INSTRUCTION = """Output tags can refer to the following tags:
598
+ {custom_tags}
599
+ You can choose tags from the above list that are relevant to the memory. Additionally, you can freely add tags based on the content of the memory."""
600
+
601
+
602
+ CUSTOM_TAGS_INSTRUCTION_ZH = """输出tags可以参考下列标签:
603
+ {custom_tags}
604
+ 你可以选择与memory相关的在上述列表中可以加入tags,同时你可以根据memory的内容自由添加tags。"""
605
+
606
+
607
+ IMAGE_ANALYSIS_PROMPT_EN = """You are an intelligent memory assistant. Please analyze the provided image based on the contextual information (if any) and extract meaningful information that should be remembered.
608
+
609
+ Please extract:
610
+ 1. **Visual Content**: What objects, people, scenes, or text are visible in the image?
611
+ 2. **Key Information**: What important details, facts, or information can be extracted?
612
+ 3. **User Relevance**: What aspects of this image might be relevant to the user's memory?
613
+
614
+ Return a valid JSON object with the following structure:
615
+ {
616
+ "memory list": [
617
+ {
618
+ "key": <string, a unique and concise memory title>,
619
+ "memory_type": <string, "LongTermMemory" or "UserMemory">,
620
+ "value": <a detailed, self-contained description of what should be remembered from the image>,
621
+ "tags": <a list of relevant keywords (e.g., ["image", "visual", "scene", "object"])>
622
+ },
623
+ ...
624
+ ],
625
+ "summary": <a natural paragraph summarizing the image content, 120–200 words>
626
+ }
627
+
628
+ Language rules:
629
+ - The `key`, `value`, `tags`, `summary` and `memory_type` fields should match the language of the user's context if available, otherwise use English.
630
+ - Keep `memory_type` in English.
631
+
632
+ Example:
633
+ Reference context:
634
+ role-user: I plan to carry this for hiking at Mount Siguniang
635
+ role-Bob: Me too
636
+
637
+ Image URL to be analyzed: https://xxxxxx.jpg
638
+ {
639
+ "memory list": [
640
+ {
641
+ "key": "Cylindrical Carry-On Item Attached to Hiking Backpack",
642
+ "memory_type": "LongTermMemory",
643
+ "value": "An outdoor hiking backpack has a black cylindrical carry-on item secured to its side with webbing straps. The cylinder is positioned vertically, with a length close to the height of the backpack’s side pocket. The exterior is dark-colored with a textured or perforated surface, clearly designed for outdoor use and convenient access while walking.",
644
+ "tags": ["outdoor", "hiking", "backpack", "side-mounted", "carry-on item"]
645
+ },
646
+ {
647
+ "key": "Mount Siguniang Hiking Equipment Plan",
648
+ "memory_type": "UserMemory",
649
+ "value": "Both the user and Bob explicitly plan to carry this outdoor backpack during their hiking trip to Mount Siguniang, indicating that this carrying setup has been included in their preparation for a high-altitude hiking journey.",
650
+ "tags": ["user plan", "Mount Siguniang", "hiking", "trekking trip"]
651
+ }
652
+ ],
653
+ "summary": "The image presents a typical hiking setup in an outdoor context. A hiking or travel backpack has a black cylindrical carry-on item attached to its side, suggesting a lightweight and practical configuration for long-distance walking. The overall visual tone emphasizes mobility and convenience. The accompanying text highlights ease of travel, no installation required, and suitability for carrying while on the move. Clear specifications for the cylindrical item are also shown, including its width (approximately 2.56 inches), height (approximately 9.76 inches), and net weight (about 1.45 pounds), underscoring its compact size and manageable weight. Combined with the provided context, this setup is planned for a hiking trip to Mount Siguniang, giving the image a clear personal usage scenario and long-term memory relevance."
654
+ }
655
+
656
+ If context is provided, incorporate it into the extraction. If no context is given, extract only the key information from the image.
657
+
658
+ Reference context:
659
+ {context}
660
+
661
+ Focus on extracting factual, observable information from the image. Avoid speculation unless clearly relevant to user memory."""
662
+
663
+
664
+ IMAGE_ANALYSIS_PROMPT_ZH = """您是一个智能记忆助手。请根据上下文信息(如有)分析提供的图像并提取应该被记住的有意义信息。
665
+
666
+ 请提取:
667
+ 1. **视觉内容**:图像中可见的物体、人物、场景或文字是什么?
668
+ 2. **关键信息**:可以提取哪些重要的细节、事实或信息?
669
+ 3. **用户相关性**:图像的哪些方面可能与用户的记忆相关?
670
+
671
+ 返回一个有效的 JSON 对象,格式如下:
672
+ {
673
+ "memory list": [
674
+ {
675
+ "key": <字符串,一个唯一且简洁的记忆标题>,
676
+ "memory_type": <字符串,"LongTermMemory" 或 "UserMemory">,
677
+ "value": <一个详细、自包含的描述,说明应该从图像中记住什么>,
678
+ "tags": <相关关键词列表(例如:["图像", "视觉", "场景", "物体"])>
679
+ },
680
+ ...
681
+ ],
682
+ "summary": <一个自然段落,总结图像内容,120-200字>
683
+ }
684
+
685
+ 语言规则:
686
+ - `key`、`value`、`tags`、`summary` 和 `memory_type` 字段应该与用户上下文的语言匹配(如果可用),否则使用中文。
687
+ - `memory_type` 保持英文。
688
+
689
+ 例子:
690
+ 参考的上下文:
691
+ role-user: 我打算背这个去四姑娘山徒步
692
+ role-bob: 我也是
693
+
694
+ 待解析的url:https://xxxxxx.jpg
695
+ {
696
+ "memory list": [
697
+ {
698
+ "key": "徒步背包侧挂圆柱形随行物品",
699
+ "memory_type": "LongTermMemory",
700
+ "value": "一只户外徒步背包侧面通过织带固定了一件黑色圆柱形随行物品。圆柱体纵向放置,长度接近背包侧袋高度,外壳为深色并带有防滑或透气纹理,整体外观明显为户外使用设计,方便在行走过程中快速取放。",
701
+ "tags": ["户外", "徒步", "背包", "侧挂", "随行物品"]
702
+ },
703
+ {
704
+ "key": "四姑娘山徒步随身装备计划",
705
+ "memory_type": "UserMemory",
706
+ "value": "用户和Bob明确计划在四姑娘山徒步行程中背负该款户外背包,说明这套背负方式已被纳入他们高海拔徒步行程的装备准备中。",
707
+ "tags": ["用户计划", "四姑娘山", "徒步", "登山行程"]
708
+ }
709
+ ],
710
+ "summary": "画面展示了一种典型的徒步出行配置:一只登山或旅行背包侧边固定着一件黑色圆柱形随行物品,整体氛围明显指向户外行走和轻量化携带场景。画面中的文字强调轻便、无需安装、适合随身携带的使用理念,并直接给出了随行物品的尺寸与重量信息(宽度约2.56英寸、高度约9.76英寸、净重约1.45磅),突出了便于背负和长时间携行的特点。结合用户给出的背景,这套装备被计划用于四姑娘山徒步,具备清晰的个人使用情境和长期记忆价值。"
711
+ }
712
+
713
+ 如果给定了上下文,就结合上下文信息进行提取,如果没有给定上下文,请直接提取图片的关键信息。
714
+ 参考的上下文:
715
+ {context}
716
+
717
+ 专注于从图像中提取事实性、可观察的信息。除非与用户记忆明显相关,否则避免推测。
718
+ """
719
+
720
+
721
+ SIMPLE_STRUCT_REWRITE_MEMORY_PROMPT_BACKUP = """
722
+ You are a strict, language-preserving memory validator and rewriter.
723
+
724
+ Your task is to eliminate hallucinations and tighten memories by grounding them strictly in the user’s explicit messages. Memories must be factual, unambiguous, and free of any inferred or speculative content.
725
+
726
+ Rules:
727
+ 1. **Language Consistency**: Keep the exact original language of each memory—no translation or language switching.
728
+ 2. **Strict Factual Grounding**: Include only what the user explicitly stated. Remove or flag anything not directly present in the messages—no assumptions, interpretations, predictions, or generalizations NOT supported by the text. However, **you MUST retain specific details, reasons, explanations, and feelings if the user explicitly expressed them.** Minor formatting corrections (e.g., adding missing spaces between names, fixing obvious typos) are ALLOWED.
729
+ 4. **Hallucination Removal**:
730
+ - If a memory contains **any content not supported by the user's explicit statements**, it must be rewritten.
731
+ - **Do NOT remove** details, reasons, or explanations that the user explicitly provided, even if they are subjective or specific.
732
+ - Do **not** rephrase inferences as facts. Instead, either:
733
+ - Remove the unsupported part and retain only the grounded core.
734
+ 5. **No Change if Fully Grounded**: If the memory is concise, unambiguous, and fully supported by the user’s messages, keep it unchanged.
735
+ 6. **Timestamp Exception**: Memories may include timestamps (e.g., dates like "On December 19, 2026") derived from conversation metadata. If the date in the memory is likely the conversation time (even if not shown in the `messages` list), do NOT treat it as a hallucination or require a rewrite.
736
+
737
+ Inputs:
738
+ messages:
739
+ {messages_inline}
740
+
741
+ memories:
742
+ {memories_inline}
743
+
744
+ Output Format:
745
+ - Return a JSON object with string keys ("0", "1", "2", ...) matching input memory indices.
746
+ - Each value must be: {{ "need_rewrite": boolean, "rewritten": string, "reason": string }}
747
+ - The "reason" must be brief and precise, e.g.:
748
+ - "contains unsupported inference ...."
749
+ - "fully grounded and concise"
750
+
751
+ Important: Output **only** the JSON. No extra text, explanations, markdown, or fields.
752
+ """
753
+
754
+ SIMPLE_STRUCT_REWRITE_MEMORY_PROMPT = """
755
+ You are a strict, language-preserving memory validator and rewriter.
756
+
757
+ Your task is to eliminate hallucinations and tighten memories by grounding them strictly in the user’s explicit messages. Memories must be factual, unambiguous, and free of any inferred or speculative content.
758
+
759
+ Rules:
760
+ 1. **Language Consistency**: Keep the exact original language of each memory—no translation or language switching.
761
+ 2. **Strict Factual Grounding**: Include only what is explicitly stated by the user in messages marked as [user]. Remove or flag anything not directly present in the user’s utterances—no assumptions, interpretations, predictions, generalizations, or content originating solely from [assistant].
762
+ 3. **Source Attribution Requirement**:
763
+ - Every memory must be clearly traceable to its source:
764
+ - If a fact appears **only in [assistant] messages** and **is not affirmed by [user]**, label it as “[assistant] memory”.
765
+ - If [assistant] states something and [user] explicitly contradicts or denies it, label it as “[assistant] memory, but [user] [brief quote or summary of denial]”.
766
+ - If a fact is stated by [user] —whether or not [assistant] also mentions it— it is attributed to “[user]” and may be retained without qualification.
767
+ 4. **Timestamp Exception**: Memories may include timestamps (e.g., "On December 19, 2026") derived from conversation metadata. If such a date likely reflects the conversation time (even if not in the `messages` list), do NOT treat it as hallucinated—but still attribute it to “[user]” only if the user mentioned or confirmed the date.
768
+
769
+ Inputs:
770
+ messages:
771
+ {messages_inline}
772
+
773
+ memories:
774
+ {memories_inline}
775
+
776
+ Output Format:
777
+ - Return a JSON object with string keys ("0", "1", "2", ...) matching input memory indices.
778
+ - Each value must be: {{ "need_rewrite": boolean, "rewritten": string, "reason": string }}
779
+ - The "reason" must be brief and precise, e.g.:
780
+ - "contains unsupported inference from [assistant]"
781
+ - "[assistant] memory, but [user] said 'I don't have a dog'"
782
+ - "fully grounded in [user]"
783
+
784
+ Important: Output **only** the JSON. No extra text, explanations, markdown, or fields.
785
+ """
786
+
787
+ SIMPLE_STRUCT_REWRITE_MEMORY_USER_ONLY_PROMPT = """
788
+ You are a strict, language-preserving memory validator and rewriter.
789
+
790
+ Your task is to eliminate hallucinations and tighten memories by grounding them strictly in the user’s explicit messages. Memories must be factual, unambiguous, and free of any inferred or speculative content.
791
+
792
+ Note: The provided messages contain only user messages. The assistant's responses are intentionally omitted, not because the assistant didn't answer, but to focus strictly on validating memories against user input.
793
+
794
+ Rules:
795
+ 1. **Language Consistency**: Keep the exact original language of each memory—no translation or language switching.
796
+ 2. **Strict Factual Grounding**: Include only what the user explicitly stated. Remove or flag anything not directly present in the messages—no assumptions, interpretations, predictions, or generalizations NOT supported by the text. However, **you MUST retain specific details, reasons, explanations, and feelings if the user explicitly expressed them.** Minor formatting corrections (e.g., adding missing spaces between names, fixing obvious typos) are ALLOWED.
797
+ 4. **Hallucination Removal**:
798
+ - If a memory contains **any content not supported by the user's explicit statements**, it must be rewritten.
799
+ - **Do NOT remove** details, reasons, or explanations that the user explicitly provided, even if they are subjective or specific.
800
+ - Do **not** rephrase inferences as facts. Instead, either:
801
+ - Remove the unsupported part and retain only the grounded core.
802
+ 5. **No Change if Fully Grounded**: If the memory is concise, unambiguous, and fully supported by the user’s messages, keep it unchanged.
803
+ 6. **Timestamp Exception**: Memories may include timestamps (e.g., dates like "On December 19, 2026") derived from conversation metadata. If the date in the memory is likely the conversation time (even if not shown in the `messages` list), do NOT treat it as a hallucination or require a rewrite.
804
+
805
+ Inputs:
806
+ messages:
807
+ {messages_inline}
808
+
809
+ memories:
810
+ {memories_inline}
811
+
812
+ Output Format:
813
+ - Return a JSON object with string keys ("0", "1", "2", ...) matching input memory indices.
814
+ - Each value must be: {{ "need_rewrite": boolean, "rewritten": string, "reason": string }}
815
+ - The "reason" must be brief and precise, e.g.:
816
+ - "contains unsupported inference ...."
817
+ - "fully grounded and concise"
818
+
819
+ Important: Output **only** the JSON. No extra text, explanations, markdown, or fields.
820
+ """
821
+
822
+ SIMPLE_STRUCT_REWRITE_MEMORY_PROMPT_BACKUP = """
823
+ You are a strict, language-preserving memory validator and rewriter.
824
+
825
+ Your task is to eliminate hallucinations and tighten memories by grounding them strictly in the user’s explicit messages. Memories must be factual, unambiguous, and free of any inferred or speculative content.
826
+
827
+ Rules:
828
+ 1. **Language Consistency**: Keep the exact original language of each memory—no translation or language switching.
829
+ 2. **Strict Factual Grounding**: Include only what the user explicitly stated. Remove or flag anything not directly present in the messages—no assumptions, interpretations, predictions, or generalizations NOT supported by the text. However, **you MUST retain specific details, reasons, explanations, and feelings if the user explicitly expressed them.** Minor formatting corrections (e.g., adding missing spaces between names, fixing obvious typos) are ALLOWED.
830
+ 4. **Hallucination Removal**:
831
+ - If a memory contains **any content not supported by the user's explicit statements**, it must be rewritten.
832
+ - **Do NOT remove** details, reasons, or explanations that the user explicitly provided, even if they are subjective or specific.
833
+ - Do **not** rephrase inferences as facts. Instead, either:
834
+ - Remove the unsupported part and retain only the grounded core.
835
+ 5. **No Change if Fully Grounded**: If the memory is concise, unambiguous, and fully supported by the user’s messages, keep it unchanged.
836
+ 6. **Timestamp Exception**: Memories may include timestamps (e.g., dates like "On December 19, 2026") derived from conversation metadata. If the date in the memory is likely the conversation time (even if not shown in the `messages` list), do NOT treat it as a hallucination or require a rewrite.
837
+
838
+ Inputs:
839
+ messages:
840
+ {messages_inline}
841
+
842
+ memories:
843
+ {memories_inline}
844
+
845
+ Output Format:
846
+ - Return a JSON object with string keys ("0", "1", "2", ...) matching input memory indices.
847
+ - Each value must be: {{ "need_rewrite": boolean, "rewritten": string, "reason": string }}
848
+ - The "reason" must be brief and precise, e.g.:
849
+ - "contains unsupported inference ...."
850
+ - "fully grounded and concise"
851
+
852
+ Important: Output **only** the JSON. No extra text, explanations, markdown, or fields.
853
+ """
854
+
855
+ SIMPLE_STRUCT_HALLUCINATION_FILTER_PROMPT = """
856
+ You are a strict memory validator.
857
+ Your task is to identify and delete hallucinated memories that are not explicitly stated by the user in the provided messages.
858
+
859
+ Rules:
860
+ 1. **Explicit Denial & Inconsistency**: If a memory claims something that the user explicitly denied or is clearly inconsistent with the user's statements, mark it for deletion.
861
+ 2. **Timestamp Exception**: Memories may include timestamps (e.g., dates like "On December 19, 2026") derived from conversation metadata. If the date in the memory is likely the conversation time (even if not shown in the `messages` list), do NOT treat it as a hallucination or require a rewrite.
862
+
863
+ Example:
864
+ Messages:
865
+ [user]: I'm planning a trip to Japan next month for about a week.
866
+ [assistant]: That sounds great! Are you planning to visit Tokyo Disneyland?
867
+ [user]: No, I won't be going to Tokyo this time. I plan to stay in Kyoto and Osaka to avoid crowds.
868
+
869
+ Memories:
870
+ {{
871
+ "0": "User plans to travel to Japan for a week next month.",
872
+ "1": "User intends to visit Tokyo Disneyland.",
873
+ "2": "User plans to stay in Kyoto and Osaka."
874
+ }}
875
+
876
+ Output:
877
+ {{
878
+ "0": {{ "keep": true, "reason": "Explicitly stated by user." }},
879
+ "1": {{ "keep": false, "reason": "User explicitly denied visiting Tokyo." }},
880
+ "2": {{ "keep": true, "reason": "Explicitly stated by user." }}
881
+ }}
882
+
883
+ Inputs:
884
+ Messages:
885
+ {messages_inline}
886
+
887
+ Memories:
888
+ {memories_inline}
889
+
890
+ Output Format:
891
+ - Return a JSON object with string keys ("0", "1", "2", ...) matching the input memory indices.
892
+ - Each value must be: {{ "keep": boolean, "reason": string }}
893
+ - "keep": true only if the memory is a direct reflection of the user's explicit words.
894
+ - "reason": brief, factual, and cites missing or unsupported content.
895
+
896
+ Important: Output **only** the JSON. No extra text, explanations, markdown, or fields.
897
+ """
898
+
899
+
900
+ SIMPLE_STRUCT_ADD_BEFORE_SEARCH_PROMPT = """
901
+ You are a memory manager.
902
+ Your task is to decide if a new memory should be added to the long-term memory, given a list of existing related memories.
903
+
904
+ Rules:
905
+ 1. **Redundancy Check**: If the new memory is completely redundant, already known, or covered by the existing memories, discard it.
906
+ 2. **New Information**: If the new memory provides new information, details, or updates compared to the existing memories, keep it.
907
+ 3. **Contradiction**: If the new memory contradicts existing memories but seems valid/newer, keep it (updates).
908
+ 4. **Context Check**: Use the provided conversation messages to verify if the new memory is grounded in the user's explicit statements.
909
+
910
+ Inputs:
911
+ Messages:
912
+ {messages_inline}
913
+
914
+ Candidate Memories (to be evaluated):
915
+ {candidates_inline}
916
+
917
+ Output Format:
918
+ - Return a JSON object with string keys ("0", "1", "2", ...) matching the input candidate memory indices.
919
+ - Each value must be: {{ "keep": boolean, "reason": string }}
920
+ - "keep": true if the memory should be added.
921
+ - "reason": brief explanation.
922
+
923
+ Important: Output **only** the JSON. No extra text.
924
+ """
925
+
926
+ MEMORY_MERGE_PROMPT_EN = """You are a memory consolidation expert. Given a new memory and a set of similar existing memories, determine whether they should be merged.
927
+
928
+ Before generating the value, you must complete the following reasoning steps (done in internal reasoning, no need to output them):
929
+ 1. Identify the “fact units” contained in the new memory, for example:
930
+ • Identity-type facts: name, occupation, place of residence, etc.
931
+ • Stable preference-type facts: things the user likes/dislikes long-term, frequently visited places, etc.
932
+ • Relationship-type facts: relationships with someone (friend, colleague, fixed activity partner, etc.)
933
+ • One-off event/plan-type facts: events on a specific day, temporary plans for this weekend, etc.
934
+ 2. For each fact unit, determine:
935
+ • Which existing memories are expressing “the same kind of fact”
936
+ • Whether the corresponding fact in the new memory is just a “repeated confirmation” of that fact, rather than “new factual content”
937
+
938
+ Merge rules (must be followed when generating value):
939
+ • The merged value:
940
+ • Must not repeat the same meaning (each fact should be described only once)
941
+ • Must not repeat the same fact just because it was mentioned multiple times or at different times
942
+ • Unless time itself changes the meaning (for example, “used to dislike → now likes”), do not keep specific time information
943
+ • If the new memory contains multiple different types of facts (for example: “name + hobby + plan for this weekend”):
944
+ • You may output multiple merge results; each merge result should focus on only one type of fact (for example: one about “name”, one about “hobby”)
945
+ • Do not force unrelated facts into the same value
946
+ • One-off events/plans (such as “going skiing this weekend”, “attending a party on Sunday”):
947
+ • If there is no directly related and complementary event memory in the existing memories, treat it as an independent memory and do not merge it with identity/stable preference-type memories
948
+ • Do not merge a “temporary plan” and a “long-term preference” into the same value just because they are related (e.g. a plan to ski vs. a long-term preference for skiing)
949
+
950
+ Output format requirements:
951
+ • You must return a single JSON object.
952
+ • If a merge occurred:
953
+ • “value”: The merged memory content (only describe the final conclusion, preserving all “semantically unique” information, without repetition)
954
+ • “merged_from”: A list of IDs of the similar memories that were merged
955
+ • “should_merge”: true
956
+ • If the new memory cannot be merged with any existing memories, return:
957
+ • “should_merge”: false
958
+
959
+ Example:
960
+ New memory:
961
+ The user’s name is Tom, the user likes skiing, and plans to go skiing this weekend.
962
+
963
+ Similar existing memories:
964
+ xxxx-xxxx-xxxx-xxxx-01: The user’s name is Tom
965
+ xxxx-xxxx-xxxx-xxxx-10: The user likes skiing
966
+ xxxx-xxxx-xxxx-xxxx-11: The user lives by the sea
967
+
968
+ Expected return value:
969
+ {{
970
+ "value": "The user's name is Tom and the user likes skiing",
971
+ "merged_from": ["xxxx-xxxx-xxxx-xxxx-01", "xxxx-xxxx-xxxx-xxxx-10"],
972
+ "should_merge": true
973
+ }}
974
+
975
+ New memory:
976
+ The user is going to attend a party on Sunday.
977
+
978
+ Similar existing memories:
979
+ xxxx-xxxx-xxxx-xxxx-01: The user read a book yesterday.
980
+
981
+ Expected return value:
982
+ {{
983
+ "should_merge": false
984
+ }}
985
+
986
+ If the new memory largely overlaps with or complements the existing memories, merge them into an integrated memory and return a JSON object:
987
+ • “value”: The merged memory content
988
+ • “merged_from”: A list of IDs of the similar memories that were merged
989
+ • “should_merge”: true
990
+
991
+ If the new memory is unique and should remain independent, return:
992
+ {{
993
+ "should_merge": false
994
+ }}
995
+
996
+ You must only return a valid JSON object in the final output, and no additional content (no natural language explanations, no extra fields).
997
+
998
+ New memory:
999
+ {new_memory}
1000
+
1001
+ Similar existing memories:
1002
+ {similar_memories}
1003
+
1004
+ Only return a valid JSON object, and do not include any other content.
1005
+ """
1006
+
1007
+ MEMORY_MERGE_PROMPT_ZH = """
1008
+ 你是一个记忆整合专家。给定一个新记忆和相似的现有记忆,判断它们是否应该合并。
1009
+
1010
+ 在生成 value 之前,必须先完成以下判断步骤(在内在推理中完成,不需要输出):
1011
+ 1. 识别新记忆中包含的「事实单元」,例如:
1012
+ - 身份信息类:名字、职业、居住地等
1013
+ - 稳定偏好类:长期喜欢/不喜欢的事物、常去地点等
1014
+ - 关系类:与某人的关系(朋友、同事、固定搭子等)
1015
+ - 一次性事件/计划类:某天要参加的活动、本周末的临时安排等
1016
+ 2. 对每个事实单元,判断:
1017
+ - 哪些 existing memories 在表达“同一类事实”,
1018
+ - 新记忆中对应的事实是否只是对该事实的「重复确认」,而不是“新的事实内容”
1019
+
1020
+ 合并规则(生成 value 时必须遵守):
1021
+ - 合并后的 value:
1022
+ - 不要重复表达同一语义(同一事实只描述一次)
1023
+ - 不要因为多次提及或不同时间而重复同一事实
1024
+ - 除非时间本身改变了语义(例如“从不喜欢 → 现在开始喜欢”),否则不要保留具体时间信息
1025
+ - 如果新记忆中包含多个不同类型的事实(例如“名字 + 爱好 + 本周计划”):
1026
+ - 不要合并就好
1027
+ - 不要把彼此无关的事实硬塞进同一个 value 中
1028
+ - 一次性事件/计划(如“本周末去滑雪”“周天参加聚会”):
1029
+ - 如果 existing memories 中没有与之直接相关、可互补的事件记忆,则视为独立记忆,不要与身份/长期偏好类记忆合并
1030
+ - 不要因为它和某个长期偏好有关(例如喜欢滑雪),就把“临时计划”和“长期偏好”合在一个 value 里
1031
+
1032
+ 输出格式要求:
1033
+ - 你需要返回一个 JSON 对象。
1034
+ - 若发生了合并:
1035
+ - "value": 合并后的记忆内容(只描述最终结论,保留所有「语义上独特」的信息,不重复)
1036
+ - "merged_from": 被合并的相似记忆 ID 列表
1037
+ - "should_merge": true
1038
+ - 若新记忆无法与现有记忆合并,返回:
1039
+ - "should_merge": false
1040
+
1041
+ 示例:
1042
+ 新记忆:
1043
+ 用户的名字是Tom,用户喜欢滑雪,并计划周末去滑雪
1044
+
1045
+ 相似的现有记忆:
1046
+ xxxx-xxxx-xxxx-xxxx-01: 用户的名字是Tom
1047
+ xxxx-xxxx-xxxx-xxxx-10: 用户喜欢滑雪
1048
+ xxxx-xxxx-xxxx-xxxx-11: 用户住在海边
1049
+
1050
+ 应该的返回值:
1051
+ {{
1052
+ "value": "用户的名字是Tom,用户喜欢滑雪",
1053
+ "merged_from": ["xxxx-xxxx-xxxx-xxxx-01", "xxxx-xxxx-xxxx-xxxx-10"],
1054
+ "should_merge": true
1055
+ }}
1056
+
1057
+ 新记忆:
1058
+ 用户周天要参加一个聚会
1059
+
1060
+ 相似的现有记忆:
1061
+ xxxx-xxxx-xxxx-xxxx-01: 用户昨天读了一本书
1062
+
1063
+ 应该的返回值:
1064
+ {{
1065
+ "should_merge": false
1066
+ }}
1067
+
1068
+ 如果新记忆与现有记忆大量重叠或互补,将它们合并为一个整合的记忆,并返回一个JSON对象:
1069
+ - "value": 合并后的记忆内容
1070
+ - "merged_from": 被合并的相似记忆ID列表
1071
+ - "should_merge": true
1072
+
1073
+ 如果新记忆是独特的,应该保持独立,返回:
1074
+ {{
1075
+ "should_merge": false
1076
+ }}
1077
+
1078
+ 最终只返回有效的 JSON 对象,不要任何额外内容(不要自然语言解释、不要多余字段)。
1079
+
1080
+ 新记忆:
1081
+ {new_memory}
1082
+
1083
+ 相似的现有记忆:
1084
+ {similar_memories}
1085
+
1086
+ 只返回有效的JSON对象,不要其他内容。"""
1087
+
1088
+ # Prompt mapping for specialized tasks (e.g., hallucination filtering)
1089
+ PROMPT_MAPPING = {
1090
+ "hallucination_filter": SIMPLE_STRUCT_HALLUCINATION_FILTER_PROMPT,
1091
+ "rewrite": SIMPLE_STRUCT_REWRITE_MEMORY_PROMPT,
1092
+ "rewrite_user_only": SIMPLE_STRUCT_REWRITE_MEMORY_USER_ONLY_PROMPT,
1093
+ "add_before_search": SIMPLE_STRUCT_ADD_BEFORE_SEARCH_PROMPT,
1094
+ "memory_merge_en": MEMORY_MERGE_PROMPT_EN,
1095
+ "memory_merge_zh": MEMORY_MERGE_PROMPT_ZH,
1096
+ }