Skip to content

Agent Zero AI framework

cache clearing, code exec heading trim

frdela82312f524fd
diff --git a/helpers/api.py b/helpers/api.py
index 52d0fe5c5..29ad11d1b 100644
--- a/helpers/api.py
+++ b/helpers/api.py
@@ -288,14 +288,16 @@ def register_api_route(app: Flask, lock: ThreadLockType) -> None:
def register_watchdogs():
from helpers import watchdog
- def on_api_change(items:list[watchdog.WatchItem]):
+ def on_api_change(items: list[watchdog.WatchItem]):
PrintStyle.debug("API endpoint watchdog triggered:", items)
cache.clear(CACHE_AREA)
-
watchdog.add_watchdog(
"api_handlers",
- roots=[files.get_abs_path("api")],
+ roots=[
+ files.get_abs_path(files.API_DIR),
+ files.get_abs_path(files.USER_DIR, files.API_DIR),
+ ],
patterns=["*.py"],
handler=on_api_change,
)
diff --git a/helpers/extension.py b/helpers/extension.py
index d16fb6428..cfcbf8286 100644
--- a/helpers/extension.py
+++ b/helpers/extension.py
@@ -29,6 +29,7 @@ class _Unset:
_UNSET = _Unset()
_EXTENSIONS_LOG_COUNTS: dict[str, int] = {}
+
# debug - extensions call counter
def _log_extension_call(name: str):
try:
@@ -298,20 +299,40 @@ def _get_extensions(folder: str):
cache.add(_EXTENSIONS_CACHE_AREA, folder, classes)
return classes
+
def register_extensions_watchdogs():
- from helpers import watchdog
+ from helpers import watchdog, projects
def extensions_changed(items: list[watchdog.WatchItem]):
cache.clear(_EXTENSIONS_CACHE_AREA)
cache.clear(_CLASSES_CACHE_AREA)
PrintStyle.debug("Extensions watchdog triggered:", items)
+ # extensions and usr/extensions
watchdog.add_watchdog(
- id="extensions",
+ id="extensions_base",
roots=[
files.get_abs_path(files.EXTENSIONS_DIR),
- files.get_abs_path(files.USER_DIR, files.EXTENSIONS_DIR)
- ],
- handler=extensions_changed
+ files.get_abs_path(files.USER_DIR, files.EXTENSIONS_DIR),
+ ],
+ handler=extensions_changed,
+ )
+
+ # usr/projects/**/extensions
+ watchdog.add_watchdog(
+ id="extensions_projects",
+ roots=[projects.PROJECTS_PARENT_DIR],
+ patterns=[f"*/{projects.PROJECT_META_DIR}/**/{files.EXTENSIONS_DIR}/**/*"],
+ handler=extensions_changed,
)
- # TODO - watch extensions under projects/agents
\ No newline at end of file
+
+ # agents and usr/agents
+ watchdog.add_watchdog(
+ id="extensions_agents",
+ roots=[
+ files.get_abs_path(files.AGENTS_DIR),
+ files.get_abs_path(files.USER_DIR, files.AGENTS_DIR),
+ ],
+ patterns=[f"*/{files.EXTENSIONS_DIR}/**/*"],
+ handler=extensions_changed,
+ )
\ No newline at end of file
diff --git a/helpers/files.py b/helpers/files.py
index f07ee1c91..7f95d28bd 100644
--- a/helpers/files.py
+++ b/helpers/files.py
@@ -19,6 +19,7 @@ PROJECTS_DIR = "projects"
EXTENSIONS_DIR = "extensions"
USER_DIR = "usr"
TEMP_DIR = "tmp"
+API_DIR = "api"
_base_dir = os.path.dirname(os.path.abspath(os.path.join(__file__, "../")))
class VariablesPlugin(ABC):
diff --git a/helpers/plugins.py b/helpers/plugins.py
index c3394a9e4..d7688f719 100644
--- a/helpers/plugins.py
+++ b/helpers/plugins.py
@@ -621,7 +621,7 @@ def save_plugin_config(
# or do standard load
if new_settings is not None and file_path:
files.write_file(file_path, json.dumps(new_settings))
- after_plugin_change([plugin_name])
+ # after_plugin_change([plugin_name]) # don't trigger when only config changes
def find_plugin_asset(
diff --git a/plugins/_code_execution/tools/code_execution_tool.py b/plugins/_code_execution/tools/code_execution_tool.py
index da4f000f4..46319677b 100644
--- a/plugins/_code_execution/tools/code_execution_tool.py
+++ b/plugins/_code_execution/tools/code_execution_tool.py
@@ -83,7 +83,7 @@ class CodeExecution(Tool):
text = f"{self.name} - {self.args['runtime'] if 'runtime' in self.args else 'unknown'}"
session = self.args.get("session", None)
session_text = f"[{session}] " if session or session == 0 else ""
- return f"icon://terminal {session_text}{text}"
+ return f"icon://terminal {session_text}{truncate_text_string(text, 200)}"
async def after_execution(self, response, **kwargs):
self.agent.hist_add_tool_result(self.name, response.message, **(response.additional or {}))
@@ -266,7 +266,7 @@ class CodeExecution(Tool):
last_lines.reverse()
for idx, line in enumerate(last_lines):
line = line.strip()
- line = line if len(line) <= 500 else line[:250] + line[-250:]
+ line = line if len(line) <= 500 else line[:250] + line[-250:] # only check start and end on long lines
for pat in prompt_patterns:
if pat.search(line):
PrintStyle.info(