MCPcopy
hub / github.com/docker/docker-agent / newAgentPolicy

Function newAgentPolicy

pkg/chatserver/agent.go:32–44  ·  view source on GitHub ↗

newAgentPolicy validates the requested agent name against the team and returns the selection policy. If agentName is empty, every agent in the team is exposed and the team's default agent is used as fallback. Otherwise only that one agent is exposed and used.

(t *team.Team, agentName string)

Source from the content-addressed store, hash-verified

30// team is exposed and the team's default agent is used as fallback.
31// Otherwise only that one agent is exposed and used.
32func newAgentPolicy(t *team.Team, agentName string) (agentPolicy, error) {
33 if agentName != "" {
34 if !slices.Contains(t.AgentNames(), agentName) {
35 return agentPolicy{}, fmt.Errorf("agent %q not found", agentName)
36 }
37 return agentPolicy{exposed: []string{agentName}, fallback: agentName}, nil
38 }
39 a, err := t.DefaultAgent()
40 if err != nil {
41 return agentPolicy{}, fmt.Errorf("resolving default agent: %w", err)
42 }
43 return agentPolicy{exposed: t.AgentNames(), fallback: a.Name()}, nil
44}
45
46// pick returns the agent name to use for a request. The "model" field is
47// honoured when it matches an exposed agent; otherwise we silently fall

Callers 1

RunFunction · 0.85

Calls 3

AgentNamesMethod · 0.80
DefaultAgentMethod · 0.80
NameMethod · 0.65

Tested by

no test coverage detected