validateAgentInList checks that targetAgent appears in the given agent list. Returns a tool error result if not found, or nil if the target is valid. The action describes the attempted operation (e.g. "transfer task to"), and listDesc is a human-readable description of the list (e.g. "sub-agents lis
(currentAgent, targetAgent, action, listDesc string, agents []*agent.Agent)
| 35 | // The action describes the attempted operation (e.g. "transfer task to"), |
| 36 | // and listDesc is a human-readable description of the list (e.g. "sub-agents list"). |
| 37 | func validateAgentInList(currentAgent, targetAgent, action, listDesc string, agents []*agent.Agent) *tools.ToolCallResult { |
| 38 | if slices.ContainsFunc(agents, func(a *agent.Agent) bool { return a.Name() == targetAgent }) { |
| 39 | return nil |
| 40 | } |
| 41 | if names := agentNames(agents); len(names) > 0 { |
| 42 | return tools.ResultError(fmt.Sprintf( |
| 43 | "Agent %s cannot %s %s: target agent not in %s. Available agent IDs are: %s", |
| 44 | currentAgent, action, targetAgent, listDesc, strings.Join(names, ", "), |
| 45 | )) |
| 46 | } |
| 47 | return tools.ResultError(fmt.Sprintf( |
| 48 | "Agent %s cannot %s %s: target agent not in %s. No agents are configured in this list.", |
| 49 | currentAgent, action, targetAgent, listDesc, |
| 50 | )) |
| 51 | } |
| 52 | |
| 53 | // buildTaskSystemMessage constructs the system message for a delegated task. |
| 54 | // attachedFiles, when non-empty, lists absolute paths of files the user |