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)
| 30 | // team is exposed and the team's default agent is used as fallback. |
| 31 | // Otherwise only that one agent is exposed and used. |
| 32 | func 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 |
no test coverage detected