Skip to content

Agent Zero AI framework

Resume goals after terminal edits

Alessandro81e5f2872e27
diff --git a/plugins/_goal/AGENTS.md b/plugins/_goal/AGENTS.md
index 3a9a48c46..0c22ba1f5 100644
--- a/plugins/_goal/AGENTS.md
+++ b/plugins/_goal/AGENTS.md
@@ -22,6 +22,7 @@
- Active goals are injected into agent extras; paused and blocked goals remain visible in the UI, while complete goals are hidden.
- Goal records track accumulated active time with `elapsed_seconds` and `active_since`; pausing freezes elapsed time until resume.
- User controls may pause, resume, edit, or delete a goal; destructive delete uses inline confirmation. Model tools may create goals and mark them complete or blocked.
+- Saving an edit that reactivates a complete or blocked goal resends the edited objective so agent processing resumes.
- `/goal <objective>` creates the goal and sends the objective as the user message so the agent starts working immediately.
- `/goal auto` fills the composer with a prompt asking the agent to create and manage its own goal instead of silently sending a message.
- While a goal is active, response-tool calls are intermediate updates; only completing or blocking the goal restores normal loop termination.
diff --git a/plugins/_goal/api/goal.py b/plugins/_goal/api/goal.py
index 7dd5a47ee..13a1d2d14 100644
--- a/plugins/_goal/api/goal.py
+++ b/plugins/_goal/api/goal.py
@@ -41,6 +41,7 @@ class Goal(ApiHandler):
return {"ok": True, "goal": goals.public_goal(goal)}
def _update(self, context_id: str, input: dict) -> dict:
+ current = goals.get_goal(context_id)
goal = goals.update_goal(
context_id,
objective=input.get("objective") if "objective" in input else None,
@@ -48,7 +49,15 @@ class Goal(ApiHandler):
note=input.get("note") if "note" in input else None,
token_budget=input.get("token_budget") if "token_budget" in input else None,
)
- return {"ok": True, "goal": goals.public_goal(goal)}
+ return {
+ "ok": True,
+ "goal": goals.public_goal(goal),
+ "reactivated": (
+ current is not None
+ and current.get("status") in goals.FINAL_STATUSES
+ and goal.get("status") == "active"
+ ),
+ }
def _status(self, context_id: str, status: str) -> dict:
goal = goals.update_goal(context_id, status=status)
diff --git a/plugins/_goal/tests/test_goal_plugin.py b/plugins/_goal/tests/test_goal_plugin.py
index ebf36d859..c412665bf 100644
--- a/plugins/_goal/tests/test_goal_plugin.py
+++ b/plugins/_goal/tests/test_goal_plugin.py
@@ -125,6 +125,30 @@ async def test_goal_api_and_agent_tools(context_id: str):
assert goals.get_goal(context_id)["created_by"] == "model"
[email protected]("terminal_status", ["blocked", "complete"])
+async def test_editing_terminal_goal_requests_agent_reactivation(
+ context_id: str,
+ terminal_status: str,
+):
+ goals.create_goal(context_id, "Initial goal")
+ goals.update_goal(context_id, status=terminal_status)
+
+ response = await object.__new__(Goal).process(
+ {
+ "action": "update",
+ "context_id": context_id,
+ "objective": "Continue with the edited goal",
+ "status": "active",
+ },
+ None,
+ )
+
+ assert response["reactivated"] is True
+ assert response["goal"]["objective"] == "Continue with the edited goal"
+ assert response["goal"]["status"] == "active"
+
+
@pytest.mark.asyncio
async def test_active_goal_keeps_response_tool_running(context_id: str):
goals.create_goal(context_id, "Keep going")
diff --git a/plugins/_goal/webui/goal-store.js b/plugins/_goal/webui/goal-store.js
index 348f5f998..6a3360501 100644
--- a/plugins/_goal/webui/goal-store.js
+++ b/plugins/_goal/webui/goal-store.js
@@ -160,8 +160,17 @@ const model = {
void toastFrontendError("Goal objective is required.", "Goal");
return;
}
- await this.update({ action: "update", objective, status: "active" }, "Goal updated.");
+ const response = await this.update(
+ { action: "update", objective, status: "active" },
+ "Goal updated.",
+ );
this.editing = false;
+ if (response?.reactivated) {
+ await globalThis.sendMessage?.({
+ message: response.goal?.objective || objective,
+ context: response.goal?.context_id || this.contextId,
+ });
+ }
},
async pauseOrResume() {
@@ -194,9 +203,11 @@ const model = {
detail: { goal: this.goal, context_id: contextId },
}));
void toastFrontendSuccess(successMessage, "Goal");
+ return response;
} catch (error) {
console.error("Failed to update goal:", error);
void toastFrontendError(error?.message || "Failed to update goal.", "Goal");
+ return null;
} finally {
this.saving = false;
}