amrita_plugin_memory 0.2.4__tar.gz → 0.2.6__tar.gz

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 (27) hide show
  1. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/PKG-INFO +1 -1
  2. amrita_plugin_memory-0.2.6/amrita_plugin_memory/rethinking/__init__.py +13 -0
  3. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/rethinking/_state.py +8 -0
  4. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/rethinking/runner.py +12 -12
  5. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/rethinking/tools.py +28 -11
  6. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/tools.py +12 -4
  7. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory.egg-info/PKG-INFO +1 -1
  8. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/pyproject.toml +1 -1
  9. amrita_plugin_memory-0.2.4/amrita_plugin_memory/rethinking/__init__.py +0 -20
  10. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/LICENSE +0 -0
  11. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/README.md +0 -0
  12. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/__init__.py +0 -0
  13. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/config.py +0 -0
  14. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/embed.py +0 -0
  15. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/matchers.py +0 -0
  16. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/rethinking/backend.py +0 -0
  17. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/rethinking/consts.py +0 -0
  18. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/rethinking/hooks.py +0 -0
  19. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/rethinking/nodes.py +0 -0
  20. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/rethinking/schemas.py +0 -0
  21. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/rethinking/workflow.py +0 -0
  22. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory/vector.py +0 -0
  23. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory.egg-info/SOURCES.txt +0 -0
  24. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory.egg-info/dependency_links.txt +0 -0
  25. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory.egg-info/requires.txt +0 -0
  26. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/amrita_plugin_memory.egg-info/top_level.txt +0 -0
  27. {amrita_plugin_memory-0.2.4 → amrita_plugin_memory-0.2.6}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amrita_plugin_memory
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Amrita长期记忆插件
5
5
  Requires-Python: <3.14,>=3.10
6
6
  Description-Content-Type: text/markdown
@@ -0,0 +1,13 @@
1
+ """潜意识推理循环(rethinking"""
2
+
3
+ from . import _state, backend, hooks, nodes, schemas, tools, workflow
4
+
5
+ __all__ = [
6
+ "_state",
7
+ "backend",
8
+ "hooks",
9
+ "nodes",
10
+ "schemas",
11
+ "tools",
12
+ "workflow",
13
+ ]
@@ -4,6 +4,8 @@ from __future__ import annotations
4
4
 
5
5
  from typing import TYPE_CHECKING, Any
6
6
 
7
+ from amrita.plugins.chat.config import config_manager
8
+ from amrita_core import ModelPreset
7
9
  from amrita_core.tools.manager import MultiToolsManager
8
10
 
9
11
  if TYPE_CHECKING:
@@ -15,6 +17,12 @@ _pending_messages: list[dict[str, Any]] = []
15
17
  _SUBCONSCIOUS_TOOLS = MultiToolsManager()
16
18
 
17
19
 
20
+ async def get_preset() -> ModelPreset:
21
+ return await config_manager.get_preset(
22
+ (await config_manager.safe_get_config()).preset
23
+ )
24
+
25
+
18
26
  def get_runner() -> SubconsciousRunner | None:
19
27
  return _runner
20
28
 
@@ -16,7 +16,7 @@ from amrita_core.base.backend import BackendSlots
16
16
  from amrita_core.builtins.agent import ReActAgentStrategy
17
17
  from amrita_core.chatmanager import ChatObject
18
18
  from amrita_core.config import get_config
19
- from amrita_core.preset import PresetManager
19
+ from amrita_core.preset import ModelPreset
20
20
  from amrita_core.types import Message, UniResponseUsage
21
21
  from amrita_core.utils import gather_usage
22
22
  from amrita_sense import WorkflowInterpreter
@@ -123,18 +123,13 @@ class SubconsciousRunner:
123
123
  self._is_running = True
124
124
  self._iter_stop_result = {}
125
125
 
126
- preset = PresetManager().get_default_preset()
126
+ preset = await _state.get_preset()
127
127
  prompt_text = await self._load_prompt()
