MCPcopy Create free account
hub / github.com/DVampire/FinAgent / MemoryInterface

Class MemoryInterface

finagent/memory/interface.py:17–236  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16@MEMORY.register_module(force=True)
17class MemoryInterface():
18 def __init__(
19 self,
20 root,
21 symbols: List[str],
22 memory_path: str,
23 embedding_dim: int,
24 max_recent_steps = 5,
25 workdir = None,
26 tag = None,
27 ) -> None:
28
29 self.root = root
30 self.symbols = symbols
31 self.embedding_dim = embedding_dim
32 self.max_recent_steps = max_recent_steps
33 self.workdir = workdir
34 self.tag = tag
35 self.memory_path = os.path.join(self.root, self.workdir, self.tag, memory_path)
36 os.makedirs(self.memory_path, exist_ok=True)
37
38 self.market_intelligence_memorys = dict()
39 self.low_level_reflection_memorys = dict()
40 self.high_level_reflection_memorys = dict()
41 self._init_memorys()
42
43 self.market_intelligence_recent_histories = dict()
44 self.low_level_reflection_recent_histories = dict()
45 self.high_level_reflection_recent_histories = dict()
46 self._init_recent_histories()
47
48 def _init_memorys(self):
49 for symbol in self.symbols:
50 if symbol not in self.market_intelligence_memorys:
51 memory_path = os.path.join(self.memory_path, symbol, "market_intelligence")
52 os.makedirs(memory_path, exist_ok=True)
53 vecstore = FAISS(memory_path = memory_path, embedding_dim = self.embedding_dim)
54 self.market_intelligence_memorys[symbol] = BasicMemory(memory_path = memory_path,
55 vectorstore = vecstore)
56 if symbol not in self.low_level_reflection_memorys:
57 memory_path = os.path.join(self.memory_path, symbol, "low_level_reflection")
58 os.makedirs(memory_path, exist_ok=True)
59 vecstore = FAISS(memory_path = memory_path, embedding_dim=self.embedding_dim)
60 self.low_level_reflection_memorys[symbol] = BasicMemory(memory_path = memory_path,
61 vectorstore = vecstore)
62 if symbol not in self.high_level_reflection_memorys:
63 memory_path = os.path.join(self.memory_path, symbol, "high_level_reflection")
64 os.makedirs(memory_path, exist_ok=True)
65 vecstore = FAISS(memory_path = memory_path, embedding_dim=self.embedding_dim)
66 self.high_level_reflection_memorys[symbol] = BasicMemory(memory_path = memory_path,
67 vectorstore = vecstore)
68 def _init_recent_histories(self):
69 for symbol in self.symbols:
70 if symbol not in self.market_intelligence_recent_histories:
71 self.market_intelligence_recent_histories[symbol] = deque(maxlen=self.max_recent_steps)
72 if symbol not in self.low_level_reflection_recent_histories:
73 self.low_level_reflection_recent_histories[symbol] = deque(maxlen=self.max_recent_steps)
74 if symbol not in self.high_level_reflection_recent_histories:

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected