yaovi_memory.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """Embedded memory lifecycle: workspace documents in user mode, native provider in peer mode.
  2. Authorized workspace shared knowledge remains in the control-plane prompt. The
  3. native OpenViking provider owns private peer capture, recall and session commits.
  4. """
  5. class WorkspaceMemoryStore:
  6. def load_from_disk(self):
  7. pass
  8. def format_for_system_prompt(self, target):
  9. return None # the frozen workspace prompt contains this snapshot
  10. def reset_consolidation_failures(self):
  11. pass
  12. def initialize(agent, config, skip_memory, platform='yaovi'):
  13. from agent.runtime_context import current
  14. if current() is None:
  15. return False
  16. memory = config.get("memory", {})
  17. enabled = memory.get("enabled", True) and not skip_memory
  18. agent._memory_store = WorkspaceMemoryStore() if enabled else None
  19. agent._memory_manager = None
  20. agent._memory_enabled = enabled
  21. agent._user_profile_enabled = enabled
  22. agent._memory_nudge_interval = 10 if memory.get("automatic", True) else 0
  23. agent._turns_since_memory = 0
  24. agent._iters_since_skill = 0
  25. identity = current().get("nativeMemory")
  26. if enabled and identity:
  27. agent._memory_nudge_interval = 0
  28. from agent.memory_manager import MemoryManager, inject_memory_provider_tools
  29. from agent.agent_init import _memory_provider_init_kwargs
  30. from native_openviking import YaoviOpenVikingProvider
  31. manager = MemoryManager()
  32. provider = YaoviOpenVikingProvider(identity, automatic=memory.get("automatic", True), recall=memory.get("recall", True))
  33. manager.add_provider(provider)
  34. kwargs = _memory_provider_init_kwargs(agent, platform)
  35. if current().get("review"):
  36. kwargs["agent_context"] = "flush"
  37. manager.initialize_all(**kwargs)
  38. agent._memory_manager = manager
  39. inject_memory_provider_tools(agent)
  40. return True