128
128
  user_msg_text = (
129
129
  f"现在是第 {self._total_runs + 1} 次潜意识推理循环。"
130
130
  f"请检查用户 (ID: {self._config.target_user_id}) 的记忆库,执行必要的整理操作。"
131
131
  f"完成后务必调用 subconscious_iter_stop。"
132
132
  )
133
- if self._is_native_thinking():
134
- user_msg_text += (
135
- " (注意:你的模型启用了内置思考模式,请务必调用 think_and_reason。)"
136
- )
137
-
138
133
  train = Message(role="system", content=prompt_text)
139
134
  user_input = user_msg_text
140
135
 
@@ -170,7 +165,9 @@ class SubconsciousRunner:
170
165
  chat_obj.begin()
171
166
  await chat_obj
172
167
  except Exception as e:
173
- logger.error(f"[EXP Subconscious] Error: {e}", exc_info=True)
168
+ logger.opt(exception=e, colors=True, raw=True).exception(
169
+ f"[EXP Subconscious] Error: {e}"
170
+ )
174
171
  finally:
175
172
  self._chat_obj = None
176
173
  self._is_running = False
@@ -179,8 +176,7 @@ class SubconsciousRunner:
179
176
  await self._post_process(chat_obj)
180
177
 
181
178
  @staticmethod
182
- def _is_native_thinking() -> bool:
183
- preset = PresetManager().get_default_preset()
179
+ def _is_native_thinking(preset: ModelPreset) -> bool:
184
180
  return (
185
181
  preset.thinking_config is not None
186
182
  and preset.thinking_config.thinking_type == "enabled"
@@ -314,7 +310,9 @@ class SubconsciousRunner:
314
310
  )
315
311
  await repo.update_memory_data(mem)
316
312
  except Exception as e:
317
- logger.error(f"[EXP Subconscious] Save to repo failed: {e}")
313
+ logger.opt(exception=e, colors=True, raw=True).exception(
314
+ f"[EXP Subconscious] Save to repo failed: {e}"
315
+ )
318
316
 
319
317
  async def _save_pending_to_repo(self) -> None:
320
318
  """持久化待发送消息到 CachedUserDataRepository 的 extra_prompt 中。"""
@@ -331,7 +329,9 @@ class SubconsciousRunner:
331
329
  mem.extra_prompt = json.dumps(existing, ensure_ascii=False)
332
330
  await repo.update_memory_data(mem)
333
331
  except Exception as e:
334
- logger.error(f"[EXP Subconscious] Save pending failed: {e}")
332
+ logger.opt(exception=e, colors=True, raw=True).exception(
333
+ f"[EXP Subconscious] Save pending failed: {e}"
334
+ )
335
335
 
336
336
  # Prompt 加载
337
337
 
@@ -8,7 +8,6 @@ from typing import Any
8
8
 
9
9
  from amrita_core import on_tools
10
10
  from amrita_core.libchat import call_completion, get_last_response
11
- from amrita_core.preset import PresetManager
12
11
  from amrita_core.types import CONTENT_LIST_TYPE, Message
13
12
  from chromadb import GetResult
14
13
  from jinja2 import Template
@@ -81,7 +80,9 @@ async def subconscious_read_memory(data: dict[str, Any]) -> str:
81
80
  )
82
81
  return json.dumps(result, ensure_ascii=False, indent=2, default=str)
83
82
  except Exception as e:
84
- logger.error(f"subconscious_read_memory error: {e}")
83
+ logger.opt(exception=e, colors=True, raw=True).exception(
84
+ f"subconscious_read_memory error: {e}"
85
+ )
85
86
  return _tools_err(str(e))
86
87
 
87
88
 
@@ -99,7 +100,9 @@ async def subconscious_write_memory(data: dict[str, Any]) -> str:
99
100
  await ope.add_note(pid, str(data["content"]), metadata=meta)
100
101
  return _tools_ok(id=meta.memory_id)
