mirror of
https://github.com/agent0ai/agent-zero.git
synced 2026-05-06 08:01:31 +00:00
memory tool update, minor cleanup, utility models
This commit is contained in:
parent
76ff3c5fcf
commit
b3adcc7bca
11 changed files with 204 additions and 55 deletions
|
|
@ -9,7 +9,18 @@ db: VectorDB | None = None
|
|||
|
||||
class Memory(Tool):
|
||||
def execute(self,**kwargs):
|
||||
result = process_query(self.agent, self.args["memory"],self.args["action"], result_count=self.agent.config.auto_memory_count)
|
||||
result=[]
|
||||
|
||||
if "query" in kwargs:
|
||||
if "threshold" in kwargs: threshold = float(kwargs["threshold"])
|
||||
else: threshold = 0.1
|
||||
result = process_query(self.agent, kwargs["query"], action="load", threshold=threshold, result_count=3)
|
||||
elif "memorize" in kwargs:
|
||||
result = process_query(self.agent, kwargs["memorize"], action="save")
|
||||
elif "forget" in kwargs:
|
||||
result = process_query(self.agent, kwargs["forget"], action="delete")
|
||||
|
||||
# result = process_query(self.agent, self.args["memory"],self.args["action"], result_count=self.agent.config.auto_memory_count)
|
||||
return Response(message="\n\n".join(result), break_loop=False)
|
||||
|
||||
|
||||
|
|
@ -19,21 +30,21 @@ def initialize(embeddings_model, subdir=""):
|
|||
db = VectorDB(embeddings_model=embeddings_model, in_memory=False, cache_dir=dir)
|
||||
|
||||
|
||||
def process_query(agent:Agent, message: str, action: str = "load", result_count: int = 3, **kwargs):
|
||||
def process_query(agent:Agent, message: str, action: str = "load", result_count: int = 3, threshold: float = 0.1, **kwargs):
|
||||
if not db: initialize(agent.config.embeddings_model, subdir=agent.config.memory_subdir)
|
||||
|
||||
if action.strip().lower() == "save":
|
||||
id = db.insert_document(str(message)) # type: ignore
|
||||
return files.read_file("./prompts/fw.memory_saved.md")
|
||||
return [files.read_file("./prompts/fw.memory_saved.md")]
|
||||
|
||||
elif action.strip().lower() == "delete":
|
||||
deleted = db.delete_documents(message) # type: ignore
|
||||
return files.read_file("./prompts/fw.memories_deleted.md", count=deleted)
|
||||
return [files.read_file("./prompts/fw.memories_deleted.md", count=deleted)]
|
||||
|
||||
else:
|
||||
results=[]
|
||||
docs = db.search_max_rel(message,result_count) # type: ignore
|
||||
if len(docs)==0: return files.read_file("./prompts/fw.memories_not_found.md", query=message)
|
||||
docs = db.search_similarity_threshold(message,result_count,threshold) # type: ignore
|
||||
if len(docs)==0: return [files.read_file("./prompts/fw.memories_not_found.md", query=message)]
|
||||
for doc in docs:
|
||||
results.append(doc.page_content)
|
||||
return results
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue