Skip to content

Agent Zero AI framework

update checker

frdel269aafdc284e
diff --git a/python/api/message.py b/python/api/message.py
index d3c18d47c..bd378e4f7 100644
--- a/python/api/message.py
+++ b/python/api/message.py
@@ -1,7 +1,7 @@
from agent import AgentContext, UserMessage
from python.helpers.api import ApiHandler, Request, Response
-from python.helpers import files
+from python.helpers import files, extension
import os
from werkzeug.utils import secure_filename
from python.helpers.defer import DeferredTask
@@ -55,6 +55,12 @@ class Message(ApiHandler):
# Obtain agent context
context = self.use_context(ctxid)
+ # call extension point, alow it to modify data
+ data = { "message": message, "attachment_paths": attachment_paths }
+ await extension.call_extensions("user_message_ui", agent=context.get_agent(), data=data)
+ message = data.get("message", "")
+ attachment_paths = data.get("attachment_paths", [])
+
# Store attachments in agent data
# context.agent0.set_data("attachments", attachment_paths)
diff --git a/python/extensions/user_message_ui/_10_update_check.py b/python/extensions/user_message_ui/_10_update_check.py
new file mode 100644
index 000000000..ad967f44d
--- /dev/null
+++ b/python/extensions/user_message_ui/_10_update_check.py
@@ -0,0 +1,58 @@
+from python.helpers import notification
+from python.helpers.extension import Extension
+from agent import LoopData
+from python.helpers import settings, update_check
+import datetime
+
+
+# check for newer versions of A0 available and send notification
+# check after user message is sent from UI, not API, MCP etc. (user is active and can see the notification)
+# do not check too often, use cooldown
+# do not notify too often unless there's a different notification
+
+last_check = datetime.datetime.fromtimestamp(0)
+check_cooldown_seconds = 60
+last_notification_id = ""
+last_notification_time = datetime.datetime.fromtimestamp(0)
+notification_cooldown_seconds = 60 * 60 * 24
+
+class UpdateCheck(Extension):
+
+ async def execute(self, loop_data: LoopData = LoopData(), text: str = "", **kwargs):
+ try:
+ global last_check, last_notification_id, last_notification_time
+
+ # first check if update check is enabled
+ current_settings = settings.get_settings()
+ if not current_settings["update_check_enabled"]:
+ return
+
+ # check if cooldown has passed
+ if (datetime.datetime.now() - last_check).total_seconds() < check_cooldown_seconds:
+ return
+ last_check = datetime.datetime.now()
+
+ # check for updates
+ version = await update_check.check_version()
+
+ # if the user should update, send notification
+ if notif := version.get("notification"):
+ if notif.get("id") != last_notification_id or (datetime.datetime.now() - last_notification_time).total_seconds() > notification_cooldown_seconds:
+ last_notification_id = notif.get("id")
+ last_notification_time = datetime.datetime.now()
+ self.send_notification(notif)
+ except Exception as e:
+ pass # no need to log if the update server is inaccessible
+
+
+ def send_notification(self, notif):
+ notifs = self.agent.context.get_notification_manager()
+ notifs.send_notification(
+ title=notif.get("title", "Newer version available"),
+ message=notif.get("message", "A newer version of Agent Zero is available. Please update to the latest version."),
+ type=notif.get("type", "info"),
+ detail=notif.get("detail", ""),
+ display_time=notif.get("display_time", 10),
+ group=notif.get("group", "update_check"),
+ priority=notif.get("priority", notification.NotificationPriority.NORMAL),
+ )
diff --git a/python/helpers/git.py b/python/helpers/git.py
index 0e112f4a7..33e3bec22 100644
--- a/python/helpers/git.py
+++ b/python/helpers/git.py
@@ -47,4 +47,11 @@ def get_git_info():
"version": version
}
- return git_info
\ No newline at end of file
+ return git_info
+
+def get_version():
+ try:
+ git_info = get_git_info()
+ return str(git_info.get("short_tag", "")).strip() or "unknown"
+ except Exception:
+ return "unknown"
\ No newline at end of file
diff --git a/python/helpers/settings.py b/python/helpers/settings.py
index d882de94c..3a202ab01 100644
--- a/python/helpers/settings.py
+++ b/python/helpers/settings.py
@@ -111,6 +111,8 @@ class Settings(TypedDict):
# LiteLLM global kwargs applied to all model calls
litellm_global_kwargs: dict[str, Any]
+ update_check_enabled: bool
+
class PartialSettings(Settings, total=False):
pass
@@ -1217,6 +1219,27 @@ def convert_out(settings: Settings) -> SettingsOutput:
"tab": "external",
}
+ # update checker section
+ update_checker_fields: list[SettingsField] = []
+
+ update_checker_fields.append(
+ {
+ "id": "update_check_enabled",
+ "title": "Enable Update Checker",
+ "description": "Enable update checker to notify about newer versions of Agent Zero.",
+ "type": "switch",
+ "value": settings["update_check_enabled"],
+ }
+ )
+
+ update_checker_section: SettingsSection = {
+ "id": "update_checker",
+ "title": "Update Checker",
+ "description": "Update checker periodically checks for new releases of Agent Zero and will notify when an update is recommended.<br>No personal data is sent to the update server, only randomized+anonymized unique ID and current version number, which help us evaluate the importance of the update in case of critical bug fixes etc.",
+ "fields": update_checker_fields,
+ "tab": "external",
+ }
+
# Backup & Restore section
backup_fields: list[SettingsField] = []
@@ -1269,6 +1292,7 @@ def convert_out(settings: Settings) -> SettingsOutput:
mcp_server_section,
a2a_section,
external_api_section,
+ update_checker_section,
backup_section,
dev_section,
# code_exec_section,
@@ -1502,6 +1526,7 @@ def get_default_settings() -> Settings:
variables="",
secrets="",
litellm_global_kwargs={},
+ update_check_enabled=True,
)
@@ -1706,8 +1731,4 @@ def create_auth_token() -> str:
def _get_version():
- try:
- git_info = git.get_git_info()
- return str(git_info.get("short_tag", "")).strip() or "unknown"
- except Exception:
- return "unknown"
+ return git.get_version()
diff --git a/python/helpers/update_check.py b/python/helpers/update_check.py
new file mode 100644
index 000000000..ce083e1c9
--- /dev/null
+++ b/python/helpers/update_check.py
@@ -0,0 +1,15 @@
+from python.helpers import git, runtime
+import hashlib
+
+async def check_version():
+ import httpx
+
+ current_version = git.get_version()
+ anonymized_id = hashlib.sha256(runtime.get_persistent_id().encode()).hexdigest()[:20]
+
+ url = "https://api.agent-zero.ai/a0-update-check"
+ payload = {"current_version": current_version, "anonymized_id": anonymized_id}
+ async with httpx.AsyncClient() as client:
+ response = await client.post(url, json=payload)
+ version = response.json()
+ return version
\ No newline at end of file