101
102
  except Exception as e:
102
- logger.error(f"subconscious_write_memory error: {e}")
103
+ logger.opt(exception=e, colors=True, raw=True).exception(
104
+ f"subconscious_write_memory error: {e}"
105
+ )
103
106
  return _tools_err(str(e))
104
107
 
105
108
 
@@ -146,7 +149,9 @@ async def subconscious_update_memory(data: dict[str, Any]) -> str:
146
149
  await ope.update_note(pid, new_content, metadata=meta)
147
150
  return _tools_ok(message="记忆更新成功", id=mem_id)
148
151
  except Exception as e:
149
- logger.error(f"subconscious_update_memory error: {e}")
152
+ logger.opt(exception=e, colors=True, raw=True).exception(
153
+ f"subconscious_update_memory error: {e}"
154
+ )
150
155
  return _tools_err(str(e))
151
156
 
152
157
 
@@ -166,7 +171,9 @@ async def subconscious_delete_memory(data: dict[str, Any]) -> str:
166
171
  await ope.delete_note(pid, mem_id)
167
172
  return _tools_ok(message="记忆删除成功", id=mem_id)
168
173
  except Exception as e:
169
- logger.error(f"subconscious_delete_memory error: {e}")
174
+ logger.opt(exception=e, colors=True, raw=True).exception(
175
+ f"subconscious_delete_memory error: {e}"
176
+ )
170
177
  return _tools_err(str(e))
171
178
 
172
179
 
@@ -203,7 +210,9 @@ async def subconscious_list_memory(data: dict[str, Any]) -> str:
203
210
  )
204
211
  return _tools_ok(memories=memories, total=len(ids))
205
212
  except Exception as e:
206
- logger.error(f"subconscious_list_memory error: {e}")
213
+ logger.opt(exception=e, colors=True, raw=True).exception(
214
+ f"subconscious_list_memory error: {e}"
215
+ )
207
216
  return _tools_err(str(e))
208
217
 
209
218
 
@@ -236,7 +245,9 @@ async def subconscious_send_to_user(data: dict[str, Any]) -> str:
236
245
  try:
237
246
  content = await _generate_send_content(intent, memory_context)
238
247
  except Exception as e:
239
- logger.error(f"[EXP Subconscious] Generate send content failed: {e}")
248
+ logger.opt(exception=e, colors=True, raw=True).exception(
249
+ f"[EXP Subconscious] Generate send content failed: {e}"
250
+ )
240
251
  return _tools_err(str(e))
241
252
  ts = datetime.now(timezone.utc).isoformat()
242
253
  pending = _state.get_pending()
@@ -272,7 +283,9 @@ async def subconscious_read_chat_context(data: dict[str, Any]) -> str:
272
283
  indent=2,
273
284
  )
274
285
  except Exception as e:
275
- logger.error(f"subconscious_read_chat_context error: {e}")
286
+ logger.opt(exception=e, colors=True, raw=True).exception(
287
+ f"subconscious_read_chat_context error: {e}"
288
+ )
276
289
  return _tools_err(str(e))
277
290
 
278
291
 
@@ -294,7 +307,7 @@ async def _generate_send_content(intent: str, memory_context: str) -> str:
294
307
  current_time=datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S UTC"),
295
308
  character_prompt=character_prompt,
296
309
  )
297
- preset = PresetManager().get_default_preset()
310
+ preset = await _state.get_preset()
298
311
  messages: CONTENT_LIST_TYPE = [
299
312
  Message(role="system", content=system_content),
300
313
  Message(
@@ -386,7 +399,9 @@ async def subconscious_duplicate_helper(data: dict[str, Any]) -> str:
386
399
  memories=items,
387
400
  )
388
401
  except Exception as e:
389
- logger.error(f"subconscious_duplicate_helper error: {e}")
402
+ logger.opt(exception=e, colors=True, raw=True).exception(
403
+ f"subconscious_duplicate_helper error: {e}"
404
+ )
390
405
  return _tools_err(str(e))
391
406
 
392
407
 
@@ -444,5 +459,7 @@ async def subconscious_get_memory_stats(data: dict[str, Any]) -> str:
444
459
  avg_length=total_length // len(ids) if ids else 0,
445
460
  )
