Query memory for relevant information. Searches both in-memory data and file cache. Args: query: Search query limit: Maximum number of results Returns: Formatted string of matching memories
(self, query: str, limit: int = 3)
| 50 | self.file_cache.pop(0) |
| 51 | |
| 52 | def query(self, query: str, limit: int = 3) -> str: |
| 53 | """ |
| 54 | Query memory for relevant information. |
| 55 | Searches both in-memory data and file cache. |
| 56 | |
| 57 | Args: |
| 58 | query: Search query |
| 59 | limit: Maximum number of results |
| 60 | |
| 61 | Returns: |
| 62 | Formatted string of matching memories |
| 63 | """ |
| 64 | results = [] |
| 65 | query_lower = query.lower() |
| 66 | |
| 67 | # Search in file cache first (more persistent memories) |
| 68 | for line in reversed(self.file_cache): |
| 69 | if query_lower in line.lower(): |
| 70 | results.append(line.strip()) |
| 71 | if len(results) >= limit: |
| 72 | break |
| 73 | |
| 74 | # If not enough results, search in-memory data |
| 75 | if len(results) < limit and self._data: |
| 76 | for env_data in reversed(self._data): |
| 77 | for record in reversed(env_data): |
| 78 | # Search in all fields |
| 79 | for value in record.values(): |
| 80 | if isinstance(value, str) and query_lower in value.lower(): |
| 81 | results.append(str(record)) |
| 82 | break |
| 83 | if len(results) >= limit: |
| 84 | break |
| 85 | if len(results) >= limit: |
| 86 | break |
| 87 | |
| 88 | return "\n".join(results) if results else "No relevant memory found" |
| 89 | |
| 90 | def store_staged(self, staged_data: Dict[str, Any], episode: str = "", step: int = 0): |
| 91 | """ |
no outgoing calls
no test coverage detected