Allow creating a new goal after completion (#26681)

## Why

Users have indicated that they want an agent to be able to create a new
goal for itself after completing the previous goal. Currently, that's
not possible because agents cannot overwrite an existing goal even if
it's complete. This PR removes this limitation and allows `create_goal`
to overwrite an existing goal if it is in the `complete` state.

## What changed

`create_goal` now replaces the existing goal only when its status is
`complete`. The replacement is performed atomically in the goal store,
creates a fresh active goal with reset usage, and continues to reject
creation while any unfinished goal exists. App server clients see a
single `thread/goal/updated` event when the previous goal is replaced
with the new one.

The tool description and error message now reflect these semantics.

## What didn't change

Agents are not allowed to create a new goal (overwrite their existing
goal) if an existing goal is still active, blocked, paused, or in any
other state other than "completed".
This commit is contained in:
Eric Traut authored and GitHub committed 2026-06-09 13:23:31 -07:00
1 parent 472619f9fc
commit 36bf63a5cf
4 files changed
+36 -6

No files matched your search

+1 -1
View File
@@ -191,7 +191,7 @@ impl GoalToolExecutor {
.map_err(|err| FunctionCallError::RespondToModel(format!("failed to create goal: {err}")))?
.ok_or_else(|| {
FunctionCallError::RespondToModel(
"cannot create a new goal because this thread already has a goal; use update_goal only when the existing goal is complete"
"cannot create a new goal because this thread has an unfinished goal; complete the existing goal first"
.to_string(),
)
})?;