fix(tools): normalize agent_id before self-check and delegation

Apply routing.NormalizeAgentID to the raw agent_id input before any
logic runs. This prevents case/whitespace variants like "ALPHA" or
" alpha " from bypassing the self-delegation guard while still
resolving to the same agent in the registry.

The normalized value is used consistently for self-check, allowlist,
SpawnSubTurn, and result attribution.

Ref: #2148
This commit is contained in:
xiaoen
2026-04-15 22:23:17 +08:00
parent 039f35563e
commit df486b9939
+5 -2
View File
@@ -4,6 +4,8 @@ import (
"context"
"fmt"
"strings"
"github.com/sipeed/picoclaw/pkg/routing"
)
// DelegateTool delegates a task to a specific named agent and waits for
@@ -61,10 +63,11 @@ func (t *DelegateTool) Parameters() map[string]any {
}
func (t *DelegateTool) Execute(ctx context.Context, args map[string]any) *ToolResult {
agentID, _ := args["agent_id"].(string)
if strings.TrimSpace(agentID) == "" {
rawAgentID, _ := args["agent_id"].(string)
if strings.TrimSpace(rawAgentID) == "" {
return ErrorResult("agent_id is required and must be a non-empty string")
}
agentID := routing.NormalizeAgentID(rawAgentID)
task, _ := args["task"].(string)
if strings.TrimSpace(task) == "" {