"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(memory): gate features behind flags per maintainer review
shadowinlifefc6ee69f4b06
diff --git a/agent/.env.example b/agent/.env.exampleindex 74a82da93..7033a8f83 100644--- a/agent/.env.example+++ b/agent/.env.example@@ -225,10 +225,6 @@ TUSHARE_TOKEN=your-tushare-token# Memories lose importance over time (14-day half-life) unless accessed.# VT_MEMORY_DECAY=0-# Use alternative hotness-based decay (7-day half-life, sigmoid smoothing).-# Recommended for high-frequency trading context. Mutually exclusive with VT_MEMORY_DECAY.-VT_MEMORY_HOTNESS_DECAY=0-# ============================================================================# TAP Mode — credential isolation for broker orders (optional, OFF by default)# ============================================================================diff --git a/agent/src/config/env_schema.py b/agent/src/config/env_schema.pyindex b7ee6b27d..b4f886f2f 100644--- a/agent/src/config/env_schema.py+++ b/agent/src/config/env_schema.py@@ -356,11 +356,6 @@ class MemoryConfig(_EnvBase):alias="VT_MEMORY_DECAY",description="Enable importance decay computation",)- hotness_decay_enabled: EnvBool = Field(- default=False,- alias="VT_MEMORY_HOTNESS_DECAY",- description="Use alternative hotness decay (7-day half-life) instead of Ebbinghaus",- )# ---------------------------------------------------------------------------diff --git a/agent/src/memory/lifecycle.py b/agent/src/memory/lifecycle.pyindex b54cd64e2..d40aaf4e0 100644--- a/agent/src/memory/lifecycle.py+++ b/agent/src/memory/lifecycle.py@@ -21,7 +21,6 @@ from types import MappingProxyTypefrom src.memory.persistent import (MemoryEntry,PersistentMemory,- _is_hotness_decay_enabled as is_hotness_decay_enabled,compute_importance,memory_lock,)diff --git a/agent/src/memory/persistent.py b/agent/src/memory/persistent.pyindex dbc41cda6..c5c0a55c4 100644--- a/agent/src/memory/persistent.py+++ b/agent/src/memory/persistent.py@@ -77,9 +77,6 @@ HALF_LIFE_DAYS = 14.0_DECAY_LAMBDA = math.log(2) / HALF_LIFE_DAYS_ACCESS_BOOST = 0.1-_HOTNESS_HALF_LIFE_DAYS = 7.0-_HOTNESS_DECAY_RATE = math.log(2) / _HOTNESS_HALF_LIFE_DAYS-def compute_importance(quality_score: float, access_count: int, days_since_last_access: float@@ -95,25 +92,18 @@ def compute_importance(return min(1.0, max(0.0, raw))-def compute_hotness(access_count: int, days_since_last_access: float) -> float:- """Sigmoid-smoothed hotness combining frequency and recency.-- Alternative decay formula for high-frequency trading context where- 14-day half-life is too slow. Uses 7-day half-life with sigmoid- smoothing to prevent access_count from dominating.+def _is_decay_enabled() -> bool:+ """Check if importance decay is enabled via VT_MEMORY_DECAY env var."""+ from src.config.accessor import get_env_config- Inspired by Open-Viking (via AutoMemory reference hub).- """- frequency_signal = 1 / (1 + math.exp(-math.log1p(access_count)))- recency_signal = math.exp(-_HOTNESS_DECAY_RATE * days_since_last_access)- return frequency_signal * recency_signal+ return get_env_config().memory.decay_enabled-def _is_hotness_decay_enabled() -> bool:- """Check if hotness decay is enabled via VT_MEMORY_HOTNESS_DECAY env var."""+def _is_quality_enabled() -> bool:+ """Check if quality scoring is enabled via VT_MEMORY_QUALITY env var."""from src.config.accessor import get_env_config- return get_env_config().memory.hotness_decay_enabled+ return get_env_config().memory.quality_enabled# Script ranges for non-Latin tokenization and slug generation.@@ -274,11 +264,7 @@ class PersistentMemory:last_acc = _parse_timestamp(meta.get("last_accessed"), mtime)now = _time.time()days_since = max(0.0, (now - last_acc) / 86400.0)- # Select decay formula based on feature flag- if _is_hotness_decay_enabled():- importance = compute_hotness(ac, days_since)- else:- importance = compute_importance(qs, ac, days_since)+ importance = compute_importance(qs, ac, days_since)entries.append(MemoryEntry(path=path,@@ -348,7 +334,9 @@ class PersistentMemory:+ len(query_tokens & body_tokens))if token_score > 0:- final_score = token_score * (0.5 + 0.5 * entry.importance)+ final_score = token_score+ if _is_decay_enabled():+ final_score *= (0.5 + 0.5 * entry.importance)scored.append((final_score, entry))scored.sort(key=lambda x: (-x[0], -x[1].modified_at))@@ -379,7 +367,7 @@ class PersistentMemory:def add(self, name: str, content: str, memory_type: str = "project",description: str = "") -> Optional[Path]:"""Save a new memory entry and update the index."""- if self.is_duplicate(name, description, content):+ if _is_quality_enabled() and self.is_duplicate(name, description, content):logger.debug("Duplicate memory write blocked within %.0fs window: %s",DEDUP_WINDOW_SECONDS,diff --git a/agent/tests/memory/test_memory_dedup.py b/agent/tests/memory/test_memory_dedup.pyindex e2d5a1e53..793be58c3 100644--- a/agent/tests/memory/test_memory_dedup.py+++ b/agent/tests/memory/test_memory_dedup.py@@ -116,8 +116,9 @@ class TestIsDuplicate:class TestAddDedup:"""Integration tests: dedup check within the add() method."""- def test_duplicate_add_returns_none(self, tmp_path: Path) -> None:+ def test_duplicate_add_returns_none(self, tmp_path: Path, monkeypatch) -> None:"""Second add() with same name+desc within window returns None."""+ monkeypatch.setenv("VT_MEMORY_QUALITY", "1")pm = PersistentMemory(memory_dir=tmp_path)result1 = pm.add("My Note", "body content", description="important")assert result1 is not None@@ -126,8 +127,9 @@ class TestAddDedup:result2 = pm.add("My Note", "body content", description="important")assert result2 is None- def test_duplicate_add_does_not_create_second_file(self, tmp_path: Path) -> None:+ def test_duplicate_add_does_not_create_second_file(self, tmp_path: Path, monkeypatch) -> None:"""Blocked duplicate does not write a second .md file."""+ monkeypatch.setenv("VT_MEMORY_QUALITY", "1")pm = PersistentMemory(memory_dir=tmp_path)pm.add("Unique Entry", "content", description="desc")# Count .md files (excluding MEMORY.md)@@ -148,8 +150,9 @@ class TestAddDedup:assert r2 is not Noneassert r1 != r2- def test_add_after_window_expires(self, tmp_path: Path) -> None:+ def test_add_after_window_expires(self, tmp_path: Path, monkeypatch) -> None:"""Same content can be written again after dedup window expires."""+ monkeypatch.setenv("VT_MEMORY_QUALITY", "1")pm = PersistentMemory(memory_dir=tmp_path)with patch("src.memory.persistent._time.time", return_value=1000.0):diff --git a/agent/tests/test_memory_gc.py b/agent/tests/test_memory_gc.pyindex fd6c071d2..84b23ccd1 100644--- a/agent/tests/test_memory_gc.py+++ b/agent/tests/test_memory_gc.py@@ -179,8 +179,9 @@ class TestRunGC:class TestFindRelevantImportanceWeighting:- def test_higher_importance_ranks_higher(self, tmp_path: Path) -> None:+ def test_higher_importance_ranks_higher(self, tmp_path: Path, monkeypatch) -> None:"""Entry with more metadata overlap should rank above body-only match."""+ monkeypatch.setenv("VT_MEMORY_DECAY", "1")# "trading strategy" appears in title/description (metadata, 2x weight)_create_memory_file(tmp_path, "trading strategy notes", content="general notes",@@ -197,8 +198,9 @@ class TestFindRelevantImportanceWeighting:# Metadata-weighted entry ranks firstassert results[0].title == "trading strategy notes"- def test_keywords_participate_in_scoring(self, tmp_path: Path) -> None:+ def test_keywords_participate_in_scoring(self, tmp_path: Path, monkeypatch) -> None:"""Keywords in frontmatter should contribute to retrieval score."""+ monkeypatch.setenv("VT_MEMORY_DECAY", "1")_create_memory_file(tmp_path, "kw-entry", content="unrelated body",keywords=["momentum", "alpha"], entry_id="kw1234",