FinceptTerminal is a modern finance application offering advanced market analytics, investment research, and economic data tools, designed for interactive exploration and data-driven decision-making in a user-friendly environment.
C++ ai-agentsalgorithmic-tradingbloomberg-terminalcppfinancefinancial-marketsfintechgood-first-issueinvestmentinvestment-researchmachine-learningopensourcepythonqtquantitative-financestock-markettrading
feat(finagent): key AgenticMemoryModule by (user_id, agent_id)
tilakpatel2265a5fef9d29d
diff --git a/fincept-qt/scripts/agents/finagent_core/modules/memory_module.py b/fincept-qt/scripts/agents/finagent_core/modules/memory_module.pyindex ad4c26f09..9cfb0be3e 100644--- a/fincept-qt/scripts/agents/finagent_core/modules/memory_module.py+++ b/fincept-qt/scripts/agents/finagent_core/modules/memory_module.py@@ -313,6 +313,7 @@ class AgenticMemoryModule:def __init__(self,user_id: str,+ agent_id: str,db_path: Optional[str] = None,enable_auto_store: bool = True,max_memories: int = 1000@@ -326,8 +327,12 @@ class AgenticMemoryModule:enable_auto_store: Allow agent to auto-storemax_memories: Maximum memories to keep"""+ from finagent_core import resourcesself.user_id = user_id- self.db_path = db_path or f"./memories_{user_id}.db"+ self.agent_id = agent_id+ self.db_path = db_path or resources.agentic_memory_db(user_id, agent_id)+ from pathlib import Path as _P+ _P(self.db_path).parent.mkdir(parents=True, exist_ok=True)self.enable_auto_store = enable_auto_storeself.max_memories = max_memories@@ -603,8 +608,13 @@ class AgenticMemoryModule:@classmethoddef from_config(cls, config: Dict[str, Any]) -> "AgenticMemoryModule":"""Create from configuration."""+ user_id = config.get("user_id", "default")+ agent_id = config.get("agent_id")+ if not agent_id:+ raise ValueError("AgenticMemoryModule.from_config: 'agent_id' is required")return cls(- user_id=config.get("user_id", "default"),+ user_id=user_id,+ agent_id=agent_id,db_path=config.get("db_path"),enable_auto_store=config.get("enable_auto_store", True),max_memories=config.get("max_memories", 1000)diff --git a/fincept-qt/scripts/agents/finagent_core/tests/test_agentic_memory_isolation.py b/fincept-qt/scripts/agents/finagent_core/tests/test_agentic_memory_isolation.pynew file mode 100644index 000000000..e4b711390--- /dev/null+++ b/fincept-qt/scripts/agents/finagent_core/tests/test_agentic_memory_isolation.py@@ -0,0 +1,50 @@+import os++import pytest++from finagent_core.modules.memory_module import AgenticMemoryModule+++def test_init_requires_agent_id():+ with pytest.raises(TypeError):+ AgenticMemoryModule(user_id="alice") # missing agent_id+++def test_from_config_requires_agent_id():+ with pytest.raises(ValueError, match="agent_id"):+ AgenticMemoryModule.from_config({"user_id": "alice"})+++def test_same_user_different_agents_are_isolated(monkeypatch, tmp_path):+ monkeypatch.setenv("FINAGENT_DATA_DIR", str(tmp_path))++ buffett = AgenticMemoryModule.from_config(+ {"user_id": "alice", "agent_id": "warren_buffett_agent"}+ )+ ackman = AgenticMemoryModule.from_config(+ {"user_id": "alice", "agent_id": "bill_ackman_agent"}+ )++ buffett.store("prefer wonderful businesses", memory_type="preference")+ ackman.store("short poorly-run companies", memory_type="preference")++ buffett_recalls = buffett.recall(memory_type="preference", limit=10)+ ackman_recalls = ackman.recall(memory_type="preference", limit=10)++ buffett_content = [m["content"] for m in buffett_recalls]+ ackman_content = [m["content"] for m in ackman_recalls]++ assert "prefer wonderful businesses" in buffett_content+ assert "short poorly-run companies" not in buffett_content+ assert "short poorly-run companies" in ackman_content+ assert "prefer wonderful businesses" not in ackman_content+++def test_explicit_db_path_overrides_default(monkeypatch, tmp_path):+ monkeypatch.setenv("FINAGENT_DATA_DIR", str(tmp_path))+ custom = tmp_path / "custom.db"+ mod = AgenticMemoryModule.from_config(+ {"user_id": "alice", "agent_id": "x", "db_path": str(custom)}+ )+ mod.store("hello", memory_type="fact")+ assert custom.exists()