From 7f8efb9e62fd865c3a4de5a5b51682754cb643f6 Mon Sep 17 00:00:00 2001 From: Eric Jacksch Date: Thu, 19 Mar 2026 23:10:29 -0400 Subject: [PATCH] feat(subagent): attribute subagent responses with agent name When a named subagent (e.g. agent_id="karen") completes a task, its response is now prefixed with the agent's name in bold so the user can tell which agent produced the result. Self-spawns (no agent_id) are unaffected. Co-Authored-By: Claude Sonnet 4.6 --- pkg/tools/subagent.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/pkg/tools/subagent.go b/pkg/tools/subagent.go index de450eb47..377cc9c94 100644 --- a/pkg/tools/subagent.go +++ b/pkg/tools/subagent.go @@ -3,12 +3,22 @@ package tools import ( "context" "fmt" + "strings" "sync" "time" "github.com/sipeed/picoclaw/pkg/providers" ) +// attributedContent prepends "AgentName: " to content when agentID is non-empty. +func attributedContent(agentID, content string) string { + if strings.TrimSpace(agentID) == "" { + return content + } + name := strings.ToUpper(agentID[:1]) + agentID[1:] + return "**" + name + ":** " + content +} + type SubagentTask struct { ID string Task string @@ -255,7 +265,7 @@ After completing the task, provide a clear summary of what was done.` loopResult.Iterations, loopResult.Content, ), - ForUser: loopResult.Content, + ForUser: attributedContent(task.AgentID, loopResult.Content), Silent: false, IsError: false, Async: false, @@ -326,6 +336,7 @@ func (t *SubagentTool) Execute(ctx context.Context, args map[string]any) *ToolRe } label, _ := args["label"].(string) + agentID, _ := args["agent_id"].(string) if t.manager == nil { return ErrorResult("Subagent manager not configured").WithError(fmt.Errorf("manager is nil")) @@ -383,7 +394,7 @@ func (t *SubagentTool) Execute(ctx context.Context, args map[string]any) *ToolRe return &ToolResult{ ForLLM: llmContent, - ForUser: userContent, + ForUser: attributedContent(agentID, userContent), Silent: false, IsError: false, Async: false,