| 1 | from helpers.tool import Tool, Response |
| 2 | from plugins._memory.helpers.memory import Memory |
| 3 | |
| 4 | DEFAULT_THRESHOLD = 0.7 |
| 5 | DEFAULT_LIMIT = 10 |
| 6 | |
| 7 | |
| 8 | class MemoryLoad(Tool): |
| 9 | |
| 10 | async def execute(self, query="", threshold=DEFAULT_THRESHOLD, limit=DEFAULT_LIMIT, filter="", **kwargs): |
| 11 | if threshold is None or threshold == "": |
| 12 | threshold = DEFAULT_THRESHOLD |
| 13 | if limit is None or limit == "": |
| 14 | limit = DEFAULT_LIMIT |
| 15 | threshold = float(threshold) |
| 16 | limit = int(limit) |
| 17 | |
| 18 | db = await Memory.get(self.agent) |
| 19 | docs = await db.search_similarity_threshold(query=query, limit=limit, threshold=threshold, filter=filter) |
| 20 | |
| 21 | if len(docs) == 0: |
| 22 | result = self.agent.read_prompt("fw.memories_not_found.md", query=query) |
| 23 | else: |
| 24 | text = "\n\n".join(Memory.format_docs_plain(docs)) |
| 25 | result = str(text) |
| 26 | |
| 27 | return Response(message=result, break_loop=False) |