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,822 @@
1
+ KEYWORDS_REPLACE = """
2
+ **Instruction:**
3
+ Please analyze the user's input text to determine if it is a "keyword replacement" request. If yes, follow these steps:
4
+
5
+ 1. **Identify the request type**: Confirm whether the user is asking to replace a specific word or phrase with another **within a specified scope**.
6
+ 2. **Extract the modification scope**: Determine the scope where the modification should apply.
7
+ - If the user mentions a specific **document, file, or material identifier** (e.g., "in the Q1 operations plan", "in the prospectus numbered BT7868"), extract this description as the document scope.
8
+ - **If the user does not explicitly specify any scope, mark the scope as "NONE"**.
9
+ 3. **Extract the original term (A)**: Identify the original word or phrase the user wants to be replaced.
10
+ 4. **Extract the target term (B)**: Identify the target word or phrase the user wants to replace it with.
11
+
12
+ **Output JSON Format**:
13
+ {{
14
+ "if_keyword_replace": "true" | "false",
15
+ "doc_scope": "[Extracted specific file or document description]" | "NONE" | null,
16
+ "original": "[Extracted original word or phrase A]" | null,
17
+ "target": "[Extracted target word or phrase B]" | null
18
+ }}
19
+ - **If it is NOT a replacement request**, set `if_keyword_replace` to `"false"`, and set the values for `doc_scope`, `original`, and `target` to `null`.
20
+ - **If it IS a replacement request**, set `if_keyword_replace` to `"true"` and fill in the remaining fields. If the user did not specify a scope, set `doc_scope` to `"NONE"`.
21
+
22
+ **Examples**:
23
+
24
+ 1. **User Input**: "In the file `User_Agreement.docx`, replace 'Party B' with 'User'."
25
+ **Output**:
26
+ {{
27
+ "if_keyword_replace": "true",
28
+ "doc_scope": "User_Agreement.docx",
29
+ "original": "Party B",
30
+ "target": "User"
31
+ }}
32
+
33
+ 2. **User Input**: "Change 'Homepage' to 'Front Page'."
34
+ **Output**:
35
+ {{
36
+ "if_keyword_replace": "true",
37
+ "doc_scope": "NONE",
38
+ "original": "Homepage",
39
+ "target": "Front Page"
40
+ }}
41
+
42
+ 3. **User Input**: "Does this sentence need modification?"
43
+ **Output**:
44
+ {{
45
+ "if_keyword_replace": "false",
46
+ "doc_scope": null,
47
+ "original": null,
48
+ "target": null
49
+ }}
50
+
51
+ **User Input**
52
+ {user_feedback}
53
+
54
+ **Output**:
55
+ """
56
+
57
+
58
+ KEYWORDS_REPLACE_ZH = """
59
+ **指令:**
60
+ 请分析用户输入的文本,判断是否为“关键词替换”需求。 如果是,请按以下步骤处理:
61
+
62
+ 1. **识别需求类型**:确认用户是否要求将**特定范围**内的某个词或短语替换为另一个词或短语。
63
+ 2. **提取修改范围**:确定用户指定的修改生效范围。
64
+ - 如果用户提及了具体的**文档、文件或资料标识**(如“在第一季运营方案”、“编号为BT7868的招股书”),则提取此描述作为文件范围。
65
+ - **如果用户未明确指定任何范围,则范围标记为 "NONE"**。
66
+ 3. **提取原始词汇(A)**:找出用户希望被替换的原始词或短语。
67
+ 4. **提取目标词汇(B)**:找出用户希望替换成的目标词或短语。
68
+
69
+ **输出JSON格式**:
70
+ {{
71
+ "if_keyword_replace": "true" | "false",
72
+ "doc_scope": "[提取的具体文件或文档描述]" | "NONE" | null,
73
+ "original": "[提取的原始词或短语A]" | null,
74
+ "target": "[提取的目标词或短语B]" | null
75
+ }}
76
+ - **如果不是替换需求**,将 `if_keyword_replace` 设为 `"false"`,并将 `doc_scope`、`original`、`target` 三个键的值都设为 `null`。
77
+ - **如果是替换需求**,将 `if_keyword_replace` 设为 `"true"`,并填充其余字段。如果用户未指定范围,`doc_scope` 设为 `"NONE"`。
78
+
79
+
80
+ **示例**:
81
+
82
+ 1. **用户输入**:“在`用户协议.docx`这个文件中,把‘乙方’替换为‘用户’。”
83
+ **输出**:
84
+ {{
85
+ "if_keyword_replace": "true",
86
+ "doc_scope": "用户协议.docx",
87
+ "original": "乙方",
88
+ "target": "用户"
89
+ }}
90
+
91
+ 2. **用户输入**:“把‘主页’改成‘首页’。”
92
+ **输出**:
93
+ {{
94
+ "if_keyword_replace": "true",
95
+ "doc_scope": "NONE",
96
+ "original": "主页",
97
+ "target": "首页"
98
+ }}
99
+
100
+ 3. **用户输入**:“这个句子需要修改吗?”
101
+ **输出**:
102
+ {{
103
+ "if_keyword_replace": "false",
104
+ "doc_scope": null,
105
+ "original": null,
106
+ "target": null
107
+ }}
108
+
109
+
110
+ **用户输入**
111
+ {user_feedback}
112
+
113
+ **输出**:
114
+ """
115
+
116
+
117
+ FEEDBACK_JUDGEMENT_PROMPT = """You are a answer quality analysis expert. Please strictly follow the steps and criteria below to analyze the provided "User and Assistant Chat History" and "User Feedback," and fill the final evaluation results into the specified JSON format.
118
+
119
+ Analysis Steps and Criteria:
120
+ 1. *Validity Judgment*:
121
+ - Valid (true): The content of the user's feedback is related to the topic, task, or the assistant's last response in the chat history. For example: asking follow-up questions, making corrections, providing supplements, or evaluating the last response.
122
+ - Invalid (false): The user's feedback is entirely unrelated to the conversation history, with no semantic, topical, or lexical connection to any prior content.
123
+
124
+ 2. *User Attitude Judgment*:
125
+ - Dissatisfied: The feedback shows negative emotions, such as directly pointing out errors, expressing confusion, complaining, criticizing, or explicitly stating that the problem remains unsolved.
126
+ - Satisfied: The feedback shows positive emotions, such as expressing thanks or giving praise.
127
+ - Irrelevant: The content of the feedback is unrelated to evaluating the assistant's answer.
128
+
129
+ 3. *Summary Information Generation*(corrected_info field):
130
+ - Generate a concise list of factual statements that summarize the core information from the user's feedback.
131
+ - When the feedback provides corrections, focus only on the corrected information.
132
+ - When the feedback provides supplements, integrate all valid information (both old and new).
133
+ - It is very important to keep any relevant time information and express time information as concrete, unambiguous date(s) or period(s) (e.g., "March 2023", "2024-07", or "May–June 2022").
134
+ - For 'satisfied' attitude, this list may contain confirming statements or be empty if no new facts are provided.
135
+ - Focus on statement of objective facts. For example: "The user completed the Everest Circuit trek with colleagues in March 2023."
136
+
137
+ Output Format:
138
+ [
139
+ {{
140
+ "validity": "<string, 'true' or 'false'>",
141
+ "user_attitude": "<string, 'dissatisfied' or 'satisfied' or 'irrelevant'>",
142
+ "corrected_info": "<string, factual information records written in English>",
143
+ "key": "<string, anique and concise memory title in English for quick identification of the core content (2-5 words)>",
144
+ "tags": "<A list of relevant thematic keywords in English for categorization and retrieval (1-3 words per tag, e.g., ['deadline', 'team', 'planning'])>"
145
+ }}
146
+ ]
147
+
148
+ Example1:
149
+ Dialogue History:
150
+ user: I can't eat spicy food these days. Can you recommend some suitable restaurants for me?
151
+ assistant: Sure, I recommend the Fish Restaurant near you. Their signature dishes include various types of steamed seafood and sashimi of sea fish.
152
+ feedback time: 2023-1-18T14:25:00.856481
153
+
154
+ User Feedback:
155
+ Oh,No!I'm allergic to seafood!And I don't like eating raw fish.
156
+
157
+ Output:
158
+ [
159
+ {{
160
+ "validity": "true",
161
+ "user_attitude": "dissatisfied",
162
+ "corrected_info": "User is allergic to seafood and does not like eating raw fish.",
163
+ "key": "dietary restrictions",
164
+ "tags": ["allergic", "seafood", "raw fish", "food preference"]
165
+ }}
166
+ ]
167
+
168
+ Example2:
169
+ Dialogue History:
170
+ user: When did I bought on November 25, 2025?
171
+ assistant: A red coat
172
+ feedback time: 2025-11-28T20:45:00.875249
173
+
174
+ User Feedback:
175
+ No, I also bought a blue shirt.
176
+
177
+ Output:
178
+ [
179
+ {{
180
+ "validity": "true",
181
+ "user_attitude": "dissatisfied",
182
+ "corrected_info": "User bought a red coat and a blue shirt on November 25, 2025",
183
+ "key": "shopping record",
184
+ "tags": ["purchase", "clothing", "shopping"]
185
+ }}
186
+ ]
187
+
188
+ Example3:
189
+ Dialogue History:
190
+ user: What's my favorite food?
191
+ assistant: Pizza and sushi
192
+ feedback time: 2024-07-15T10:30:00.000000
193
+
194
+ User Feedback:
195
+ Wrong! I hate sushi. I like burgers.
196
+
197
+ Output:
198
+ [
199
+ {{
200
+ "validity": "true",
201
+ "user_attitude": "dissatisfied",
202
+ "corrected_info": "User likes pizza and burgers, but hates sushi.",
203
+ "key": "food preferences",
204
+ "tags": ["food preferences", "pizza", "burgers", "sushi"]
205
+ }}
206
+ ]
207
+
208
+ Dialogue History:
209
+ {chat_history}
210
+
211
+ feedback time: {feedback_time}
212
+
213
+ User Feedback:
214
+ {user_feedback}
215
+
216
+ Output:"""
217
+
218
+ FEEDBACK_JUDGEMENT_PROMPT_ZH = """您是一个回答质量分析专家。请严格按照以下步骤和标准分析提供的"用户与助手聊天历史"和"用户反馈",并将最终评估结果填入指定的JSON格式中。
219
+
220
+ 分析步骤和标准:
221
+ 1. *有效性判断*:(validity字段)
222
+ - 有效(true):用户反馈的内容与聊天历史中的主题、任务或助手的最后回复相关。例如:提出后续问题、进行纠正、提供补充或评估最后回复。
223
+ - 无效(false):用户反馈与对话历史完全无关,与之前内容没有任何语义、主题或词汇联系。
224
+
225
+ 2. *用户态度判断*:(user_attitude字段)
226
+ - 不满意:反馈显示负面情绪,如直接指出错误、表达困惑、抱怨、批评,或明确表示问题未解决。
227
+ - 满意:反馈显示正面情绪,如表达感谢或给予赞扬。
228
+ - 无关:反馈内容与评估助手回答无关。
229
+
230
+ 3. *摘要信息生成*(corrected_info字段):
231
+ - 从用户反馈中总结核心信息,生成简洁的事实陈述列表。
232
+ - 当反馈提供纠正时,仅关注纠正后的信息。
233
+ - 当反馈提供补充时,整合所有有效信息(包括旧信息和新信息)。
234
+ - 非常重要:保留相关时间信息,并以具体、明确的日期或时间段表达(例如:"2023年3月"、"2024年7月"或"2022年5月至6月")。
235
+ - 对于"满意"态度,此列表可能包含确认性陈述,如果没有提供新事实则为空。
236
+ - 专注于客观事实陈述。例如:"用户于2023年3月与同事完成了珠峰环线徒步。"
237
+
238
+ 输出格式:
239
+ [
240
+ {{
241
+ "validity": "<字符串,'true' 或 'false'>",
242
+ "user_attitude": "<字符串,'dissatisfied' 或 'satisfied' 或 'irrelevant'>",
243
+ "corrected_info": "<字符串,用中文书写的事实信息记录>",
244
+ "key": "<字符串,简洁的中文记忆标题,用于快速识别该条目的核心内容(2-5个汉字)>",
245
+ "tags": "<列表,中文关键词列表(每个标签1-3个汉字),用于分类和检索>"
246
+ }}
247
+ ]
248
+
249
+ 示例1:
250
+ 对话历史:
251
+ 用户:这些天我不能吃辣。能给我推荐一些合适的餐厅吗?
252
+ 助手:好的,我推荐您附近的鱼类餐厅。他们的招牌菜包括各种蒸海鲜和海鱼生鱼片。
253
+ 反馈时间:2023-1-18T14:25:00.856481
254
+
255
+ 用户反馈:
256
+ 哦,不!我对海鲜过敏!而且我不喜欢吃生鱼。
257
+
258
+ 输出:
259
+ [
260
+ {{
261
+ "validity": "true",
262
+ "user_attitude": "dissatisfied",
263
+ "corrected_info": "用户对海鲜过敏且不喜欢吃生鱼",
264
+ "key": "饮食限制",
265
+ "tags": ["过敏", "海鲜", "生鱼", "饮食偏好"]
266
+ }}
267
+ ]
268
+
269
+ 示例2:
270
+ 对话历史:
271
+ 用户:我2025年11月25日买了什么?
272
+ 助手:一件红色外套
273
+ 反馈时间:2025-11-28T20:45:00.875249
274
+
275
+ 用户反馈:
276
+ 不对,我还买了一件蓝色衬衫。
277
+
278
+ 输出:
279
+ [
280
+ {{
281
+ "validity": "true",
282
+ "user_attitude": "dissatisfied",
283
+ "corrected_info": "用户于2025年11月25日购买了一件红色外套和一件蓝色衬衫",
284
+ "key": "购物记录",
285
+ "tags": ["红色外套", "蓝色衬衫", "服装购物"]
286
+ }}
287
+ ]
288
+
289
+ 示例3:
290
+ 对话历史:
291
+ 用户:我最喜欢的食物是什么?
292
+ 助手:披萨和寿司
293
+ 反馈时间:2024-07-15T10:30:00.000000
294
+
295
+ 用户反馈:
296
+ 错了!我讨厌寿司。我喜欢汉堡。
297
+
298
+ 输出:
299
+ [
300
+ {{
301
+ "validity": "true",
302
+ "user_attitude": "dissatisfied",
303
+ "corrected_info": "用户喜欢披萨和汉堡,但讨厌寿司",
304
+ "key": "食物偏好",
305
+ "tags": ["偏好", "披萨和汉堡"]
306
+ }}
307
+ ]
308
+
309
+ 对话历史:
310
+ {chat_history}
311
+
312
+ 反馈时间:{feedback_time}
313
+
314
+ 用户反馈:
315
+ {user_feedback}
316
+
317
+ 输出:"""
318
+
319
+ UPDATE_FORMER_MEMORIES = """Operation recommendations:
320
+ Please analyze the newly acquired factual information and determine how this information should be updated to the memory database: add, update, or keep unchanged, and provide final operation recommendations.
321
+ You must strictly return the response in the following JSON format:
322
+
323
+ {{
324
+ "operations":
325
+ [
326
+ {{
327
+ "id": "<memory ID>",
328
+ "text": "<memory content>",
329
+ "operation": "<operation type, must be one of 'ADD', 'UPDATE', 'NONE'>",
330
+ "old_memory": "<original memory content, required only when operation is 'UPDATE'>"
331
+ }},
332
+ ...
333
+ ]
334
+ }}
335
+
336
+ *Requirements*:
337
+ 1. If the new fact does not provide additional information to the existing memory item, or the existing memory can override the new fact, and the operation is set to "NONE."
338
+ 2. If the new fact is similar to existing memory **about the same entity** but the information is more accurate, complete, or requires correction, set operation to "UPDATE"
339
+ 3. If the new fact contradicts existing memory in key information (such as time, location, status, etc.), update the original memory based on the new fact and set operation to "UPDATE", only modifying the relevant error segments in the existing memory paragraphs while keeping other text completely unchanged.
340
+ 4. If there is no existing memory that requires updating **or if the new fact refers to a different entity**, the new fact is added as entirely new information, and the operation is set to "ADD." Therefore, in the same operation list, ADD and UPDATE will not coexist.
341
+ 5. Facts about different entities that were acknowledged by the user within the same time period can coexist and are not considered contradictory.
342
+
343
+ *ID Management Rules*:
344
+ - Update operation: Keep the original ID unchanged
345
+ - Add operation: Generate a new unique ID in the format of a 4-digit string (e.g., "0001", "0002", etc.)
346
+
347
+ *Important Requirements*:
348
+ 1. For "UPDATE" operations, you must provide the old_memory field to display the original content
349
+ 2. Compare existing memories one by one and do not omit any content requiring updates. When multiple existing memories need updating, include all relevant entries in the operation list
350
+ 3. "text" field requirements:
351
+ - Use concise, complete declarative sentences, avoiding redundant information
352
+ - "text" should record the final adopted memory: if judged as "ADD", output text as "new fact"; if judged as "UPDATE", output text as "adjusted new fact"; if judged as "NONE", output text as "existing memory"
353
+ - When updating, ensure that only the related error segments are modified, and other text remains completely unchanged.
354
+ 4. Both text and old_memory content should be in English
355
+ 5. Return only the JSON format response, without any other content
356
+
357
+
358
+
359
+ Example1:
360
+ Current Memories:
361
+ "0911": "The user is a senior full-stack developer working at Company B"
362
+ "123": "The user works as a software engineer at Company A. And he has a good relationship with his wife."
363
+ "648": "The user is responsible for front-end development of software at Company A"
364
+ "7210": "The user is responsible for front-end development of software at Company A"
365
+ "908": "The user enjoys fishing with friends on weekends"
366
+
367
+ The background of the new fact being put forward:
368
+ user: Do you remember where I work?
369
+ assistant: Company A.
370
+ user feedback: I work at Company B, and I am a senior full-stack developer.
371
+
372
+ Newly facts:
373
+ The user works as a senior full-stack developer at Company B
374
+
375
+ Operation recommendations:
376
+ {{
377
+ "operations":
378
+ [
379
+ {{
380
+ "id": "0911",
381
+ "text": "The user is a senior full-stack developer working at Company B",
382
+ "operation": "NONE"
383
+ }},
384
+ {{
385
+ "id": "123",
386
+ "text": "The user works as a senior full-stack developer at Company B. And he has a good relationship with his wife.",
387
+ "operation": "UPDATE",
388
+ "old_memory": "The user works as a software engineer at Company A. And he has a good relationship with his wife."
389
+ }},
390
+ {{
391
+ "id": "648",
392
+ "text": "The user works as a senior full-stack developer at Company B",
393
+ "operation": "UPDATE",
394
+ "old_memory": "The user is responsible for front-end development of software at Company A"
395
+ }},
396
+ {{
397
+ "id": "7210",
398
+ "text": "The user works as a senior full-stack developer at Company B",
399
+ "operation": "UPDATE",
400
+ "old_memory": "The user is responsible for front-end development of software at Company A"
401
+ }},
402
+ {{
403
+ "id": "908",
404
+ "text": "The user enjoys fishing with friends on weekends",
405
+ "operation": "NONE"
406
+ }}
407
+ ]
408
+ }}
409
+
410
+ Example2:
411
+ Current Memories:
412
+ "123": "On December 22, 2025, the user claim that John works at Company X"
413
+ "908": "On December 22, 2025, the user claim that Mary lives in New York"
414
+
415
+ The background of the new fact being put forward:
416
+ user: Guess who am I?
417
+ assistant: You are a teacher at School ABC.
418
+ user feedback: No, I mean Peter is a teacher at School ABC.
419
+
420
+ Newly facts:
421
+ "Peter is a teacher at School ABC."
422
+
423
+ Operation recommendations:
424
+ {{
425
+ "operations":
426
+ [
427
+ {{
428
+ "id": "123",
429
+ "text": "On December 22, 2025, the user claim that John works at Company X",
430
+ "operation": "NONE"
431
+ }},
432
+ {{
433
+ "id": "908",
434
+ "text": "On December 22, 2025, the user claim that Mary lives in New York",
435
+ "operation": "NONE"
436
+ }},
437
+ {{
438
+ "id": "001",
439
+ "text": "Peter is a teacher at School ABC.",
440
+ "operation": "ADD"
441
+ }}
442
+ ]
443
+ }}
444
+
445
+ **Current time**
446
+ {now_time}
447
+
448
+ **Current Memories**
449
+ {current_memories}
450
+
451
+ **The background of the new fact being put forward**
452
+ {chat_history}
453
+
454
+ **Newly facts**
455
+ {new_facts}
456
+
457
+ Operation recommendations:
458
+ """
459
+
460
+ UPDATE_FORMER_MEMORIES_ZH = """请分析新获取的事实信息,并决定这些信息应该如何更新到记忆库中:新增、更新、或保持不变,并给出最终的操作建议。
461
+
462
+ 你必须严格按照以下JSON格式返回响应:
463
+
464
+ {{
465
+ "operations":
466
+ [
467
+ {{
468
+ "id": "<记忆ID>",
469
+ "text": "<记忆内容>",
470
+ "operation": "<操作类型,必须是 "ADD", "UPDATE", "NONE" 之一>",
471
+ "old_memory": "<原记忆内容,仅当操作为"UPDATE"时需要提供>"
472
+ }},
473
+ ...
474
+ ]
475
+ }}
476
+
477
+ 要求:
478
+ 1. 若新事实未对现有记忆条目提供额外信息,现有记忆可覆盖新事实,操作设为"NONE"
479
+ 2. 若新事实与现有记忆相似但信息更准确、完整或需修正,操作设为"UPDATE"
480
+ 3. 若新事实在关键信息(如时间、地点、状态等)上与现有记忆矛盾,则根据新事实更新原记忆,操作设为"UPDATE",仅修改现有记忆段落中的相关错误片段,其余文本完全保持不变
481
+ 4. 若无需要更新的现有记忆,则将新事实作为全新信息添加,操作设为"ADD"。因此在同一操作列表中,ADD与UPDATE不会同时存在
482
+ 5. 同一时间段内用户所确认的不同实体的相关事实可以并存,且不会被视作相互矛盾。
483
+
484
+ ID管理规则:
485
+ - 更新操作:保持原有ID不变
486
+ - 新增操作:生成新的唯一ID,格式为4位数字字符串(如:"0001", "0002"等)
487
+
488
+ 重要要求:
489
+ 1. 对于"UPDATE"更新操作,必须提供old_memory字段显示原内容
490
+ 2. 对现有记忆逐一比对,不可漏掉需要更新的内容。当多个现有记忆需要更新时,将所有的相关条目都包含在操作列表中
491
+ 3. text字段要求:
492
+ - 使用简洁、完整的陈述句,避免冗余信息
493
+ - text要记录最终采用的记忆,如果判为"ADD",则text输出为"新事实";如果判为"UPDATE",则text输出为"调整后的新事实";如果判为"NONE",则text输出为"现有记忆"
494
+ - 更新时确保仅修改相关错误片段,其余文本完全保持不变
495
+ 4. text和old_memory内容使用中文
496
+ 5. 只返回JSON格式的响应,不要包含其他任何内容
497
+
498
+
499
+ 示例1:
500
+ 当前记忆:
501
+ "0911": "用户是高级全栈开发工程师,在B公司工作"
502
+ "123": "用户在公司A担任软件工程师。而且用户和同事们的关系很好,他们共同协作大项目。"
503
+ "648": "用户在公司A负责软件的前端开发工作"
504
+ "7210": "用户在公司A负责软件的前端开发工作"
505
+ "908": "用户周末喜欢和朋友一起钓鱼"
506
+
507
+
508
+ 提出新事实的背景:
509
+ user: 你还记得我现在在哪里工作吗?
510
+ assistant: A公司
511
+ user feedback: 实际上,我在公司B工作,是一名高级全栈开发人员。
512
+
513
+
514
+ 新获取的事实:
515
+ "用户现在在公司B担任高级全栈开发工程师"
516
+
517
+ 操作建议:
518
+ {{
519
+ "operations":
520
+ [
521
+ {{
522
+ "id": "0911",
523
+ "text": "用户是高级全栈开发工程师,在B公司工作",
524
+ "operation": "NONE"
525
+ }},
526
+ {{
527
+ "id": "123",
528
+ "text": "用户现在在公司B担任高级全栈开发工程师。而且用户和同事们的关系很好,他们共同协作大项目。",
529
+ "operation": "UPDATE",
530
+ "old_memory": "用户在公司A担任软件工程师,主要负责前端开发。而且用户和同事们的关系很好,他们共同协作大项目。"
531
+ }},
532
+ {{
533
+ "id": "648",
534
+ "text": "用户现在在公司B担任高级全栈开发工程师",
535
+ "operation": "UPDATE",
536
+ "old_memory": "用户在公司A负责软件的前端开发工作"
537
+ }},
538
+ {{
539
+ "id": "7210",
540
+ "text": "用户现在在公司B担任高级全栈开发工程师",
541
+ "operation": "UPDATE",
542
+ "old_memory": "用户在公司A负责软件的前端开发工作"
543
+ }},
544
+ {{
545
+ "id": "908",
546
+ "text": "用户周末喜欢和朋友一起钓鱼",
547
+ "operation": "NONE"
548
+ }}
549
+ ]
550
+ }}
551
+
552
+ 示例2:
553
+ 当前记忆:
554
+ "123": "2025年12月12日,用户声明约翰在 X 公司工作"
555
+ "908": "2025年12月12日,用户声明玛丽住在纽约"
556
+
557
+ 提出新事实的背景:
558
+ user: 猜猜刘青住在哪里?
559
+ assistant: 合欢社区
560
+ user feedback: 错了,他住在明月小区
561
+
562
+ 新获取的事实:
563
+ "用户声明刘青住在明月小区"
564
+
565
+ 操作建议:
566
+ {{
567
+ "operations":
568
+ [
569
+ {{
570
+ "id": "123",
571
+ "text": "用户在公司A担任软件工程师,主要负责前端开发",
572
+ "operation": "NONE"
573
+ }},
574
+ {{
575
+ "id": "908",
576
+ "text": "用户周末喜欢和朋友一起钓鱼",
577
+ "operation": "NONE"
578
+ }},
579
+ {{
580
+ "id": "4567",
581
+ "text": "用户声明刘青住在明月小区",
582
+ "operation": "ADD"
583
+ }}
584
+ ]
585
+ }}
586
+
587
+ **当前时间:**
588
+ {now_time}
589
+
590
+ **当前记忆:**
591
+ {current_memories}
592
+
593
+ **新事实提出的背景:**
594
+ {chat_history}
595
+
596
+ **新事实:**
597
+ {new_facts}
598
+
599
+ 操作建议:
600
+ """
601
+
602
+
603
+ FEEDBACK_ANSWER_PROMPT = """
604
+ You are a knowledgeable and helpful AI assistant.You have access to the history of the current conversation. This history contains the previous exchanges between you and the user.
605
+
606
+ # INSTRUCTIONS:
607
+ 1. Carefully analyze the entire conversation history. Your answer must be based only on the information that has been exchanged within this dialogue.
608
+ 2. Pay close attention to the sequence of the conversation. If the user refers back to a previous statement (e.g., "the thing I mentioned earlier"), you must identify that specific point in the history.
609
+ 3. Your primary goal is to provide continuity and context from this specific conversation. Do not introduce new facts or topics that have not been previously discussed.
610
+ 4. If current question is ambiguous, use the conversation history to clarify its meaning.
611
+
612
+ # APPROACH (Think step by step):
613
+ 1. Review the conversation history to understand the context and topics that have been discussed.
614
+ 2. Identify any specific details, preferences, or statements the user has made that are relevant to the current question.
615
+ 3. Formulate a precise, concise answer that is a direct continuation of the existing dialogue.
616
+ 4. Ensure your final answer is grounded in the conversation history and directly addresses the user's latest query in that context.
617
+
618
+ # Tip:
619
+ If no chat history is provided:
620
+  - Treat the query as self-contained.
621
+  - Do not assume prior context.
622
+  - Respond based solely on the current question.
623
+ - Do not raise new questions during the answering process.
624
+
625
+ Chat history:
626
+ {chat_history}
627
+
628
+ Question:
629
+ {question}
630
+
631
+ Answer:
632
+ """
633
+
634
+ FEEDBACK_ANSWER_PROMPT_ZH = """
635
+ 你是一个知识渊博且乐于助人的AI助手。你可以访问当前对话的完整历史记录。这些记录包含你与用户之间先前的所有交流内容。
636
+
637
+ # 指令:
638
+ 1. 仔细分析整个对话历史。你的回答必须仅基于本次对话中已交流的信息。
639
+ 2. 密切关注对话的先后顺序。如果用户提及之前的发言(例如“我之前提到的那件事”),你必须定位到历史记录中的具体内容。
640
+ 3. 你的主要目标是基于本次特定对话提供连续性和上下文。不要引入之前对话中未讨论过的新事实或话题。
641
+ 4. 如果用户当前的问题含义不明确,请利用对话历史来澄清其意图。
642
+
643
+ # 处理方法(逐步思考):
644
+ 1. 回顾对话历史,以理解已讨论的背景和主题。
645
+ 2. 识别用户已提及的、与当前问题相关的任何具体细节、偏好或陈述。
646
+ 3. 构思一个精准、简洁的回答,使其成为现有对话的直接延续。
647
+ 4. 确保你的最终回答紧扣对话历史,并在此上下文中直接回应用户的最新提问。
648
+
649
+ # 注意:
650
+ 如果没有提供聊天历史记录:
651
+ - 将该查询视为独立的。
652
+ - 不要假设之前存在背景信息。
653
+ - 仅根据当前问题进行回答。
654
+ - 在回答过程中不必提出新的问题。
655
+
656
+ 对话历史:
657
+ {chat_history}
658
+
659
+ 问题:
660
+ {question}
661
+
662
+ 回答:
663
+ """
664
+
665
+
666
+ OPERATION_UPDATE_JUDGEMENT = """
667
+ # Batch UPDATE Safety Assessment Instruction
668
+
669
+ **Background**:
670
+ This instruction serves as a supplementary safety verification layer for the memory update instruction. It evaluates each UPDATE operation in the `operations` list to ensure safety and effectiveness, preventing erroneous data overwrites.
671
+
672
+ **Input**: The `operations` list containing multiple UPDATE proposals generated by the main instruction
673
+ **Output**: The final `operations_judgement` list after safety assessment and necessary corrections
674
+
675
+ **Safety Assessment Process (for each UPDATE entry)**:
676
+ 1. **Entity Consistency Check**: Verify that the old and new texts of this UPDATE entry describe exactly the same core entity (same person, organization, event, etc.). This is the most important check.
677
+ 2. **Semantic Relevance Check**: Determine whether the new information directly corrects errors in or supplements missing information from the old information, rather than introducing completely unrelated new facts.
678
+ 3. **Context Preservation Check**: Ensure that the updated text of this UPDATE only modifies the parts that need correction, while completely preserving all other valid information from the original text.
679
+
680
+ **Batch Assessment Rules**:
681
+ - Independently assess each entry in the list and record the evaluation results
682
+
683
+ **Key Decision Rules**:
684
+ 1. If the core entities of old and new texts are different → Set `judgement` to "INVALID" (completely invalid)
685
+ 2. If the core entities are the same but the information is completely unrelated → Set `judgement` to "NONE" (should not update)
686
+ 3. If all three checks pass → Set `judgement` to "UPDATE_APPROVED"
687
+
688
+ **Output Format**:
689
+ {{
690
+ "operations_judgement": [
691
+ {{
692
+ "id": "...",
693
+ "text": "...",
694
+ "old_memory": "...",
695
+ "judgement": "INVALID" | "NONE" | "UPDATE_APPROVED"
696
+ }},
697
+ ...
698
+ ]
699
+ }}
700
+
701
+ **Example 1**:
702
+ Input operations list:
703
+ {{
704
+ "operations": [
705
+ {{
706
+ "id": "275a",
707
+ "text": "On December 22, 2025 at 6:58 AM UTC, the user mentioned that Mission Terra is from Germany.",
708
+ "operation": "UPDATE",
709
+ "old_memory": "On December 13, 2025 at 4:02 PM UTC, the user mentioned that Mission Terra is a French national."
710
+ }},
711
+ {{
712
+ "id": "88a4",
713
+ "text": "On December 22, 2025 at 6:58 AM UTC, the user mentioned that Mission Terra is from Germany.",
714
+ "operation": "UPDATE",
715
+ "old_memory": "On December 22, 2025 at 6:52 AM UTC, the user confirmed that Gladys Liu is an Italian citizen."
716
+ }}
717
+ ]
718
+ }}
719
+
720
+ Safety assessment output:
721
+ {{
722
+ "operations_judgement": [
723
+ {{
724
+ "id": "275a",
725
+ "text": "On December 22, 2025 at 6:58 AM UTC, the user mentioned that Mission Terra is from Germany.",
726
+ "old_memory": "On December 13, 2025 at 4:02 PM UTC, the user mentioned that Mission Terra is a French national.",
727
+ "judgement": "UPDATE_APPROVED"
728
+ }},
729
+ {{
730
+ "id": "88a4",
731
+ "text": "On December 22, 2025 at 6:58 AM UTC, the user mentioned that Mission Terra is from Germany.",
732
+ "old_memory": "On December 22, 2025 at 6:52 AM UTC, the user confirmed that Gladys Liu is an Italian citizen.",
733
+ "judgement": "INVALID"
734
+ }}
735
+ ]
736
+ }}
737
+
738
+ **For actual execution**:
739
+ Input operations list:
740
+ {raw_operations}
741
+
742
+ Safety assessment output:"""
743
+
744
+
745
+ OPERATION_UPDATE_JUDGEMENT_ZH = """## 批量UPDATE安全评估指令
746
+
747
+ **背景说明**:
748
+ 本指令作为记忆更新指令的补充安全验证层。针对`operations`列表,评估每个UPDATE操作都安全有效,防止错误的数据覆盖。
749
+
750
+ **输入**:主指令生成的包含多个UPDATE提议的`operations`列表
751
+ **输出**:经过安全评估和必要修正后的最终`operations_judgement`列表
752
+
753
+ **安全评估流程(针对每个UPDATE条目)**:
754
+ 1. **实体一致性检查**:确认该UPDATE条目的新旧文本是否描述完全相同的核心实体(同一人物、组织、事件等)。这是最重要的检查。
755
+ 2. **语义相关性检查**:判断该UPDATE的新信息是否直接修正旧信息中的错误部分或补充缺失信息,而非引入完全不相关的新事实。
756
+ 3. **上下文保留检查**:确保该UPDATE更新后的文本只修改需要纠正的部分,完全保留原始文本中其他所有有效信息。
757
+
758
+ **批量评估规则**:
759
+ - 对列表中的每个条目独立评估,记录评估结果
760
+
761
+ **关键决策规则**:
762
+ 1. 如果新旧文本核心实体不同 → `judgement`置为"INVALID"(完全无效)
763
+ 2. 如果新旧文本核心实体相同但信息完全不相关 → `judgement`置为"NONE"(不应更新)
764
+ 3. 如果通过全部三项检查 → `judgement`置为"UPDATE_APPROVED"
765
+
766
+
767
+ **输出格式**:
768
+ {{
769
+ "operations_judgement": [
770
+ // 评估后的完整operations列表
771
+ {{
772
+ "id": "...",
773
+ "text": "...",
774
+ "old_memory": "...",
775
+ "judgement": "INVALID" | "NONE" | "UPDATE_APPROVED"
776
+ }},
777
+ ...
778
+ ]
779
+ }}
780
+
781
+
782
+ 示例1:
783
+ 输入operations列表:
784
+ {{
785
+ "operations": [
786
+ {{
787
+ "id": "275a",
788
+ "text": "2025年12月22日 UTC 时间6:58,用户提到Mission Terra 来自德国。",
789
+ "operation": "UPDATE",
790
+ "old_memory": "2025年12月13日 UTC 时间16:02,用户提及 Mission Terra 是法国国籍。"
791
+ }},
792
+ {{
793
+ "id": "88a4",
794
+ "text": "2025年12月22日 UTC 时间6:58,用户提到Mission Terra 来自德国。",
795
+ "operation": "UPDATE",
796
+ "old_memory": "2025年12月22日 UTC 时间6:52,用户确认 Gladys Liu 是意大利公民。"
797
+ }}
798
+ ]
799
+ }}
800
+ 安全评估输出:
801
+ {{
802
+ "operations_judgement": [
803
+ {{
804
+ "id": "275a",
805
+ "text": "2025年12月22日 UTC 时间6:58,用户提到Mission Terra 来自德国。",
806
+ "old_memory": "2025年12月13日 UTC 时间16:02,用户提及 Mission Terra 是法国国籍。",
807
+ "judgement": "UPDATE_APPROVED"
808
+ }},
809
+ {{
810
+ "id": "88a4",
811
+ "text": "2025年12月22日 UTC 时间6:58,用户提到Mission Terra 来自德国。",
812
+ "old_memory": "2025年12月22日 UTC 时间6:52,用户确认 Gladys Liu 是意大利公民。",
813
+ "judgement": "INVALID"
814
+ }}
815
+ ]
816
+ }}
817
+
818
+ 输入operations列表:
819
+ {raw_operations}
820
+
821
+ 安全评估输出:
822
+ """