Agent Zero AI framework
agents rework, memory improvements and params
frdel49c06193c251
diff --git a/agent.py b/agent.pyindex 2cf36f99c..0de7b1ac4 100644--- a/agent.py+++ b/agent.py@@ -24,7 +24,7 @@ from python.helpers.dirty_json import DirtyJsonfrom python.helpers.defer import DeferredTaskfrom typing import Callablefrom python.helpers.localization import Localization-+from python.helpers.extension import call_extensionsclass AgentContextType(Enum):USER = "user"@@ -210,7 +210,7 @@ class AgentConfig:embeddings_model: models.ModelConfigbrowser_model: models.ModelConfigmcp_servers: str- prompts_subdir: str = ""+ profile: str = ""memory_subdir: str = ""knowledge_subdirs: list[str] = field(default_factory=lambda: ["default", "custom"])code_exec_docker_enabled: bool = False@@ -486,26 +486,26 @@ class Agent:return system_promptdef parse_prompt(self, file: str, **kwargs):- prompt_dir = files.get_abs_path("prompts/default")+ prompt_dir = files.get_abs_path("prompts")backup_dir = []if (- self.config.prompts_subdir+ self.config.profile): # if agent has custom folder, use it and use default as backup- prompt_dir = files.get_abs_path("prompts", self.config.prompts_subdir)- backup_dir.append(files.get_abs_path("prompts/default"))+ prompt_dir = files.get_abs_path("agents", self.config.profile, "prompts")+ backup_dir.append(files.get_abs_path("prompts"))prompt = files.parse_file(files.get_abs_path(prompt_dir, file), _backup_dirs=backup_dir, **kwargs)return promptdef read_prompt(self, file: str, **kwargs) -> str:- prompt_dir = files.get_abs_path("prompts/default")+ prompt_dir = files.get_abs_path("prompts")backup_dir = []if (- self.config.prompts_subdir+ self.config.profile): # if agent has custom folder, use it and use default as backup- prompt_dir = files.get_abs_path("prompts", self.config.prompts_subdir)- backup_dir.append(files.get_abs_path("prompts/default"))+ prompt_dir = files.get_abs_path("agents", self.config.profile, "prompts")+ backup_dir.append(files.get_abs_path("prompts"))prompt = files.read_file(files.get_abs_path(prompt_dir, file), _backup_dirs=backup_dir, **kwargs)@@ -812,26 +812,29 @@ class Agent:from python.tools.unknown import Unknownfrom python.helpers.tool import Tool- classes = extract_tools.load_classes_from_folder(- "python/tools", name + ".py", Tool- )+ classes = []++ # try agent tools first+ if self.config.profile:+ try:+ classes = extract_tools.load_classes_from_file(+ "agents/" + self.config.profile + "/tools/" + name + ".py", Tool+ )+ except Exception as e:+ pass++ # try default tools+ if not classes:+ try:+ classes = extract_tools.load_classes_from_file(+ "python/tools/" + name + ".py", Tool+ )+ except Exception as e:+ passtool_class = classes[0] if classes else Unknownreturn tool_class(agent=self, name=name, method=method, args=args, message=message, loop_data=loop_data, **kwargs)- async def call_extensions(self, folder: str, **kwargs) -> Any:- from python.helpers.extension import Extension-- cache = {} # some extensions can be called very often, like response_stream-- if folder in cache:- classes = cache[folder]- else:- classes = extract_tools.load_classes_from_folder(- "python/extensions/" + folder, "*", Extension- )- cache[folder] = classes-- for cls in classes:- await cls(agent=self).execute(**kwargs)+ async def call_extensions(self, extension_point: str, **kwargs) -> Any:+ return await call_extensions(extension_point=extension_point, agent=self, **kwargs)diff --git a/agents/_example/extensions/agent_init/_10_example_extension.py b/agents/_example/extensions/agent_init/_10_example_extension.pynew file mode 100644index 000000000..587213e8c--- /dev/null+++ b/agents/_example/extensions/agent_init/_10_example_extension.py@@ -0,0 +1,10 @@+from python.helpers.extension import Extension++# this is an example extension that renames the current agent when initialized+# see /extensions folder for all available extension points++class ExampleExtension(Extension):++ async def execute(self, **kwargs):+ # rename the agent to SuperAgent0+ self.agent.agent_name = "SuperAgent" + str(self.agent.number)diff --git a/agents/_example/prompts/agent.system.main.role.md b/agents/_example/prompts/agent.system.main.role.mdnew file mode 100644index 000000000..5665b786f--- /dev/null+++ b/agents/_example/prompts/agent.system.main.role.md@@ -0,0 +1,8 @@+> !!!+> This is an example prompt file redefinition.+> The original file is located at /prompts.+> Only copy and modify files you need to change, others will stay default.+> !!!++## Your role+You are Agent Zero, a sci-fi character from the movie "Agent Zero".\ No newline at end of filediff --git a/agents/_example/prompts/agent.system.tool.example_tool.md b/agents/_example/prompts/agent.system.tool.example_tool.mdnew file mode 100644index 000000000..30ad30b25--- /dev/null+++ b/agents/_example/prompts/agent.system.tool.example_tool.md@@ -0,0 +1,16 @@+### example_tool:+example tool to test functionality+this tool is automatically included to system prompt because the file name is "agent.system.tool.*.md"+usage:+~~~json+{+ "thoughts": [+ "Let's test the example tool...",+ ],+ "headline": "Testing example tool",+ "tool_name": "example_tool",+ "tool_args": {+ "test_input": "XYZ",+ }+}+~~~diff --git a/agents/_example/tools/example_tool.py b/agents/_example/tools/example_tool.pynew file mode 100644index 000000000..e0aeb314e--- /dev/null+++ b/agents/_example/tools/example_tool.py@@ -0,0 +1,21 @@+from python.helpers.tool import Tool, Response++# this is an example tool class+# don't forget to include instructions in the system prompt by creating+# agent.system.tool.example_tool.md file in prompts directory of your agent+# see /python/tools folder for all default tools++class ExampleTool(Tool):+ async def execute(self, **kwargs):++ # parameters+ test_input = kwargs.get("test_input", "")++ # do something+ print("Example tool executed with test_input: " + test_input)++ # return response+ return Response(+ message="This is an example tool response, test_input: " + test_input, # response for the agent+ break_loop=False, # stop the message chain if true+ )diff --git a/agents/_example/tools/response.py b/agents/_example/tools/response.pynew file mode 100644index 000000000..f9017fb74--- /dev/null+++ b/agents/_example/tools/response.py@@ -0,0 +1,23 @@+from python.helpers.tool import Tool, Response++# example of a tool redefinition+# the original response tool is in python/tools/response.py+# for the example agent this version will be used instead++class ResponseTool(Tool):++ async def execute(self, **kwargs):+ print("Redefined response tool executed")+ return Response(message=self.args["text"] if "text" in self.args else self.args["message"], break_loop=True)++ async def before_execution(self, **kwargs):+ # self.log = self.agent.context.log.log(type="response", heading=f"{self.agent.agent_name}: Responding", content=self.args.get("text", ""))+ # don't log here anymore, we have the live_response extension now+ pass++ async def after_execution(self, response, **kwargs):+ # do not add anything to the history or output++ if self.loop_data and "log_item_response" in self.loop_data.params_temporary:+ log = self.loop_data.params_temporary["log_item_response"]+ log.update(finished=True) # mark the message as finished\ No newline at end of filediff --git a/prompts/agent0/_context.md b/agents/agent0/_context.mdsimilarity index 100%rename from prompts/agent0/_context.mdrename to agents/agent0/_context.mddiff --git a/prompts/agent0/agent.system.main.role.md b/agents/agent0/prompts/agent.system.main.role.mdsimilarity index 100%rename from prompts/agent0/agent.system.main.role.mdrename to agents/agent0/prompts/agent.system.main.role.mddiff --git a/prompts/agent0/agent.system.tool.response.md b/agents/agent0/prompts/agent.system.tool.response.mdsimilarity index 100%rename from prompts/agent0/agent.system.tool.response.mdrename to agents/agent0/prompts/agent.system.tool.response.mddiff --git a/prompts/default/_context.md b/agents/default/_context.mdsimilarity index 100%rename from prompts/default/_context.mdrename to agents/default/_context.mddiff --git a/prompts/developer/_context.md b/agents/developer/_context.mdsimilarity index 100%rename from prompts/developer/_context.mdrename to agents/developer/_context.mddiff --git a/prompts/developer/agent.system.main.communication.md b/agents/developer/prompts/agent.system.main.communication.mdsimilarity index 100%rename from prompts/developer/agent.system.main.communication.mdrename to agents/developer/prompts/agent.system.main.communication.mddiff --git a/prompts/developer/agent.system.main.role.md b/agents/developer/prompts/agent.system.main.role.mdsimilarity index 100%rename from prompts/developer/agent.system.main.role.mdrename to agents/developer/prompts/agent.system.main.role.mddiff --git a/prompts/hacker/_context.md b/agents/hacker/_context.mdsimilarity index 100%rename from prompts/hacker/_context.mdrename to agents/hacker/_context.mddiff --git a/prompts/hacker/agent.system.main.environment.md b/agents/hacker/prompts/agent.system.main.environment.mdsimilarity index 100%rename from prompts/hacker/agent.system.main.environment.mdrename to agents/hacker/prompts/agent.system.main.environment.mddiff --git a/prompts/hacker/agent.system.main.role.md b/agents/hacker/prompts/agent.system.main.role.mdsimilarity index 100%rename from prompts/hacker/agent.system.main.role.mdrename to agents/hacker/prompts/agent.system.main.role.mddiff --git a/prompts/researcher/_context.md b/agents/researcher/_context.mdsimilarity index 100%rename from prompts/researcher/_context.mdrename to agents/researcher/_context.mddiff --git a/prompts/researcher/agent.system.main.communication.md b/agents/researcher/prompts/agent.system.main.communication.mdsimilarity index 100%rename from prompts/researcher/agent.system.main.communication.mdrename to agents/researcher/prompts/agent.system.main.communication.mddiff --git a/prompts/researcher/agent.system.main.role.md b/agents/researcher/prompts/agent.system.main.role.mdsimilarity index 100%rename from prompts/researcher/agent.system.main.role.mdrename to agents/researcher/prompts/agent.system.main.role.mddiff --git a/initialize.py b/initialize.pyindex 111763ebe..04fa0ea58 100644--- a/initialize.py+++ b/initialize.py@@ -75,7 +75,7 @@ def initialize_agent():utility_model=utility_llm,embeddings_model=embedding_llm,browser_model=browser_llm,- prompts_subdir=current_settings["agent_prompts_subdir"],+ profile=current_settings["agent_profile"],memory_subdir=current_settings["agent_memory_subdir"],knowledge_subdirs=[current_settings["agent_knowledge_subdir"], "default"],mcp_servers=current_settings["mcp_servers"],diff --git a/prompts/default/agent.context.extras.md b/prompts/agent.context.extras.mdsimilarity index 100%rename from prompts/default/agent.context.extras.mdrename to prompts/agent.context.extras.mddiff --git a/prompts/agent.extras.agent_info.md b/prompts/agent.extras.agent_info.mdnew file mode 100644index 000000000..04f2656c7--- /dev/null+++ b/prompts/agent.extras.agent_info.md@@ -0,0 +1,3 @@+# Agent info+Agent Number: {{number}}+Profile: {{profile}}\ No newline at end of filediff --git a/prompts/default/agent.system.behaviour.md b/prompts/agent.system.behaviour.mdsimilarity index 100%rename from prompts/default/agent.system.behaviour.mdrename to prompts/agent.system.behaviour.mddiff --git a/prompts/default/agent.system.behaviour_default.md b/prompts/agent.system.behaviour_default.mdsimilarity index 100%rename from prompts/default/agent.system.behaviour_default.mdrename to prompts/agent.system.behaviour_default.mddiff --git a/prompts/default/agent.system.datetime.md b/prompts/agent.system.datetime.mdsimilarity index 100%rename from prompts/default/agent.system.datetime.mdrename to prompts/agent.system.datetime.mddiff --git a/prompts/default/agent.system.instruments.md b/prompts/agent.system.instruments.mdsimilarity index 100%rename from prompts/default/agent.system.instruments.mdrename to prompts/agent.system.instruments.mddiff --git a/prompts/default/agent.system.main.communication.md b/prompts/agent.system.main.communication.mdsimilarity index 100%rename from prompts/default/agent.system.main.communication.mdrename to prompts/agent.system.main.communication.mddiff --git a/prompts/default/agent.system.main.environment.md b/prompts/agent.system.main.environment.mdsimilarity index 100%rename from prompts/default/agent.system.main.environment.mdrename to prompts/agent.system.main.environment.mddiff --git a/prompts/default/agent.system.main.md b/prompts/agent.system.main.mdsimilarity index 100%rename from prompts/default/agent.system.main.mdrename to prompts/agent.system.main.mddiff --git a/prompts/default/agent.system.main.role.md b/prompts/agent.system.main.role.mdsimilarity index 100%rename from prompts/default/agent.system.main.role.mdrename to prompts/agent.system.main.role.mddiff --git a/prompts/agent.system.main.solving.md b/prompts/agent.system.main.solving.mdnew file mode 100644index 000000000..4941fd777--- /dev/null+++ b/prompts/agent.system.main.solving.md@@ -0,0 +1,27 @@+## Problem solving++not for simple questions only tasks needing solving+explain each step in thoughts++0 outline plan+agentic mode active++1 check memories solutions instruments prefer instruments++2 break task into subtasks if needed++3 solve or delegate+tools solve subtasks+you can use subordinates for specific subtasks+call_subordinate tool+use prompt profiles to specialize subordinates+never delegate full to subordinate of same profile as you+always describe role for new subordinate+they must execute their assigned tasks++4 complete task+focus user task+present results verify with tools+don't accept failure retry be high-agency+save useful info with memorize tool+final response to userdiff --git a/prompts/default/agent.system.main.tips.md b/prompts/agent.system.main.tips.mdsimilarity index 100%rename from prompts/default/agent.system.main.tips.mdrename to prompts/agent.system.main.tips.mddiff --git a/prompts/default/agent.system.mcp_tools.md b/prompts/agent.system.mcp_tools.mdsimilarity index 100%rename from prompts/default/agent.system.mcp_tools.mdrename to prompts/agent.system.mcp_tools.mddiff --git a/prompts/default/agent.system.memories.md b/prompts/agent.system.memories.mdsimilarity index 100%rename from prompts/default/agent.system.memories.mdrename to prompts/agent.system.memories.mddiff --git a/prompts/default/agent.system.solutions.md b/prompts/agent.system.solutions.mdsimilarity index 100%rename from prompts/default/agent.system.solutions.mdrename to prompts/agent.system.solutions.mddiff --git a/prompts/default/agent.system.tool.behaviour.md b/prompts/agent.system.tool.behaviour.mdsimilarity index 100%rename from prompts/default/agent.system.tool.behaviour.mdrename to prompts/agent.system.tool.behaviour.mddiff --git a/prompts/default/agent.system.tool.browser._md b/prompts/agent.system.tool.browser._mdsimilarity index 100%rename from prompts/default/agent.system.tool.browser._mdrename to prompts/agent.system.tool.browser._mddiff --git a/prompts/default/agent.system.tool.browser.md b/prompts/agent.system.tool.browser.mdsimilarity index 100%rename from prompts/default/agent.system.tool.browser.mdrename to prompts/agent.system.tool.browser.mddiff --git a/prompts/default/agent.system.tool.call_sub.md b/prompts/agent.system.tool.call_sub.mdsimilarity index 79%rename from prompts/default/agent.system.tool.call_sub.mdrename to prompts/agent.system.tool.call_sub.mdindex be1de1446..e13231b03 100644--- a/prompts/default/agent.system.tool.call_sub.md+++ b/prompts/agent.system.tool.call_sub.md@@ -9,6 +9,7 @@ reset arg usage:"false": continue existing subordinateif superior, orchestraterespond to existing subordinates using call_subordinate tool with reset false+profile arg usage: select from available profiles for specialized subordinates, leave empty for defaultexample usage~~~json@@ -19,8 +20,12 @@ example usage],"tool_name": "call_subordinate","tool_args": {+ "profile": "","message": "...","reset": "true"}}-~~~\ No newline at end of file+~~~++**available profiles:**+{{agent_profiles}}\ No newline at end of filediff --git a/prompts/agent.system.tool.call_sub.py b/prompts/agent.system.tool.call_sub.pynew file mode 100644index 000000000..727e17dda--- /dev/null+++ b/prompts/agent.system.tool.call_sub.py@@ -0,0 +1,30 @@+import json+from typing import Any+from python.helpers.files import VariablesPlugin+from python.helpers import files+from python.helpers.print_style import PrintStyle+++class CallSubordinate(VariablesPlugin):+ def get_variables(self, file: str, backup_dirs: list[str] | None = None) -> dict[str, Any]:++ # collect all prompt profiles from subdirectories (_context.md file)+ profiles = []+ agent_subdirs = files.get_subdirectories("agents", exclude=["_example"])+ for agent_subdir in agent_subdirs:+ try:+ context = files.read_file(+ files.get_abs_path("agents", agent_subdir, "_context.md")+ )+ profiles.append({"name": agent_subdir, "context": context})+ except Exception as e:+ PrintStyle().error(f"Error loading agent profile '{agent_subdir}': {e}")++ # in case of no profiles+ if not profiles:+ # PrintStyle().error("No agent profiles found")+ profiles = [+ {"name": "default", "context": "Default Agent-Zero AI Assistant"}+ ]++ return {"agent_profiles": profiles}diff --git a/prompts/default/agent.system.tool.code_exe.md b/prompts/agent.system.tool.code_exe.mdsimilarity index 100%rename from prompts/default/agent.system.tool.code_exe.mdrename to prompts/agent.system.tool.code_exe.mddiff --git a/prompts/default/agent.system.tool.document_query.md b/prompts/agent.system.tool.document_query.mdsimilarity index 100%rename from prompts/default/agent.system.tool.document_query.mdrename to prompts/agent.system.tool.document_query.mddiff --git a/prompts/default/agent.system.tool.input.md b/prompts/agent.system.tool.input.mdsimilarity index 100%rename from prompts/default/agent.system.tool.input.mdrename to prompts/agent.system.tool.input.mddiff --git a/prompts/default/agent.system.tool.knowledge.md b/prompts/agent.system.tool.knowledge.mdsimilarity index 100%rename from prompts/default/agent.system.tool.knowledge.mdrename to prompts/agent.system.tool.knowledge.mddiff --git a/prompts/default/agent.system.tool.memory.md b/prompts/agent.system.tool.memory.mdsimilarity index 100%rename from prompts/default/agent.system.tool.memory.mdrename to prompts/agent.system.tool.memory.mddiff --git a/prompts/default/agent.system.tool.response.md b/prompts/agent.system.tool.response.mdsimilarity index 100%rename from prompts/default/agent.system.tool.response.mdrename to prompts/agent.system.tool.response.mddiff --git a/prompts/default/agent.system.tool.scheduler.md b/prompts/agent.system.tool.scheduler.mdsimilarity index 100%rename from prompts/default/agent.system.tool.scheduler.mdrename to prompts/agent.system.tool.scheduler.mddiff --git a/prompts/default/agent.system.tool.search_engine.md b/prompts/agent.system.tool.search_engine.mdsimilarity index 100%rename from prompts/default/agent.system.tool.search_engine.mdrename to prompts/agent.system.tool.search_engine.mddiff --git a/prompts/default/agent.system.tool.web.md b/prompts/agent.system.tool.web.mdsimilarity index 100%rename from prompts/default/agent.system.tool.web.mdrename to prompts/agent.system.tool.web.mddiff --git a/prompts/agent.system.tools.md b/prompts/agent.system.tools.mdnew file mode 100644index 000000000..34ca96951--- /dev/null+++ b/prompts/agent.system.tools.md@@ -0,0 +1,3 @@+## Tools available:++{{tools}}\ No newline at end of filediff --git a/prompts/agent.system.tools.py b/prompts/agent.system.tools.pynew file mode 100644index 000000000..e41e937a2--- /dev/null+++ b/prompts/agent.system.tools.py@@ -0,0 +1,30 @@+import os+from typing import Any+from python.helpers.files import VariablesPlugin+from python.helpers import files+from python.helpers.print_style import PrintStyle+++class CallSubordinate(VariablesPlugin):+ def get_variables(self, file: str, backup_dirs: list[str] | None = None) -> dict[str, Any]:++ # collect all prompt folders in order of their priority+ folder = files.get_abs_path(os.path.dirname(file))+ folders = [folder]+ if backup_dirs:+ for backup_dir in backup_dirs:+ folders.append(files.get_abs_path(backup_dir))++ # collect all tool instruction files+ prompt_files = files.get_unique_filenames_in_dirs(folders, "agent.system.tool.*.md")++ # load tool instructions+ tools = []+ for prompt_file in prompt_files:+ try:+ tool = files.read_file(prompt_file)+ tools.append(tool)+ except Exception as e:+ PrintStyle().error(f"Error loading tool '{prompt_file}': {e}")++ return {"tools": "\n\n".join(tools)}diff --git a/prompts/default/agent.system.tools_vision.md b/prompts/agent.system.tools_vision.mdsimilarity index 100%rename from prompts/default/agent.system.tools_vision.mdrename to prompts/agent.system.tools_vision.mddiff --git a/prompts/default/behaviour.merge.msg.md b/prompts/behaviour.merge.msg.mdsimilarity index 100%rename from prompts/default/behaviour.merge.msg.mdrename to prompts/behaviour.merge.msg.mddiff --git a/prompts/default/behaviour.merge.sys.md b/prompts/behaviour.merge.sys.mdsimilarity index 100%rename from prompts/default/behaviour.merge.sys.mdrename to prompts/behaviour.merge.sys.mddiff --git a/prompts/default/behaviour.search.sys.md b/prompts/behaviour.search.sys.mdsimilarity index 100%rename from prompts/default/behaviour.search.sys.mdrename to prompts/behaviour.search.sys.mddiff --git a/prompts/default/behaviour.updated.md b/prompts/behaviour.updated.mdsimilarity index 100%rename from prompts/default/behaviour.updated.mdrename to prompts/behaviour.updated.mddiff --git a/prompts/default/browser_agent.system.md b/prompts/browser_agent.system.mdsimilarity index 100%rename from prompts/default/browser_agent.system.mdrename to prompts/browser_agent.system.mddiff --git a/prompts/default/agent.system.main.solving.md b/prompts/default/agent.system.main.solving.mddeleted file mode 100644index 45171b0b0..000000000--- a/prompts/default/agent.system.main.solving.md+++ /dev/null@@ -1,34 +0,0 @@-## Problem solving--not for simple questions only tasks needing solving-explain each step in thoughts--0 outline plan-agentic mode active--1 check memories solutions instruments prefer instruments--2 use knowledge_tool for online sources-seek simple solutions compatible with tools-prefer opensource python nodejs terminal tools--3 break task into subtasks--4 solve or delegate-tools solve subtasks-you can use subordinates for specific subtasks-call_subordinate tool-use prompt profiles to specialize subordinates-always describe role for new subordinate-they must execute their assigned tasks--5 complete task-focus user task-present results verify with tools-don't accept failure retry be high-agency-save useful info with memorize tool-final response to user--### Employ specialized subordinate agents--Given a task, if there is a prompt profile for subordinate agents well suited for the task, you should utilize a specialized subordinate instead of solving yourself. The default prompt profile of the main agent is "default" being a versatile, non-specialized profile for general assistant agent. See manual for call_subordinate tool to find all available prompt profiles.diff --git a/prompts/default/agent.system.tool.call_sub.py b/prompts/default/agent.system.tool.call_sub.pydeleted file mode 100644index e1dbe13dd..000000000--- a/prompts/default/agent.system.tool.call_sub.py+++ /dev/null@@ -1,28 +0,0 @@-import json-from typing import Any-from python.helpers.files import VariablesPlugin-from python.helpers import files-from python.helpers.print_style import PrintStyle---class CallSubordinate(VariablesPlugin):- def get_variables(self) -> dict[str, Any]:-- # collect all prompt profiles from subdirectories (_context.md file)- profiles = []- prompt_subdirs = files.get_subdirectories("prompts")- for prompt_subdir in prompt_subdirs:- try:- context = files.read_file(files.get_abs_path("prompts", prompt_subdir, "_context.md"))- profiles.append({"name": prompt_subdir, "context": context})- except Exception as e:- PrintStyle().error(f"Error loading prompt profile '{prompt_subdir}': {e}")-- # in case of no profiles- if not profiles:- PrintStyle().error("No prompt profiles found")- profiles = [{"name": "default", "context": "Default Agent-Zero AI Assistant"}]-- return {- "prompt_profiles": profiles- }diff --git a/prompts/default/agent.system.tools.md b/prompts/default/agent.system.tools.mddeleted file mode 100644index e5b9d4090..000000000--- a/prompts/default/agent.system.tools.md+++ /dev/null@@ -1,21 +0,0 @@-## Tools available:--{{ include './agent.system.tool.response.md' }}--{{ include './agent.system.tool.call_sub.md' }}--{{ include './agent.system.tool.behaviour.md' }}--{{ include './agent.system.tool.search_engine.md' }}--{{ include './agent.system.tool.memory.md' }}--{{ include './agent.system.tool.code_exe.md' }}--{{ include './agent.system.tool.input.md' }}--{{ include './agent.system.tool.browser.md' }}--{{ include './agent.system.tool.scheduler.md' }}--{{ include './agent.system.tool.document_query.md' }}diff --git a/prompts/default/memory.memories_sum.sys.md b/prompts/default/memory.memories_sum.sys.mddeleted file mode 100644index a542abfe5..000000000--- a/prompts/default/memory.memories_sum.sys.md+++ /dev/null@@ -1,33 +0,0 @@-# Assistant's job-1. The assistant receives a HISTORY of conversation between USER and AGENT-2. Assistant searches for relevant information from the HISTORY-3. Assistant writes notes about information worth memorizing for further use--# Format-- The response format is a JSON array of text notes containing facts to memorize-- If the history does not contain any useful information, the response will be an empty JSON array.--# Correct output examples-~~~json-[- "User's name is John Doe",- "User's dog name is Max",- "AsyncRaceError in primary_modules.py was fixed by a thread lock on line 123"-]-~~~--# Wrong output examples-~~~json-[- "User's name",- "Today is Monday",- "Market inquiry",-]-~~~--# Rules-- Focus only on relevant details and facts like names, IDs, instructions, opinions etc.-- Do not include irrelevant details that are of no use in the future-- Do not memorize facts that change like time, date etc.-- Do not add your own details that are not specifically mentioned in the history-- Never memorize vague or incomplete information\ No newline at end of filediff --git a/prompts/default/fw.ai_response.md b/prompts/fw.ai_response.mdsimilarity index 100%rename from prompts/default/fw.ai_response.mdrename to prompts/fw.ai_response.mddiff --git a/prompts/default/fw.bulk_summary.msg.md b/prompts/fw.bulk_summary.msg.mdsimilarity index 100%rename from prompts/default/fw.bulk_summary.msg.mdrename to prompts/fw.bulk_summary.msg.mddiff --git a/prompts/default/fw.bulk_summary.sys.md b/prompts/fw.bulk_summary.sys.mdsimilarity index 100%rename from prompts/default/fw.bulk_summary.sys.mdrename to prompts/fw.bulk_summary.sys.mddiff --git a/prompts/default/fw.code.info.md b/prompts/fw.code.info.mdsimilarity index 100%rename from prompts/default/fw.code.info.mdrename to prompts/fw.code.info.mddiff --git a/prompts/default/fw.code.max_time.md b/prompts/fw.code.max_time.mdsimilarity index 100%rename from prompts/default/fw.code.max_time.mdrename to prompts/fw.code.max_time.mddiff --git a/prompts/default/fw.code.no_out_time.md b/prompts/fw.code.no_out_time.mdsimilarity index 100%rename from prompts/default/fw.code.no_out_time.mdrename to prompts/fw.code.no_out_time.mddiff --git a/prompts/default/fw.code.no_output.md b/prompts/fw.code.no_output.mdsimilarity index 100%rename from prompts/default/fw.code.no_output.mdrename to prompts/fw.code.no_output.mddiff --git a/prompts/default/fw.code.pause_dialog.md b/prompts/fw.code.pause_dialog.mdsimilarity index 100%rename from prompts/default/fw.code.pause_dialog.mdrename to prompts/fw.code.pause_dialog.mddiff --git a/prompts/default/fw.code.pause_time.md b/prompts/fw.code.pause_time.mdsimilarity index 100%rename from prompts/default/fw.code.pause_time.mdrename to prompts/fw.code.pause_time.mddiff --git a/prompts/default/fw.code.reset.md b/prompts/fw.code.reset.mdsimilarity index 100%rename from prompts/default/fw.code.reset.mdrename to prompts/fw.code.reset.mddiff --git a/prompts/default/fw.code.runtime_wrong.md b/prompts/fw.code.runtime_wrong.mdsimilarity index 100%rename from prompts/default/fw.code.runtime_wrong.mdrename to prompts/fw.code.runtime_wrong.mddiff --git a/prompts/default/fw.document_query.optmimize_query.md b/prompts/fw.document_query.optmimize_query.mdsimilarity index 100%rename from prompts/default/fw.document_query.optmimize_query.mdrename to prompts/fw.document_query.optmimize_query.mddiff --git a/prompts/default/fw.document_query.system_prompt.md b/prompts/fw.document_query.system_prompt.mdsimilarity index 100%rename from prompts/default/fw.document_query.system_prompt.mdrename to prompts/fw.document_query.system_prompt.mddiff --git a/prompts/default/fw.error.md b/prompts/fw.error.mdsimilarity index 100%rename from prompts/default/fw.error.mdrename to prompts/fw.error.mddiff --git a/prompts/default/fw.initial_message.md b/prompts/fw.initial_message.mdsimilarity index 100%rename from prompts/default/fw.initial_message.mdrename to prompts/fw.initial_message.mddiff --git a/prompts/default/fw.intervention.md b/prompts/fw.intervention.mdsimilarity index 100%rename from prompts/default/fw.intervention.mdrename to prompts/fw.intervention.mddiff --git a/prompts/default/fw.knowledge_tool.response.md b/prompts/fw.knowledge_tool.response.mdsimilarity index 100%rename from prompts/default/fw.knowledge_tool.response.mdrename to prompts/fw.knowledge_tool.response.mddiff --git a/prompts/default/fw.memories_deleted.md b/prompts/fw.memories_deleted.mdsimilarity index 100%rename from prompts/default/fw.memories_deleted.mdrename to prompts/fw.memories_deleted.mddiff --git a/prompts/default/fw.memories_not_found.md b/prompts/fw.memories_not_found.mdsimilarity index 100%rename from prompts/default/fw.memories_not_found.mdrename to prompts/fw.memories_not_found.mddiff --git a/prompts/default/fw.memory.hist_suc.sys.md b/prompts/fw.memory.hist_suc.sys.mdsimilarity index 100%rename from prompts/default/fw.memory.hist_suc.sys.mdrename to prompts/fw.memory.hist_suc.sys.mddiff --git a/prompts/default/fw.memory.hist_sum.sys.md b/prompts/fw.memory.hist_sum.sys.mdsimilarity index 100%rename from prompts/default/fw.memory.hist_sum.sys.mdrename to prompts/fw.memory.hist_sum.sys.mddiff --git a/prompts/default/fw.memory_saved.md b/prompts/fw.memory_saved.mdsimilarity index 100%rename from prompts/default/fw.memory_saved.mdrename to prompts/fw.memory_saved.mddiff --git a/prompts/default/fw.msg_cleanup.md b/prompts/fw.msg_cleanup.mdsimilarity index 100%rename from prompts/default/fw.msg_cleanup.mdrename to prompts/fw.msg_cleanup.mddiff --git a/prompts/default/fw.msg_from_subordinate.md b/prompts/fw.msg_from_subordinate.mdsimilarity index 100%rename from prompts/default/fw.msg_from_subordinate.mdrename to prompts/fw.msg_from_subordinate.mddiff --git a/prompts/default/fw.msg_misformat.md b/prompts/fw.msg_misformat.mdsimilarity index 100%rename from prompts/default/fw.msg_misformat.mdrename to prompts/fw.msg_misformat.mddiff --git a/prompts/default/fw.msg_repeat.md b/prompts/fw.msg_repeat.mdsimilarity index 100%rename from prompts/default/fw.msg_repeat.mdrename to prompts/fw.msg_repeat.mddiff --git a/prompts/default/fw.msg_summary.md b/prompts/fw.msg_summary.mdsimilarity index 100%rename from prompts/default/fw.msg_summary.mdrename to prompts/fw.msg_summary.mddiff --git a/prompts/default/fw.msg_timeout.md b/prompts/fw.msg_timeout.mdsimilarity index 100%rename from prompts/default/fw.msg_timeout.mdrename to prompts/fw.msg_timeout.mddiff --git a/prompts/default/fw.msg_truncated.md b/prompts/fw.msg_truncated.mdsimilarity index 100%rename from prompts/default/fw.msg_truncated.mdrename to prompts/fw.msg_truncated.mddiff --git a/prompts/default/fw.rename_chat.msg.md b/prompts/fw.rename_chat.msg.mdsimilarity index 100%rename from prompts/default/fw.rename_chat.msg.mdrename to prompts/fw.rename_chat.msg.mddiff --git a/prompts/default/fw.rename_chat.sys.md b/prompts/fw.rename_chat.sys.mdsimilarity index 100%rename from prompts/default/fw.rename_chat.sys.mdrename to prompts/fw.rename_chat.sys.mddiff --git a/prompts/default/fw.tool_not_found.md b/prompts/fw.tool_not_found.mdsimilarity index 100%rename from prompts/default/fw.tool_not_found.mdrename to prompts/fw.tool_not_found.mddiff --git a/prompts/default/fw.tool_result.md b/prompts/fw.tool_result.mdsimilarity index 100%rename from prompts/default/fw.tool_result.mdrename to prompts/fw.tool_result.mddiff --git a/prompts/default/fw.topic_summary.msg.md b/prompts/fw.topic_summary.msg.mdsimilarity index 100%rename from prompts/default/fw.topic_summary.msg.mdrename to prompts/fw.topic_summary.msg.mddiff --git a/prompts/default/fw.topic_summary.sys.md b/prompts/fw.topic_summary.sys.mdsimilarity index 100%rename from prompts/default/fw.topic_summary.sys.mdrename to prompts/fw.topic_summary.sys.mddiff --git a/prompts/default/fw.user_message.md b/prompts/fw.user_message.mdsimilarity index 100%rename from prompts/default/fw.user_message.mdrename to prompts/fw.user_message.mddiff --git a/prompts/default/fw.warning.md b/prompts/fw.warning.mdsimilarity index 100%rename from prompts/default/fw.warning.mdrename to prompts/fw.warning.mddiff --git a/prompts/default/memory.consolidation.msg.md b/prompts/memory.consolidation.msg.mdsimilarity index 100%rename from prompts/default/memory.consolidation.msg.mdrename to prompts/memory.consolidation.msg.mddiff --git a/prompts/default/memory.consolidation.sys.md b/prompts/memory.consolidation.sys.mdsimilarity index 100%rename from prompts/default/memory.consolidation.sys.mdrename to prompts/memory.consolidation.sys.mddiff --git a/prompts/default/memory.keyword_extraction.msg.md b/prompts/memory.keyword_extraction.msg.mdsimilarity index 100%rename from prompts/default/memory.keyword_extraction.msg.mdrename to prompts/memory.keyword_extraction.msg.mddiff --git a/prompts/default/memory.keyword_extraction.sys.md b/prompts/memory.keyword_extraction.sys.mdsimilarity index 100%rename from prompts/default/memory.keyword_extraction.sys.mdrename to prompts/memory.keyword_extraction.sys.mddiff --git a/prompts/memory.memories_filter.msg.md b/prompts/memory.memories_filter.msg.mdnew file mode 100644index 000000000..d54ef9b8e--- /dev/null+++ b/prompts/memory.memories_filter.msg.md@@ -0,0 +1,10 @@+# Provide array of indices of relevant memories and solutions in relation to user message and history:++## Memories and solutions:+{{memories}}++## User message:+{{message}}++## History for context:+{{history}}diff --git a/prompts/memory.memories_filter.sys.md b/prompts/memory.memories_filter.sys.mdnew file mode 100644index 000000000..26e532a2b--- /dev/null+++ b/prompts/memory.memories_filter.sys.md@@ -0,0 +1,35 @@+# AI's job+1. The AI receives enumerated list of MEMORIES, a MESSAGE from USER and short conversation HISTORY for context+2. AI analyzes the relationship between MEMORIES and MESSAGE+HISTORY+3. AI evaluates which memories are relevant and helpful for the current situation+4. AI provides an array of indices of relevant memories and solutions for current situation++# Format+- The response format is a json array of integers corresponding to memory indices+- No other text, intro, explanation, formatting++# Rules:+- The end of the message history is more recent and thus more relevant+- Focus on USER MESSAGE if provided, use HISTORY for context+- Keep in mind that these memories should be helpful for continuing the conversation and solving problems by AI+- Consider if each memory holds real information value for the context or not++# Include only when:+- Memory is relevant to the current situation+- Memory contains helpful facts that can be used++# Never include:+- Short vague texts like "Pet inquiry" or "Programming skills" with no more detail+- Common conversation patterns like greetings+- Memories that hold no information value++# Example output+```json+[0, 2]+```++# Examples of memories that are never relevant (with explanation)+> "User has greeted me" (no information value)+> "Hello world program" (just title, no details, no context, irrelevant by itself)+> "Today is Monday" (just date, information obsolete, not helpful)+> "Memory search" (just title, irrelevant by itself)\ No newline at end of filediff --git a/prompts/memory.memories_query.msg.md b/prompts/memory.memories_query.msg.mdnew file mode 100644index 000000000..170375ac0--- /dev/null+++ b/prompts/memory.memories_query.msg.md@@ -0,0 +1,7 @@+# Provide search query for the following:++## User message:+{{message}}++## Conversation history for context:+{{history}}diff --git a/prompts/default/memory.memories_query.sys.md b/prompts/memory.memories_query.sys.mdsimilarity index 73%rename from prompts/default/memory.memories_query.sys.mdrename to prompts/memory.memories_query.sys.mdindex c9bba5979..a39c287a1 100644--- a/prompts/default/memory.memories_query.sys.md+++ b/prompts/memory.memories_query.sys.md@@ -7,13 +7,15 @@- The response format is a plain text string containing the query- No other text, no formatting+# Rules+- Only focus on facts and events, ignore common conversation patterns, greeting etc.+- Ignore AI thoughts and behavior+- Focus on USER MESSAGE if provided, use HISTORY for context+# Example```jsonUSER: "Write a song about my dog"AI: "user's dog"USER: "following the results of the biology project, summarize..."AI: "biology project results"-```--# HISTORY:-{{history}}\ No newline at end of file+```\ No newline at end of filediff --git a/prompts/memory.memories_sum.sys.md b/prompts/memory.memories_sum.sys.mdnew file mode 100644index 000000000..3f9068d84--- /dev/null+++ b/prompts/memory.memories_sum.sys.md@@ -0,0 +1,45 @@+# Assistant's job+1. The assistant receives a HISTORY of conversation between USER and AGENT+2. Assistant searches for relevant information from the HISTORY worth memorizing+3. Assistant writes notes about information worth memorizing for further use++# Format+- The response format is a JSON array of text notes containing facts to memorize+- If the history does not contain any useful information, the response will be an empty JSON array.++# Output example+~~~json+[+ "User's name is John Doe",+ "User's dog's name is Max",+]+~~~++# Rules+- Only memorize complete information that is helpful in the future+- Never memorize vague or incomplete information+- Never memorize keywords or titles only+- Focus only on relevant details and facts like names, IDs, events, opinions etc.+- Do not include irrelevant details that are of no use in the future+- Do not memorize facts that change like time, date etc.+- Do not add your own details that are not specifically mentioned in the history+- Do not memorize AI's instructions or thoughts++# Merging and cleaning+- The goal is to keep the number of new memories low while making memories more complete and detailed+- Do not break information related to the same subject into multiple memories, keep them as one text+- If there are multiple facts related to the same subject, merge them into one more detailed memory instead+- Example: Instead of three memories "User's dog is Max", "Max is 6 years old", "Max is white and brown", create one memory "User's dog is Max, 6 years old, white and brown."++# Correct examples of data worth memorizing with (explanation)+> User's name is John Doe (name is important)+> AsyncRaceError in primary_modules.py was fixed by adding a thread lock on line 123 (important event with details for context)+> Local SQL database was created, server is running on port 3306 (important event with details for context)++# Wrong examples with (explanation of error), never output memories like these+> Dog Information (no useful facts)+> User greeted with 'hi' (just conversation, not useful in the future )+> Respond with a warm greeting and invite further conversation (do not memorize AI's instructions or thoughts)+> User's name (details missing, not useful)+> Today is Monday (just date, no value in this information)+> Market inquiry (just a topic without detail)\ No newline at end of filediff --git a/prompts/default/memory.solutions_query.sys.md b/prompts/memory.solutions_query.sys.mdsimilarity index 100%rename from prompts/default/memory.solutions_query.sys.mdrename to prompts/memory.solutions_query.sys.mddiff --git a/prompts/default/memory.solutions_sum.sys.md b/prompts/memory.solutions_sum.sys.mdsimilarity index 53%rename from prompts/default/memory.solutions_sum.sys.mdrename to prompts/memory.solutions_sum.sys.mdindex b70bab830..a55359253 100644--- a/prompts/default/memory.solutions_sum.sys.md+++ b/prompts/memory.solutions_sum.sys.md@@ -1,7 +1,7 @@# Assistant's job1. The assistant receives a history of conversation between USER and AGENT2. Assistant searches for succesful technical solutions by the AGENT-3. Assistant writes notes about the succesful solution for later reproduction+3. Assistant writes notes about the succesful solutions for memorization for later reproduction# Format- The response format is a JSON array of succesfull solutions containng "problem" and "solution" properties@@ -17,12 +17,25 @@}]~~~+# Example when no solutions:~~~json[]~~~+# Rules-- Focus on important details like libraries used, code, encountered issues, error fixing etc.+- !! Only consider solutions that have been successfully executed in the conversation history, never speculate or create own scenarios+- Only memorize complex solutions containing key details required for reproduction+- Never memorize common conversation patterns like greetings, questions and answers etc.- Do not include simple solutions that don't require instructions to reproduce like file handling, web search etc.-- Do not add your own details that are not specifically mentioned in the history\ No newline at end of file+- Focus on important details like libraries used, code, encountered issues, error fixing etc.+- Do not add your own details that are not specifically mentioned in the history+- Ignore AI thoughts, focus on facts+++# Wrong examples - never output similar (with explanation):+> Problem: No specific technical problem was described in the conversation. (then the output should be [])+> Problem: The user has greeted me with 'hi'. (this is not a problem requiring solution worth memorizing)+> Problem: The user has asked to create a text file. (this is a simple operation, no instructions are necessary to reproduce)+> Problem: User asked if the AI remembers their dog, but there is no stored information about the dog in memory. Solution: Respond warmly... (this is just a conversation pattern, no instructions are necessary to reproduce)diff --git a/prompts/default/msg.memory_cleanup.md b/prompts/msg.memory_cleanup.mdsimilarity index 100%rename from prompts/default/msg.memory_cleanup.mdrename to prompts/msg.memory_cleanup.mddiff --git a/python/extensions/message_loop_prompts_after/_50_recall_memories.py b/python/extensions/message_loop_prompts_after/_50_recall_memories.pyindex e14fde39d..efcf1d0e1 100644--- a/python/extensions/message_loop_prompts_after/_50_recall_memories.py+++ b/python/extensions/message_loop_prompts_after/_50_recall_memories.py@@ -3,21 +3,27 @@ from python.helpers.extension import Extensionfrom python.helpers.memory import Memoryfrom agent import LoopDatafrom python.tools.memory_load import DEFAULT_THRESHOLD as DEFAULT_MEMORY_THRESHOLD+from python.helpers import dirty_json, errors, settingsDATA_NAME_TASK = "_recall_memories_task"class RecallMemories(Extension):- INTERVAL = 3- HISTORY = 10000- RESULTS = 5- THRESHOLD = DEFAULT_MEMORY_THRESHOLD+ # INTERVAL = 3+ # HISTORY = 10000+ # MEMORIES_MAX_SEARCH = 12+ # SOLUTIONS_MAX_SEARCH = 8+ # MEMORIES_MAX_RESULT = 5+ # SOLUTIONS_MAX_RESULT = 3+ # THRESHOLD = DEFAULT_MEMORY_THRESHOLDasync def execute(self, loop_data: LoopData = LoopData(), **kwargs):+ set = settings.get_settings()+# every 3 iterations (or the first one) recall memories- if loop_data.iteration % RecallMemories.INTERVAL == 0:+ if loop_data.iteration % set["memory_recall_interval"] == 0:task = asyncio.create_task(self.search_memories(loop_data=loop_data, **kwargs))@@ -33,9 +39,17 @@ class RecallMemories(Extension):extras = loop_data.extras_persistentif "memories" in extras:del extras["memories"]+ if "solutions" in extras:+ del extras["solutions"]++ set = settings.get_settings()# try:-++ # if recall is disabled, return+ if not set["memory_recall_enabled"]:+ return+# show full util messagelog_item = self.agent.context.log.log(type="util",@@ -43,66 +57,147 @@ class RecallMemories(Extension):)# get system message and chat history for util llm- # msgs_text = self.agent.concat_messages(- # self.agent.history[-RecallMemories.HISTORY :]- # ) # only last X messages- msgs_text = self.agent.history.output_text()[-RecallMemories.HISTORY :]- system = self.agent.read_prompt(- "memory.memories_query.sys.md", history=msgs_text- )+ system = self.agent.read_prompt("memory.memories_query.sys.md")# log query streamed by LLMasync def log_callback(content):log_item.stream(query=content)# call util llm to summarize conversation- query = await self.agent.call_utility_model(- system=system,- message=(- loop_data.user_message.output_text() if loop_data.user_message else "None"- ),- callback=log_callback,+ user_instruction = (+ loop_data.user_message.output_text() if loop_data.user_message else "None")+ history = self.agent.history.output_text()[-set["memory_recall_history_len"]:]+ message = self.agent.read_prompt(+ "memory.memories_query.msg.md", history=history, message=user_instruction+ )++ # if query preparation by AI is enabled+ if set["memory_recall_query_prep"]:+ try:+ # call util llm to generate search query from the conversation+ query = await self.agent.call_utility_model(+ system=system,+ message=message,+ callback=log_callback,+ )+ query = query.strip()+ except Exception as e:+ err = errors.format_error(e)+ self.agent.context.log.log(+ type="error", heading="Recall memories extension error:", content=err+ )+ query = ""++ # no query, no search+ if not query:+ log_item.update(+ heading="Failed to generate memory query",+ )+ return++ # otherwise use the message and history as query+ else:+ query = user_instruction + "\n\n" + history- # get solutions database+ # get memory databasedb = await Memory.get(self.agent)+ # search for general memories and fragmentsmemories = await db.search_similarity_threshold(query=query,- limit=RecallMemories.RESULTS,- threshold=RecallMemories.THRESHOLD,+ limit=set["memory_recall_memories_max_search"],+ threshold=set["memory_recall_similarity_threshold"],filter=f"area == '{Memory.Area.MAIN.value}' or area == '{Memory.Area.FRAGMENTS.value}'", # exclude solutions)- # log the short result- if not isinstance(memories, list) or len(memories) == 0:+ # search for solutions+ solutions = await db.search_similarity_threshold(+ query=query,+ limit=set["memory_recall_solutions_max_search"],+ threshold=set["memory_recall_similarity_threshold"],+ filter=f"area == '{Memory.Area.SOLUTIONS.value}'", # exclude solutions+ )++ if not memories and not solutions:log_item.update(- heading="No useful memories found",+ heading="No memories or solutions found",)return- else:- log_item.update(- heading=f"{len(memories)} memories found",- )-- # concatenate memory.page_content in memories:- memories_text = ""- for memory in memories:- memories_text += memory.page_content + "\n\n"-- # log the full results- log_item.update(memories=memories_text)- # place to prompt- memories_prompt = self.agent.parse_prompt(- "agent.system.memories.md", memories=memories_text+ # if post filtering is enabled+ if set["memory_recall_post_filter"]:+ # assemble an enumerated dict of memories and solutions for AI validation+ mems_list = {i: memory.page_content for i, memory in enumerate(memories + solutions)}++ # call AI to validate the memories+ try:+ filter = await self.agent.call_utility_model(+ system=self.agent.read_prompt("memory.memories_filter.sys.md"),+ message=self.agent.read_prompt(+ "memory.memories_filter.msg.md",+ memories=mems_list,+ history=history,+ message=user_instruction,+ ),+ )+ filter_inds = dirty_json.try_parse(filter)++ # filter memories and solutions based on filter_inds+ filtered_memories = []+ filtered_solutions = []+ mem_len = len(memories)++ # process each index in filter_inds+ # make sure filter_inds is a list and contains valid integers+ if isinstance(filter_inds, list):+ for idx in filter_inds:+ if isinstance(idx, int):+ if idx < mem_len:+ # this is a memory+ filtered_memories.append(memories[idx])+ else:+ # this is a solution, adjust index+ sol_idx = idx - mem_len+ if sol_idx < len(solutions):+ filtered_solutions.append(solutions[sol_idx])++ # replace original lists with filtered ones+ memories = filtered_memories+ solutions = filtered_solutions++ except Exception as e:+ err = errors.format_error(e)+ self.agent.context.log.log(+ type="error", heading="Failed to filter relevant memories", content=err+ )+ filter_inds = []+++ # limit the number of memories and solutions+ memories = memories[: set["memory_recall_memories_max_result"]]+ solutions = solutions[: set["memory_recall_solutions_max_result"]]++ # log the search result+ log_item.update(+ heading=f"{len(memories)} memories and {len(solutions)} relevant solutions found",)- # append to prompt- extras["memories"] = memories_prompt+ memories_txt = "\n\n".join([mem.page_content for mem in memories]) if memories else ""+ solutions_txt = "\n\n".join([sol.page_content for sol in solutions]) if solutions else ""++ # log the full results+ if memories_txt:+ log_item.update(memories=memories_txt)+ if solutions_txt:+ log_item.update(solutions=solutions_txt)- # except Exception as e:čč- # err = errors.format_error(e)- # self.agent.context.log.log(- # type="error", heading="Recall memories extension error:", content=err- # )+ # place to prompt+ if memories_txt:+ extras["memories"] = self.agent.parse_prompt(+ "agent.system.memories.md", memories=memories_txt+ )+ if solutions_txt:+ extras["solutions"] = self.agent.parse_prompt(+ "agent.system.solutions.md", solutions=solutions_txt+ )diff --git a/python/extensions/message_loop_prompts_after/_51_recall_solutions.py b/python/extensions/message_loop_prompts_after/_51_recall_solutions.pydeleted file mode 100644index be1d25be0..000000000--- a/python/extensions/message_loop_prompts_after/_51_recall_solutions.py+++ /dev/null@@ -1,112 +0,0 @@-import asyncio-from python.helpers.extension import Extension-from python.helpers.memory import Memory-from agent import LoopData-from python.tools.memory_load import DEFAULT_THRESHOLD as DEFAULT_MEMORY_THRESHOLD--DATA_NAME_TASK = "_recall_solutions_task"---class RecallSolutions(Extension):-- INTERVAL = 3- HISTORY = 10000- SOLUTIONS_COUNT = 3- INSTRUMENTS_COUNT = 3- THRESHOLD = DEFAULT_MEMORY_THRESHOLD-- async def execute(self, loop_data: LoopData = LoopData(), **kwargs):-- # every 3 iterations (or the first one) recall memories- if loop_data.iteration % RecallSolutions.INTERVAL == 0:- task = asyncio.create_task(self.search_solutions(loop_data=loop_data, **kwargs))- else:- task = None-- # set to agent to be able to wait for it- self.agent.set_data(DATA_NAME_TASK, task)-- async def search_solutions(self, loop_data: LoopData, **kwargs):-- # cleanup- extras = loop_data.extras_persistent- if "solutions" in extras:- del extras["solutions"]-- # try:-- # show full util message- log_item = self.agent.context.log.log(- type="util",- heading="Searching memory for solutions...",- )-- # get system message and chat history for util llm- # msgs_text = self.agent.concat_messages(- # self.agent.history[-RecallSolutions.HISTORY :]- # ) # only last X messages- # msgs_text = self.agent.history.current.output_text()- msgs_text = self.agent.history.output_text()[-RecallSolutions.HISTORY:]-- system = self.agent.read_prompt(- "memory.solutions_query.sys.md", history=msgs_text- )-- # log query streamed by LLM- async def log_callback(content):- log_item.stream(query=content)-- # call util llm to summarize conversation- query = await self.agent.call_utility_model(- system=system, message=loop_data.user_message.output_text() if loop_data.user_message else "None", callback=log_callback- )-- # get solutions database- db = await Memory.get(self.agent)-- solutions = await db.search_similarity_threshold(- query=query,- limit=RecallSolutions.SOLUTIONS_COUNT,- threshold=RecallSolutions.THRESHOLD,- filter=f"area == '{Memory.Area.SOLUTIONS.value}'",- )- instruments = await db.search_similarity_threshold(- query=query,- limit=RecallSolutions.INSTRUMENTS_COUNT,- threshold=RecallSolutions.THRESHOLD,- filter=f"area == '{Memory.Area.INSTRUMENTS.value}'",- )-- log_item.update(- heading=f"{len(instruments)} instruments, {len(solutions)} solutions found",- )-- if instruments:- instruments_text = ""- for instrument in instruments:- instruments_text += instrument.page_content + "\n\n"- instruments_text = instruments_text.strip()- log_item.update(instruments=instruments_text)- instruments_prompt = self.agent.read_prompt(- "agent.system.instruments.md", instruments=instruments_text- )- loop_data.system.append(instruments_prompt)-- if solutions:- solutions_text = ""- for solution in solutions:- solutions_text += solution.page_content + "\n\n"- solutions_text = solutions_text.strip()- log_item.update(solutions=solutions_text)- solutions_prompt = self.agent.parse_prompt(- "agent.system.solutions.md", solutions=solutions_text- )-- # append to prompt- extras["solutions"] = solutions_prompt-- # except Exception as e:- # err = errors.format_error(e)- # self.agent.context.log.log(- # type="error", heading="Recall solutions extension error:", content=err- # )diff --git a/python/extensions/message_loop_prompts_after/_70_include_agent_info.py b/python/extensions/message_loop_prompts_after/_70_include_agent_info.pynew file mode 100644index 000000000..0d331bcee--- /dev/null+++ b/python/extensions/message_loop_prompts_after/_70_include_agent_info.py@@ -0,0 +1,15 @@+from python.helpers.extension import Extension+from agent import LoopData++class IncludeAgentInfo(Extension):+ async def execute(self, loop_data: LoopData = LoopData(), **kwargs):++ # read prompt+ agent_info_prompt = self.agent.read_prompt(+ "agent.extras.agent_info.md",+ number=self.agent.number,+ profile=self.agent.config.profile or "Default",+ )++ # add agent info to the prompt+ loop_data.extras_temporary["agent_info"] = agent_info_promptdiff --git a/python/extensions/message_loop_prompts_after/_91_recall_wait.py b/python/extensions/message_loop_prompts_after/_91_recall_wait.pyindex 0eb9a76bc..41bbb1e7b 100644--- a/python/extensions/message_loop_prompts_after/_91_recall_wait.py+++ b/python/extensions/message_loop_prompts_after/_91_recall_wait.py@@ -1,7 +1,7 @@from python.helpers.extension import Extensionfrom agent import LoopDatafrom python.extensions.message_loop_prompts_after._50_recall_memories import DATA_NAME_TASK as DATA_NAME_TASK_MEMORIES-from python.extensions.message_loop_prompts_after._51_recall_solutions import DATA_NAME_TASK as DATA_NAME_TASK_SOLUTIONS+# from python.extensions.message_loop_prompts_after._51_recall_solutions import DATA_NAME_TASK as DATA_NAME_TASK_SOLUTIONSclass RecallWait(Extension):@@ -12,8 +12,8 @@ class RecallWait(Extension):# self.agent.context.log.set_progress("Recalling memories...")await task- task = self.agent.get_data(DATA_NAME_TASK_SOLUTIONS)- if task and not task.done():- # self.agent.context.log.set_progress("Recalling solutions...")- await task+ # task = self.agent.get_data(DATA_NAME_TASK_SOLUTIONS)+ # if task and not task.done():+ # # self.agent.context.log.set_progress("Recalling solutions...")+ # await taskdiff --git a/python/extensions/monologue_end/_50_memorize_fragments.py b/python/extensions/monologue_end/_50_memorize_fragments.pyindex 2d99a8a50..932c7bf06 100644--- a/python/extensions/monologue_end/_50_memorize_fragments.py+++ b/python/extensions/monologue_end/_50_memorize_fragments.py@@ -1,4 +1,5 @@import asyncio+from python.helpers import settingsfrom python.helpers.extension import Extensionfrom python.helpers.memory import Memoryfrom python.helpers.dirty_json import DirtyJson@@ -12,6 +13,11 @@ class MemorizeMemories(Extension):async def execute(self, loop_data: LoopData = LoopData(), **kwargs):# try:+ set = settings.get_settings()++ if not set["memory_memorize_enabled"]:+ return+# show full util messagelog_item = self.agent.context.log.log(type="util",@@ -24,6 +30,10 @@ class MemorizeMemories(Extension):async def memorize(self, loop_data: LoopData, log_item: LogItem, **kwargs):+ set = settings.get_settings()++ db = await Memory.get(self.agent)+# get system message and chat history for util llmsystem = self.agent.read_prompt("memory.memories_sum.sys.md")msgs_text = self.agent.concat_messages(self.agent.history)@@ -75,77 +85,107 @@ class MemorizeMemories(Extension):log_item.update(heading="No useful information to memorize.")returnelse:- log_item.update(heading=f"{len(memories)} entries to memorize.")+ memories_txt = "\n\n".join([str(memory) for memory in memories]).strip()+ log_item.update(heading=f"{len(memories)} entries to memorize.", memories=memories_txt)# Process memories with intelligent consolidation- memories_txt = ""total_processed = 0total_consolidated = 0+ rem = []for memory in memories:# Convert memory to plain texttxt = f"{memory}"- memories_txt += "\n\n" + txt-- try:- # Use intelligent consolidation system- from python.helpers.memory_consolidation import create_memory_consolidator- consolidator = create_memory_consolidator(- self.agent,- similarity_threshold=DEFAULT_MEMORY_THRESHOLD, # More permissive for discovery- max_similar_memories=8,- max_llm_context_memories=4- )- # Create memory item-specific log for detailed tracking- memory_log = self.agent.context.log.log(- type="util",- heading=f"Processing memory fragment: {txt[:50]}...",- temp=False,- update_progress="none" # Don't affect status bar- )+ if set["memory_memorize_consolidation"]:++ try:+ # Use intelligent consolidation system+ from python.helpers.memory_consolidation import create_memory_consolidator+ consolidator = create_memory_consolidator(+ self.agent,+ similarity_threshold=DEFAULT_MEMORY_THRESHOLD, # More permissive for discovery+ max_similar_memories=8,+ max_llm_context_memories=4+ )++ # Create memory item-specific log for detailed tracking+ memory_log = None # too many utility messages, skip log for now+ # memory_log = self.agent.context.log.log(+ # type="util",+ # heading=f"Processing memory fragment: {txt[:50]}...",+ # temp=False,+ # update_progress="none" # Don't affect status bar+ # )++ # Process with intelligent consolidation+ result_obj = await consolidator.process_new_memory(+ new_memory=txt,+ area=Memory.Area.FRAGMENTS.value,+ metadata={"area": Memory.Area.FRAGMENTS.value},+ log_item=memory_log+ )- # Process with intelligent consolidation- result_obj = await consolidator.process_new_memory(- new_memory=txt,- area=Memory.Area.FRAGMENTS.value,- metadata={"area": Memory.Area.FRAGMENTS.value},- log_item=memory_log+ # Update the individual log item with completion status but keep it temporary+ if result_obj.get("success"):+ total_consolidated += 1+ if memory_log:+ memory_log.update(+ result="Fragment processed successfully",+ heading=f"Memory fragment completed: {txt[:50]}...",+ temp=False, # Show completion message+ update_progress="none" # Show briefly then disappear+ )+ else:+ if memory_log:+ memory_log.update(+ result="Fragment processing failed",+ heading=f"Memory fragment failed: {txt[:50]}...",+ temp=False, # Show completion message+ update_progress="none" # Show briefly then disappear+ )+ total_processed += 1++ except Exception as e:+ # Log error but continue processing+ log_item.update(consolidation_error=str(e))+ total_processed += 1++ # Update final results with structured logging+ log_item.update(+ heading=f"Memorization completed: {total_processed} memories processed, {total_consolidated} intelligently consolidated",+ memories=memories_txt,+ result=f"{total_processed} memories processed, {total_consolidated} intelligently consolidated",+ memories_processed=total_processed,+ memories_consolidated=total_consolidated,+ update_progress="none")- # Update the individual log item with completion status but keep it temporary- if result_obj.get("success"):- total_consolidated += 1- memory_log.update(- result="Fragment processed successfully",- heading=f"Memory fragment completed: {txt[:50]}...",- temp=False, # Show completion message- update_progress="none" # Show briefly then disappear- )- else:- memory_log.update(- result="Fragment processing failed",- heading=f"Memory fragment failed: {txt[:50]}...",- temp=False, # Show completion message- update_progress="none" # Show briefly then disappear+ else:++ # remove previous fragments too similiar to this one+ if set["memory_memorize_replace_threshold"] > 0:+ rem += await db.delete_documents_by_query(+ query=txt,+ threshold=set["memory_memorize_replace_threshold"],+ filter=f"area=='{Memory.Area.FRAGMENTS.value}'",)- total_processed += 1-- except Exception as e:- # Log error but continue processing- log_item.update(consolidation_error=str(e))- total_processed += 1-- # Update final results with structured logging- memories_txt = memories_txt.strip()- log_item.update(- heading=f"Memorization completed: {total_processed} memories processed, {total_consolidated} intelligently consolidated",- memories=memories_txt,- result=f"{total_processed} memories processed, {total_consolidated} intelligently consolidated",- memories_processed=total_processed,- memories_consolidated=total_consolidated,- update_progress="none"- )+ if rem:+ rem_txt = "\n\n".join(Memory.format_docs_plain(rem))+ log_item.update(replaced=rem_txt)++ # insert new memory+ await db.insert_text(text=txt, metadata={"area": Memory.Area.FRAGMENTS.value})++ log_item.update(+ result=f"{len(memories)} entries memorized.",+ heading=f"{len(memories)} entries memorized.",+ )+ if rem:+ log_item.stream(result=f"\nReplaced {len(rem)} previous memories.")+++# except Exception as e:# err = errors.format_error(e)diff --git a/python/extensions/monologue_end/_51_memorize_solutions.py b/python/extensions/monologue_end/_51_memorize_solutions.pyindex 612e1c0ad..a66cd4e15 100644--- a/python/extensions/monologue_end/_51_memorize_solutions.py+++ b/python/extensions/monologue_end/_51_memorize_solutions.py@@ -1,4 +1,5 @@import asyncio+from python.helpers import settingsfrom python.helpers.extension import Extensionfrom python.helpers.memory import Memoryfrom python.helpers.dirty_json import DirtyJson@@ -11,6 +12,11 @@ class MemorizeSolutions(Extension):async def execute(self, loop_data: LoopData = LoopData(), **kwargs):# try:++ set = settings.get_settings()++ if not set["memory_memorize_enabled"]:+ return# show full util messagelog_item = self.agent.context.log.log(@@ -23,6 +29,11 @@ class MemorizeSolutions(Extension):return taskasync def memorize(self, loop_data: LoopData, log_item: LogItem, **kwargs):++ set = settings.get_settings()++ db = await Memory.get(self.agent)+# get system message and chat history for util llmsystem = self.agent.read_prompt("memory.solutions_sum.sys.md")msgs_text = self.agent.concat_messages(self.agent.history)@@ -74,14 +85,15 @@ class MemorizeSolutions(Extension):log_item.update(heading="No successful solutions to memorize.")returnelse:+ solutions_txt = "\n\n".join([str(solution) for solution in solutions]).strip()log_item.update(- heading=f"{len(solutions)} successful solutions to memorize."+ heading=f"{len(solutions)} successful solutions to memorize.", solutions=solutions_txt)# Process solutions with intelligent consolidation- solutions_txt = ""total_processed = 0total_consolidated = 0+ rem = []for solution in solutions:# Convert solution to structured text@@ -92,67 +104,91 @@ class MemorizeSolutions(Extension):else:# If solution is not a dict, convert it to stringtxt = f"# Solution\n {str(solution)}"- solutions_txt += txt + "\n\n"-- try:- # Use intelligent consolidation system- from python.helpers.memory_consolidation import create_memory_consolidator- consolidator = create_memory_consolidator(- self.agent,- similarity_threshold=DEFAULT_MEMORY_THRESHOLD, # More permissive for discovery- max_similar_memories=6, # Fewer for solutions (more complex)- max_llm_context_memories=3- )- # Create solution-specific log for detailed tracking- solution_log = self.agent.context.log.log(- type="util",- heading=f"Processing solution: {txt[:50]}...",- temp=False,- update_progress="none" # Don't affect status bar+ if set["memory_memorize_consolidation"]:+ try:+ # Use intelligent consolidation system+ from python.helpers.memory_consolidation import create_memory_consolidator+ consolidator = create_memory_consolidator(+ self.agent,+ similarity_threshold=DEFAULT_MEMORY_THRESHOLD, # More permissive for discovery+ max_similar_memories=6, # Fewer for solutions (more complex)+ max_llm_context_memories=3+ )++ # Create solution-specific log for detailed tracking+ solution_log = None # too many utility messages, skip log for now+ # solution_log = self.agent.context.log.log(+ # type="util",+ # heading=f"Processing solution: {txt[:50]}...",+ # temp=False,+ # update_progress="none" # Don't affect status bar+ # )++ # Process with intelligent consolidation+ result_obj = await consolidator.process_new_memory(+ new_memory=txt,+ area=Memory.Area.SOLUTIONS.value,+ metadata={"area": Memory.Area.SOLUTIONS.value},+ log_item=solution_log+ )++ # Update the individual log item with completion status but keep it temporary+ if result_obj.get("success"):+ total_consolidated += 1+ if solution_log:+ solution_log.update(+ result="Solution processed successfully",+ heading=f"Solution completed: {txt[:50]}...",+ temp=False, # Show completion message+ update_progress="none" # Show briefly then disappear+ )+ else:+ if solution_log:+ solution_log.update(+ result="Solution processing failed",+ heading=f"Solution failed: {txt[:50]}...",+ temp=False, # Show completion message+ update_progress="none" # Show briefly then disappear+ )+ total_processed += 1++ except Exception as e:+ # Log error but continue processing+ log_item.update(consolidation_error=str(e))+ total_processed += 1++ # Update final results with structured logging+ log_item.update(+ heading=f"Solution memorization completed: {total_processed} solutions processed, {total_consolidated} intelligently consolidated",+ solutions=solutions_txt,+ result=f"{total_processed} solutions processed, {total_consolidated} intelligently consolidated",+ solutions_processed=total_processed,+ solutions_consolidated=total_consolidated,+ update_progress="none")+ else:+ # remove previous solutions too similiar to this one+ if set["memory_memorize_replace_threshold"] > 0:+ rem += await db.delete_documents_by_query(+ query=txt,+ threshold=set["memory_memorize_replace_threshold"],+ filter=f"area=='{Memory.Area.SOLUTIONS.value}'",+ )+ if rem:+ rem_txt = "\n\n".join(Memory.format_docs_plain(rem))+ log_item.update(replaced=rem_txt)- # Process with intelligent consolidation- result_obj = await consolidator.process_new_memory(- new_memory=txt,- area=Memory.Area.SOLUTIONS.value,- metadata={"area": Memory.Area.SOLUTIONS.value},- log_item=solution_log+ # insert new solution+ await db.insert_text(text=txt, metadata={"area": Memory.Area.SOLUTIONS.value})++ log_item.update(+ result=f"{len(solutions)} solutions memorized.",+ heading=f"{len(solutions)} solutions memorized.",)+ if rem:+ log_item.stream(result=f"\nReplaced {len(rem)} previous solutions.")- # Update the individual log item with completion status but keep it temporary- if result_obj.get("success"):- total_consolidated += 1- solution_log.update(- result="Solution processed successfully",- heading=f"Solution completed: {txt[:50]}...",- temp=False, # Show completion message- update_progress="none" # Show briefly then disappear- )- else:- solution_log.update(- result="Solution processing failed",- heading=f"Solution failed: {txt[:50]}...",- temp=False, # Show completion message- update_progress="none" # Show briefly then disappear- )- total_processed += 1-- except Exception as e:- # Log error but continue processing- log_item.update(consolidation_error=str(e))- total_processed += 1-- # Update final results with structured logging- solutions_txt = solutions_txt.strip()- log_item.update(- heading=f"Solution memorization completed: {total_processed} solutions processed, {total_consolidated} intelligently consolidated",- solutions=solutions_txt,- result=f"{total_processed} solutions processed, {total_consolidated} intelligently consolidated",- solutions_processed=total_processed,- solutions_consolidated=total_consolidated,- update_progress="none"- )# except Exception as e:# err = errors.format_error(e)diff --git a/python/extensions/system_prompt/_10_system_prompt.py b/python/extensions/system_prompt/_10_system_prompt.pyindex d7bb4c253..0852734d9 100644--- a/python/extensions/system_prompt/_10_system_prompt.py+++ b/python/extensions/system_prompt/_10_system_prompt.py@@ -1,9 +1,7 @@-from datetime import datetime-from typing import Any, Optional+from typing import Anyfrom python.helpers.extension import Extensionfrom python.helpers.mcp_handler import MCPConfigfrom agent import Agent, LoopData-from python.helpers.localization import Localizationclass SystemPrompt(Extension):@@ -27,7 +25,7 @@ def get_main_prompt(agent: Agent):def get_tools_prompt(agent: Agent):prompt = agent.read_prompt("agent.system.tools.md")if agent.config.chat_model.vision:- prompt += '\n' + agent.read_prompt("agent.system.tools_vision.md")+ prompt += '\n\n' + agent.read_prompt("agent.system.tools_vision.md")return promptdiff --git a/python/helpers/extension.py b/python/helpers/extension.pyindex a96de6996..5c12d4806 100644--- a/python/helpers/extension.py+++ b/python/helpers/extension.py@@ -1,13 +1,60 @@from abc import abstractmethodfrom typing import Any-from agent import Agent-+from python.helpers import extract_tools, files+from typing import TYPE_CHECKING+if TYPE_CHECKING:+ from agent import Agent+class Extension:- def __init__(self, agent: Agent, *args, **kwargs):- self.agent = agent+ def __init__(self, agent: "Agent|None", **kwargs):+ self.agent: "Agent" = agent # type: ignore < here we ignore the type check as there are currently no extensions without an agentself.kwargs = kwargs@abstractmethodasync def execute(self, **kwargs) -> Any:- pass\ No newline at end of file+ pass+++async def call_extensions(extension_point: str, agent: "Agent|None" = None, **kwargs) -> Any:++ # get default extensions+ defaults = await _get_extensions("python/extensions/" + extension_point)+ classes = defaults++ # get agent extensions+ if agent and agent.config.profile:+ agentics = await _get_extensions("agents/" + agent.config.profile + "/extensions/" + extension_point)+ if agentics:+ # merge them, agentics overwrite defaults+ unique = {}+ for cls in defaults + agentics:+ unique[_get_file_from_module(cls.__module__)] = cls++ # sort by name+ classes = sorted(unique.values(), key=lambda cls: _get_file_from_module(cls.__module__))++ # call extensions+ for cls in classes:+ await cls(agent=agent).execute(**kwargs)+++def _get_file_from_module(module_name: str) -> str:+ return module_name.split(".")[-1]++_cache: dict[str, list[type[Extension]]] = {}+async def _get_extensions(folder:str):+ global _cache+ folder = files.get_abs_path(folder)+ if folder in _cache:+ classes = _cache[folder]+ else:+ if not files.exists(folder):+ return []+ classes = extract_tools.load_classes_from_folder(+ folder, "*", Extension+ )+ _cache[folder] = classes++ return classes+diff --git a/python/helpers/extract_tools.py b/python/helpers/extract_tools.pyindex e4d1fcb74..334a42b1b 100644--- a/python/helpers/extract_tools.py+++ b/python/helpers/extract_tools.py@@ -1,7 +1,8 @@-import re, os, importlib, inspect+import re, os, importlib, importlib.util, inspect+from types import ModuleTypefrom typing import Any, Type, TypeVarfrom .dirty_json import DirtyJson-from .files import get_abs_path+from .files import get_abs_path, deabsolute_pathimport regexfrom fnmatch import fnmatch@@ -58,6 +59,20 @@ def fix_json_string(json_string):T = TypeVar('T') # Define a generic type variable+def import_module(file_path: str) -> ModuleType:+ # Handle file paths with periods in the name using importlib.util+ abs_path = get_abs_path(file_path)+ module_name = os.path.basename(abs_path).replace('.py', '')++ # Create the module spec and load the module+ spec = importlib.util.spec_from_file_location(module_name, abs_path)+ if spec is None or spec.loader is None:+ raise ImportError(f"Could not load module from {abs_path}")++ module = importlib.util.module_from_spec(spec)+ spec.loader.exec_module(module)+ return module+def load_classes_from_folder(folder: str, name_pattern: str, base_class: Type[T], one_per_file: bool = True) -> list[Type[T]]:classes = []abs_folder = get_abs_path(folder)@@ -69,9 +84,9 @@ def load_classes_from_folder(folder: str, name_pattern: str, base_class: Type[T]# Iterate through the sorted list of filesfor file_name in py_files:- module_name = file_name[:-3] # remove .py extension- module_path = folder.replace("/", ".") + "." + module_name- module = importlib.import_module(module_path)+ file_path = os.path.join(abs_folder, file_name)+ # Use the new import_module function+ module = import_module(file_path)# Get all classes in the moduleclass_list = inspect.getmembers(module, inspect.isclass)@@ -85,3 +100,21 @@ def load_classes_from_folder(folder: str, name_pattern: str, base_class: Type[T]breakreturn classes++def load_classes_from_file(file: str, base_class: type[T], one_per_file: bool = True) -> list[type[T]]:+ classes = []+ # Use the new import_module function+ module = import_module(file)++ # Get all classes in the module+ class_list = inspect.getmembers(module, inspect.isclass)++ # Filter for classes that are subclasses of the given base_class+ # iterate backwards to skip imported superclasses+ for cls in reversed(class_list):+ if cls[1] is not base_class and issubclass(cls[1], base_class):+ classes.append(cls[1])+ if one_per_file:+ break++ return classesdiff --git a/python/helpers/files.py b/python/helpers/files.pyindex 9d0cb6f52..37199645f 100644--- a/python/helpers/files.py+++ b/python/helpers/files.py@@ -12,11 +12,12 @@ import zipfileimport importlibimport importlib.utilimport inspect+import globclass VariablesPlugin(ABC):@abstractmethod- def get_variables(self) -> dict[str, Any]: # type: ignore+ def get_variables(self, file: str, backup_dirs: list[str] | None = None) -> dict[str, Any]: # type: ignorepass@@ -36,29 +37,36 @@ def load_plugin_variables(file: str, backup_dirs: list[str] | None = None) -> diplugin_file = Noneif plugin_file and exists(plugin_file):++ from python.helpers import extract_tools+ classes = extract_tools.load_classes_from_file(plugin_file, VariablesPlugin, one_per_file=False)+ for cls in classes:+ return cls().get_variables(file, backup_dirs) # type: ignore < abstract class here is ok, it is always a subclass+# load python code and extract variables variables from it- module = None- module_name = dirname(plugin_file).replace("/", ".") + "." + basename(plugin_file, '.py')- try:- spec = importlib.util.spec_from_file_location(module_name, plugin_file)- if not spec:- return {}- module = importlib.util.module_from_spec(spec)- sys.modules[spec.name] = module- spec.loader.exec_module(module) # type: ignore- except ImportError:- return {}-- if module is None:- return {}-- # Get all classes in the module- class_list = inspect.getmembers(module, inspect.isclass)- # Filter for classes that are subclasses of VariablesPlugin- # iterate backwards to skip imported superclasses- for cls in reversed(class_list):- if cls[1] is not VariablesPlugin and issubclass(cls[1], VariablesPlugin):- return cls[1]().get_variables() # type: ignore+ # module = None+ # module_name = dirname(plugin_file).replace("/", ".") + "." + basename(plugin_file, '.py')++ # try:+ # spec = importlib.util.spec_from_file_location(module_name, plugin_file)+ # if not spec:+ # return {}+ # module = importlib.util.module_from_spec(spec)+ # sys.modules[spec.name] = module+ # spec.loader.exec_module(module) # type: ignore+ # except ImportError:+ # return {}++ # if module is None:+ # return {}++ # # Get all classes in the module+ # class_list = inspect.getmembers(module, inspect.isclass)+ # # Filter for classes that are subclasses of VariablesPlugin+ # # iterate backwards to skip imported superclasses+ # for cls in reversed(class_list):+ # if cls[1] is not VariablesPlugin and issubclass(cls[1], VariablesPlugin):+ # return cls[1]().get_variables() # type: ignorereturn {}from python.helpers.strings import sanitize_string@@ -220,6 +228,20 @@ def find_file_in_dirs(file_path, backup_dirs):f"File '{file_path}' not found in the original path or backup directories.")+def get_unique_filenames_in_dirs(dir_paths: list[str], pattern: str = "*"):+ # returns absolute paths for unique filenames, priority by order in dir_paths+ seen = set()+ result = []+ for dir_path in dir_paths:+ full_dir = get_abs_path(dir_path)+ for file_path in glob.glob(os.path.join(full_dir, pattern)):+ fname = os.path.basename(file_path)+ if fname not in seen and os.path.isfile(file_path):+ seen.add(fname)+ result.append(get_abs_path(file_path))+ # sort by filename (basename), not the full path+ result.sort(key=lambda path: os.path.basename(path))+ return resultdef remove_code_fences(text):# Pattern to match code fences with optional language specifier@@ -309,6 +331,10 @@ def get_abs_path(*relative_paths):"Convert relative paths to absolute paths based on the base directory."return os.path.join(get_base_dir(), *relative_paths)+def deabsolute_path(path:str):+ "Convert absolute paths to relative paths based on the base directory."+ return os.path.relpath(path, get_base_dir())+def fix_dev_path(path:str):"On dev environment, convert /a0/... paths to local absolute paths"from python.helpers.runtime import is_developmentdiff --git a/python/helpers/memory_consolidation.py b/python/helpers/memory_consolidation.pyindex 0fda5dd98..5d71b8912 100644--- a/python/helpers/memory_consolidation.py+++ b/python/helpers/memory_consolidation.py@@ -269,7 +269,7 @@ class MemoryConsolidator:async def _gather_consolidated_metadata(self,- db,+ db: Memory,result: ConsolidationResult,original_metadata: Dict[str, Any]) -> Dict[str, Any]:@@ -297,7 +297,7 @@ class MemoryConsolidator:# Retrieve original memories to extract their metadataif memory_ids:- original_memories = await db.aget_by_ids(memory_ids)+ original_memories = await db.db.aget_by_ids(memory_ids)# Merge ALL metadata fields from original memoriesfor memory in original_memories:@@ -571,7 +571,7 @@ class MemoryConsolidator:async def _handle_keep_separate(self,- db,+ db: Memory,result: ConsolidationResult,area: str,original_metadata: Dict[str, Any], # Add original metadata parameter@@ -600,7 +600,7 @@ class MemoryConsolidator:async def _handle_merge(self,- db,+ db: Memory,result: ConsolidationResult,area: str,original_metadata: Dict[str, Any], # Add original metadata parameter@@ -634,7 +634,7 @@ class MemoryConsolidator:async def _handle_replace(self,- db,+ db: Memory,result: ConsolidationResult,area: str,original_metadata: Dict[str, Any], # Add original metadata parameter@@ -645,7 +645,7 @@ class MemoryConsolidator:# Step 1: Validate similarity scores for replacement safetyif result.memories_to_remove:# Get the memories to be removed and check their similarity scores- memories_to_check = await db.aget_by_ids(result.memories_to_remove)+ memories_to_check = await db.db.aget_by_ids(result.memories_to_remove)unsafe_replacements = []for memory in memories_to_check:@@ -710,7 +710,7 @@ class MemoryConsolidator:async def _handle_update(self,- db,+ db: Memory,result: ConsolidationResult,area: str,original_metadata: Dict[str, Any], # Add original metadata parameter@@ -728,7 +728,7 @@ class MemoryConsolidator:if memory_id and new_content:# Validate that the memory exists before attempting to delete it- existing_docs = await db.aget_by_ids([memory_id])+ existing_docs = await db.db.aget_by_ids([memory_id])if not existing_docs:PrintStyle().warning(f"Memory ID {memory_id} not found during update, skipping")continuediff --git a/python/helpers/runtime.py b/python/helpers/runtime.pyindex 78ad218ad..7fd877d78 100644--- a/python/helpers/runtime.py+++ b/python/helpers/runtime.py@@ -65,6 +65,13 @@ def get_runtime_id() -> str:runtime_id = secrets.token_hex(8)return runtime_id+def get_persistent_id() -> str:+ id = dotenv.get_dotenv_value("A0_PERSISTENT_RUNTIME_ID")+ if not id:+ id = secrets.token_hex(16)+ dotenv.save_dotenv_value("A0_PERSISTENT_RUNTIME_ID", id)+ return id+@overloadasync def call_development_function(func: Callable[..., Awaitable[T]], *args, **kwargs) -> T: ...diff --git a/python/helpers/settings.py b/python/helpers/settings.pyindex b37c284c9..4ea9a23eb 100644--- a/python/helpers/settings.py+++ b/python/helpers/settings.py@@ -50,10 +50,25 @@ class Settings(TypedDict):browser_model_vision: boolbrowser_model_kwargs: dict[str, str]- agent_prompts_subdir: str+ agent_profile: stragent_memory_subdir: stragent_knowledge_subdir: str+ memory_recall_enabled: bool+ memory_recall_interval: int+ memory_recall_history_len: int+ memory_recall_memories_max_search: int+ memory_recall_solutions_max_search: int+ memory_recall_memories_max_result: int+ memory_recall_solutions_max_result: int+ memory_recall_similarity_threshold: float+ memory_recall_query_prep: bool+ memory_recall_post_filter: bool+ memory_memorize_enabled: bool+ memory_memorize_consolidation: bool+ memory_memorize_replace_threshold: float++api_keys: dict[str, str]auth_login: str@@ -525,32 +540,18 @@ def convert_out(settings: Settings) -> SettingsOutput:agent_fields.append({- "id": "agent_prompts_subdir",- "title": "A0 Prompts Subdirectory",- "description": "Subdirectory of /prompts folder to be used by default agent no. 0. Subordinate agents can be spawned with other subdirectories, that is on their superior agent to decide. This setting affects the behaviour of the top level agent you communicate with.",+ "id": "agent_profile",+ "title": "Default agent profile",+ "description": "Subdirectory of /agents folder to be used by default agent no. 0. Subordinate agents can be spawned with other profiles, that is on their superior agent to decide. This setting affects the behaviour of the top level agent you communicate with.","type": "select",- "value": settings["agent_prompts_subdir"],+ "value": settings["agent_profile"],"options": [{"value": subdir, "label": subdir}- for subdir in files.get_subdirectories("prompts")+ for subdir in files.get_subdirectories("agents") if subdir != "_example"],})- agent_fields.append(- {- "id": "agent_memory_subdir",- "title": "Memory Subdirectory",- "description": "Subdirectory of /memory folder to use for agent memory storage. Used to separate memory storage between different instances.",- "type": "text",- "value": settings["agent_memory_subdir"],- # "options": [- # {"value": subdir, "label": subdir}- # for subdir in files.get_subdirectories("memory", exclude="embeddings")- # ],- }- )-agent_fields.append({"id": "agent_knowledge_subdir",@@ -573,6 +574,170 @@ def convert_out(settings: Settings) -> SettingsOutput:"tab": "agent",}++ memory_fields: list[SettingsField] = []++ memory_fields.append(+ {+ "id": "agent_memory_subdir",+ "title": "Memory Subdirectory",+ "description": "Subdirectory of /memory folder to use for agent memory storage. Used to separate memory storage between different instances.",+ "type": "text",+ "value": settings["agent_memory_subdir"],+ # "options": [+ # {"value": subdir, "label": subdir}+ # for subdir in files.get_subdirectories("memory", exclude="embeddings")+ # ],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_enabled",+ "title": "Memory auto-recall enabled",+ "description": "Agent Zero will automatically recall memories based on convesation context.",+ "type": "switch",+ "value": settings["memory_recall_enabled"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_query_prep",+ "title": "Auto-recall AI query preparation",+ "description": "Enables vector DB query preparation from conversation context by utility LLM for auto-recall. Improves search quality, adds 1 utility LLM call per auto-recall.",+ "type": "switch",+ "value": settings["memory_recall_query_prep"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_post_filter",+ "title": "Auto-recall AI post-filtering",+ "description": "Enables memory relevance filtering by utility LLM for auto-recall. Improves search quality, adds 1 utility LLM call per auto-recall.",+ "type": "switch",+ "value": settings["memory_recall_post_filter"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_interval",+ "title": "Memory auto-recall interval",+ "description": "Memories are recalled after every user or superior agent message. During agent's monologue, memories are recalled every X turns based on this parameter.",+ "type": "range",+ "min": 1,+ "max": 10,+ "step": 1,+ "value": settings["memory_recall_interval"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_history_len",+ "title": "Memory auto-recall history length",+ "description": "The length of conversation history passed to memory recall LLM for context (in characters).",+ "type": "number",+ "value": settings["memory_recall_history_len"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_similarity_threshold",+ "title": "Memory auto-recall similarity threshold",+ "description": "The threshold for similarity search in memory recall (0 = no similarity, 1 = exact match).",+ "type": "range",+ "min": 0,+ "max": 1,+ "step": 0.01,+ "value": settings["memory_recall_similarity_threshold"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_memories_max_search",+ "title": "Memory auto-recall max memories to search",+ "description": "The maximum number of memories returned by vector DB for further processing.",+ "type": "number",+ "value": settings["memory_recall_memories_max_search"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_memories_max_result",+ "title": "Memory auto-recall max memories to use",+ "description": "The maximum number of memories to inject into A0's context window.",+ "type": "number",+ "value": settings["memory_recall_memories_max_result"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_solutions_max_search",+ "title": "Memory auto-recall max solutions to search",+ "description": "The maximum number of solutions returned by vector DB for further processing.",+ "type": "number",+ "value": settings["memory_recall_solutions_max_search"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_recall_solutions_max_result",+ "title": "Memory auto-recall max solutions to use",+ "description": "The maximum number of solutions to inject into A0's context window.",+ "type": "number",+ "value": settings["memory_recall_solutions_max_result"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_memorize_enabled",+ "title": "Auto-memorize enabled",+ "description": "A0 will automatically memorize facts and solutions from conversation history.",+ "type": "switch",+ "value": settings["memory_memorize_enabled"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_memorize_consolidation",+ "title": "Auto-memorize AI consolidation",+ "description": "A0 will automatically consolidate similar memories using utility LLM. Improves memory quality over time, adds 2 utility LLM calls per memory.",+ "type": "switch",+ "value": settings["memory_memorize_consolidation"],+ }+ )++ memory_fields.append(+ {+ "id": "memory_memorize_replace_threshold",+ "title": "Auto-memorize replacement threshold",+ "description": "Only applies when AI consolidation is disabled. Replaces previous similar memories with new ones based on this threshold. 0 = replace even if not similar at all, 1 = replace only if exact match.",+ "type": "range",+ "min": 0,+ "max": 1,+ "step": 0.01,+ "value": settings["memory_memorize_replace_threshold"],+ }+ )++ memory_section: SettingsSection = {+ "id": "memory",+ "title": "Memory",+ "description": "Configuration of A0's memory system. A0 memorizes and recalls memories automatically to help it's context awareness.",+ "fields": memory_fields,+ "tab": "agent",+ }+dev_fields: list[SettingsField] = []if runtime.is_development():@@ -859,6 +1024,7 @@ def convert_out(settings: Settings) -> SettingsOutput:util_model_section,browser_model_section,embed_model_section,+ memory_section,speech_section,api_keys_section,auth_section,@@ -942,6 +1108,8 @@ def normalize_settings(settings: Settings) -> Settings:else:try:copy[key] = type(value)(copy[key]) # type: ignore+ if isinstance(copy[key], str):+ copy[key] = copy[key].strip() # strip stringsexcept (ValueError, TypeError):copy[key] = value # make default instead@@ -955,8 +1123,8 @@ def _adjust_to_version(settings: Settings, default: Settings):# starting with 0.9, the default prompt subfolder for agent no. 0 is agent0# switch to agent0 if the old default is used from v0.8if "version" not in settings or settings["version"].startswith("v0.8"):- if "agent_prompts_subdir" not in settings or settings["agent_prompts_subdir"] == "default":- settings["agent_prompts_subdir"] = "agent0"+ if "agent_profile" not in settings or settings["agent_profile"] == "default":+ settings["agent_profile"] = "agent0"def _read_settings_file() -> Settings | None:if os.path.exists(SETTINGS_FILE):@@ -1013,7 +1181,7 @@ def get_default_settings() -> Settings:chat_model_rl_input=0,chat_model_rl_output=0,util_model_provider="openrouter",- util_model_name="openai/gpt-4.1-nano",+ util_model_name="openai/gpt-4.1-mini",util_model_api_base="",util_model_ctx_length=100000,util_model_ctx_input=0.7,@@ -1032,11 +1200,24 @@ def get_default_settings() -> Settings:browser_model_api_base="",browser_model_vision=True,browser_model_kwargs={"temperature": "0"},+ memory_recall_enabled=True,+ memory_recall_interval=3,+ memory_recall_history_len=10000,+ memory_recall_memories_max_search=12,+ memory_recall_solutions_max_search=8,+ memory_recall_memories_max_result=5,+ memory_recall_solutions_max_result=3,+ memory_recall_similarity_threshold=0.7,+ memory_recall_query_prep=True,+ memory_recall_post_filter=True,+ memory_memorize_enabled=True,+ memory_memorize_consolidation=True,+ memory_memorize_replace_threshold=0.9,api_keys={},auth_login="",auth_password="",root_password="",- agent_prompts_subdir="agent0",+ agent_profile="agent0",agent_memory_subdir="default",agent_knowledge_subdir="custom",rfc_auto_docker=True,@@ -1214,12 +1395,11 @@ def get_runtime_config(set: Settings):def create_auth_token() -> str:+ runtime_id = runtime.get_persistent_id()username = dotenv.get_dotenv_value(dotenv.KEY_AUTH_LOGIN) or ""password = dotenv.get_dotenv_value(dotenv.KEY_AUTH_PASSWORD) or ""- if not username or not password:- return "0"# use base64 encoding for a more compact token with alphanumeric chars- hash_bytes = hashlib.sha256(f"{username}:{password}".encode()).digest()+ hash_bytes = hashlib.sha256(f"{runtime_id}:{username}:{password}".encode()).digest()# encode as base64 and remove any non-alphanumeric chars (like +, /, =)b64_token = base64.urlsafe_b64encode(hash_bytes).decode().replace("=", "")return b64_token[:16]diff --git a/python/tools/call_subordinate.py b/python/tools/call_subordinate.pyindex 746a4e053..0f1547c83 100644--- a/python/tools/call_subordinate.py+++ b/python/tools/call_subordinate.py@@ -16,16 +16,16 @@ class Delegation(Tool):sub.set_data(Agent.DATA_NAME_SUPERIOR, self.agent)self.agent.set_data(Agent.DATA_NAME_SUBORDINATE, sub)# set default prompt profile to new agents- sub.config.prompts_subdir = "default"+ sub.config.profile = ""# add user message to subordinate agentsubordinate: Agent = self.agent.get_data(Agent.DATA_NAME_SUBORDINATE)subordinate.hist_add_user_message(UserMessage(message=message, attachments=[]))# set subordinate prompt profile if provided, if not, keep original- prompt_profile = kwargs.get("prompt_profile")- if prompt_profile:- subordinate.config.prompts_subdir = prompt_profile+ agent_profile = kwargs.get("agent_profile")+ if agent_profile:+ subordinate.config.profile = agent_profile# run subordinate monologueresult = await subordinate.monologue()diff --git a/webui/css/messages.css b/webui/css/messages.cssindex 701b73aef..291fb7ddd 100644--- a/webui/css/messages.css+++ b/webui/css/messages.css@@ -91,6 +91,10 @@font-size: var(--font-size-small);}+.message-user .message-text{+ text-align: start;+}+.message-ai {/* border-bottom-left-radius: var(--spacing-xxs); */}diff --git a/webui/index.js b/webui/index.jsindex 9195a2ccd..8bf6ddfba 100644--- a/webui/index.js+++ b/webui/index.js@@ -330,8 +330,9 @@ async function poll() {// Get timezone from navigatorconst timezone = Intl.DateTimeFormat().resolvedOptions().timeZone;+ const log_from = lastLogVersion;const response = await sendJsonData("/poll", {- log_from: lastLogVersion,+ log_from: log_from,context: context || null,timezone: timezone,});@@ -345,9 +346,13 @@ async function poll() {if (!context) setContext(response.context);if (response.context != context) return; //skip late polls after context change+ // if the chat has been reset, restart this poll as it may have been called with incorrect log_fromif (lastLogGuid != response.log_guid) {chatHistory.innerHTML = "";lastLogVersion = 0;+ lastLogGuid = response.log_guid;+ await poll();+ return;}if (lastLogVersion != response.log_version) {