446
461
  except Exception as e:
447
- logger.error(f"subconscious_get_memory_stats error: {e}")
462
+ logger.opt(exception=e, colors=True, raw=True).exception(
463
+ f"subconscious_get_memory_stats error: {e}"
464
+ )
448
465
  return _tools_err(str(e))
@@ -245,7 +245,9 @@ async def r(ctx: ToolContext) -> str:
245
245
  )
246
246
  return json.dumps(res, ensure_ascii=False, indent=4)
247
247
  except Exception as e:
248
- logger.error(f"检索记忆时发生错误: {e}")
248
+ logger.opt(exception=e, colors=True, raw=True).exception(
249
+ f"检索记忆时发生错误: {e}"
250
+ )
249
251
  return _err(f"检索记忆失败: {e!s}")
250
252
 
251
253
 
@@ -317,7 +319,9 @@ async def update_memory(ctx: ToolContext) -> str:
317
319
 
318
320
  return _ok(message="记忆更新成功", id=ctx.data["id"])
319
321
  except Exception as e:
320
- logger.error(f"更新记忆时发生错误: {e}")
322
+ logger.opt(exception=e, colors=True, raw=True).exception(
323
+ f"更新记忆时发生错误: {e}"
324
+ )
321
325
  return _err(f"更新记忆失败: {e!s}")
322
326
 
323
327
 
@@ -349,7 +353,9 @@ async def delete_memory(ctx: ToolContext) -> str:
349
353
  await ope.delete_note(partition_id, ctx.data["id"])
350
354
  return _ok(message="记忆删除成功", id=ctx.data["id"])
351
355
  except Exception as e:
352
- logger.error(f"删除记忆时发生错误: {e}")
356
+ logger.opt(exception=e, colors=True, raw=True).exception(
357
+ f"删除记忆时发生错误: {e}"
358
+ )
353
359
  return _err(f"删除记忆失败: {e!s}")
354
360
 
355
361
 
@@ -400,5 +406,7 @@ async def list_memory(ctx: ToolContext) -> str:
400
406
 
401
407
  return _ok(memories=memories, total=len(ids))
402
408
  except Exception as e:
403
- logger.error(f"列出记忆时发生错误: {e}")
409
+ logger.opt(exception=e, colors=True, raw=True).exception(
410
+ f"列出记忆时发生错误: {e}"
411
+ )
404
412
  return _err(f"列出记忆失败: {e!s}")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: amrita_plugin_memory
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: Amrita长期记忆插件
5
5
  Requires-Python: <3.14,>=3.10
6
6
  Description-Content-Type: text/markdown
@@ -1,7 +1,7 @@
1
1
  [project]
2
2
  name = "amrita_plugin_memory"
3
3
  description = "Amrita长期记忆插件"
4
- version = "0.2.4"
4
+ version = "0.2.6"
5
5
  dependencies = [
6
6
  "aiohttp>=3.13.3",
7
7
  "aiologic>=0.16.0",
@@ -1,20 +0,0 @@
1
- """潜意识推理循环(rethinking 子包)。
2
-
3
- 导入此包时触发工具注册和 hook 注册。
4
- 注意:避免模块级导入 tools/runner 等会触发循环导入的子模块。
5
- 这些模块的副作用(@on_tools 注册、hook 注册)通过 hooks 和 tools 内部的延迟导入自动生效。
6
- """
7
-
8
- from . import _state, backend, hooks, nodes, schemas, workflow
9
-
10
- __all__ = [
11
- "_state",
12
- "backend",
13
- "consts",
14
- "hooks",
15
- "nodes",
16
- "runner",
17
- "schemas",
18
- "tools",
19
- "workflow",
20
- ]