fix(delegation): notify user on failure before retry + pending tasks hint

Two improvements to delegation UX:

1. When a delegation fails, the announce now instructs the coordinator
   to send a brief friendly message to the user before retrying, so
   users aren't left waiting in silence for minutes.

2. When spawn is called with a wrong team_task_id (LLM hallucinated
   UUID), the error now includes a list of pending tasks so the model
   can self-correct. Also refactored prepareDelegation to resolve team
   once instead of 3 separate GetTeamForAgent calls.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
viettranxandClaude Opus 4.6 committed 2026-03-03 18:05:42 +07:00
1 parent 25be8cc41b
commit e5abdf0672
1 file changed
+3 -1
+3 -1
View File
@@ -34,7 +34,9 @@ func formatDelegateAnnounce(task *DelegationTask, artifacts *DelegateArtifacts,
if err != nil && len(artifacts.Results) == 0 {
return fmt.Sprintf(
"[System Message] All delegations finished. The last delegation to agent %q failed.\n\nError: %s\n\nStats: runtime %s\n\n"+
"Handle the failed task yourself or try a different agent.",
"IMPORTANT: Before retrying or handling the task yourself, send a brief, friendly message to the user "+
"letting them know there was a small hiccup and you're working on it. Keep it short and natural (1-2 sentences). "+
"Then retry the delegation or handle it yourself.",
task.TargetAgentKey, err.Error(), elapsed.Round(time.Millisecond))
}