Add or refresh a file in working memory.
(self, file_path: str, content: str, tokens: int)
| 86 | self._turn: int = 0 |
| 87 | |
| 88 | def add(self, file_path: str, content: str, tokens: int): |
| 89 | """Add or refresh a file in working memory.""" |
| 90 | now = int(time.time()) |
| 91 | if file_path in self._files: |
| 92 | item = self._files[file_path] |
| 93 | item.content = content |
| 94 | item.tokens = tokens |
| 95 | item.last_used_at = now |
| 96 | item.last_used_turn = self._turn |
| 97 | item.access_count += 1 |
| 98 | else: |
| 99 | self._files[file_path] = WorkingMemoryItem( |
| 100 | file_path=file_path, |
| 101 | content=content, |
| 102 | tokens=tokens, |
| 103 | loaded_at=now, |
| 104 | last_used_at=now, |
| 105 | last_used_turn=self._turn, |
| 106 | ) |
| 107 | self._evict_by_tokens() |
| 108 | |
| 109 | def get(self, file_path: str) -> Optional[str]: |
| 110 | """Get file content and mark as recently used.""" |
no test coverage detected