Skip to content

Agent Zero AI framework

Return LogOutput object and update callers

frdel2cf73c4b4a28
diff --git a/agent.py b/agent.py
index ac0fb1d6c..4904734e7 100644
--- a/agent.py
+++ b/agent.py
@@ -177,7 +177,7 @@ class AgentContext:
# recursive is not used now, prepared for context hierarchy
self.output_data[key] = value
- # @extensible
+ @extensible
def output(self):
return {
"id": self.id,
diff --git a/python/api/api_log_get.py b/python/api/api_log_get.py
index e4042c5b2..44e64333d 100644
--- a/python/api/api_log_get.py
+++ b/python/api/api_log_get.py
@@ -44,7 +44,8 @@ class ApiLogGet(ApiHandler):
start_pos = max(0, total_items - length)
# Get log items from the calculated start position
- log_items = context.log.output(start=start_pos)
+ log_output = context.log.output(start=start_pos)
+ log_items = log_output.items
# Return log data with metadata
return {
diff --git a/python/helpers/log.py b/python/helpers/log.py
index 2cac02ed9..9f10ff9e3 100644
--- a/python/helpers/log.py
+++ b/python/helpers/log.py
@@ -209,6 +209,13 @@ class LogItem:
}
+@dataclass(frozen=True)
+class LogOutput:
+ items: list[dict[str, Any]]
+ start: int
+ end: int
+
+
class Log:
def __init__(self):
@@ -400,7 +407,7 @@ class Log:
if update not in seen and update < len(logs):
out.append(logs[update].output())
seen.add(update)
- return out
+ return LogOutput(items=out, start=start, end=end)
def reset(self):
with self._lock:
diff --git a/python/helpers/state_snapshot.py b/python/helpers/state_snapshot.py
index f845aa6d3..cde137cb4 100644
--- a/python/helpers/state_snapshot.py
+++ b/python/helpers/state_snapshot.py
@@ -224,7 +224,13 @@ async def build_snapshot_from_request(*, request: StateRequestV1) -> SnapshotV1:
active_context = AgentContext.get(ctxid) if ctxid else None
- logs = active_context.log.output(start=from_no) if active_context else []
+ if active_context:
+ log_output = active_context.log.output(start=from_no)
+ logs = log_output.items
+ log_end = log_output.end
+ else:
+ logs = []
+ log_end = 0
notification_manager = AgentContext.get_notification_manager()
notifications = notification_manager.output(start=notifications_from_no)
@@ -290,7 +296,7 @@ async def build_snapshot_from_request(*, request: StateRequestV1) -> SnapshotV1:
"tasks": tasks,
"logs": logs,
"log_guid": active_context.log.guid if active_context else "",
- "log_version": len(active_context.log.updates) if active_context else 0,
+ "log_version": log_end,
"log_progress": active_context.log.progress if active_context else 0,
"log_progress_active": bool(active_context.log.progress_active) if active_context else False,
"paused": active_context.paused if active_context else False,