MCPcopy Index your code
hub / github.com/docker/docker-agent / validateAgentInList

Function validateAgentInList

pkg/runtime/agent_delegation.go:37–51  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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").
37func 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

Callers 3

handleTaskTransferMethod · 0.85
handleHandoffMethod · 0.85
TestValidateAgentInListFunction · 0.85

Calls 3

ResultErrorFunction · 0.92
agentNamesFunction · 0.85
NameMethod · 0.65

Tested by 1

TestValidateAgentInListFunction · 0.68