fix: warn when agent services share a Foundry agent name#8879
Conversation
📋 Prioritization NoteThanks for the contribution! The linked issue isn't in the current milestone yet. |
There was a problem hiding this comment.
Pull request overview
Adds a deploy-time, non-blocking warning in the azure.ai.agents extension when multiple azure.ai.agent services in a project resolve to the same Foundry agent name, helping users avoid silent overwrites in Foundry.
Changes:
- Scan
azure.ai.agentservices during pre-deploy to detect duplicate resolved Foundry agent names and emit a warning once per extension process. - Add unit tests covering duplicate grouping, deterministic sorting, and skip conditions.
- Document the new warning behavior in the extension changelog.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| cli/azd/extensions/azure.ai.agents/internal/cmd/listen.go | Adds duplicate-agent-name detection and emits an advisory warning during predeploy (once per process). |
| cli/azd/extensions/azure.ai.agents/internal/cmd/listen_test.go | Adds table-driven tests for duplicate detection and skip cases. |
| cli/azd/extensions/azure.ai.agents/CHANGELOG.md | Notes the new warning behavior for azd deploy / azd up. |
jongio
left a comment
There was a problem hiding this comment.
One convention item: the new sort.* calls can be switched to slices.Sort/slices.SortFunc to match the Go 1.26+ patterns used throughout this extension. See inline suggestion for the specific change.
Fixes #8872
Problem
In an
azure.yamlwith multiplehost: azure.ai.agentservices, two or more services can carry the same agentname. Foundry uses the agentnameas an agent's unique identifier, so deploying both services creates/updates the same Foundry agent — they silently overwrite each other, and azd gives no signal.Example from the issue: services
toolbox-agent-2andtoolbox-agent-4both setname: toolbox-agent-2.Change
azd deploy/azd upnow emits a non-blocking warning when two or moreazure.ai.agentservices resolve to the same Foundry agentname, naming the colliding services so the user can give each a unique name. Deploy still proceeds.findDuplicateAgentNamesscans theazure.ai.agentservices, resolves each viaproject.LoadAgentDefinition(covers the unified inline shape, the legacy config shape, and a legacy on-diskagent.yaml), groups the azure.yaml service keys by resolved agent name, and returns groups shared by ≥2 services (deterministically sorted). Services that aren't hosted agents, can't be resolved, or have an empty name are skipped.warnDuplicateAgentNamesprints one yellow warning per group to stderr viaoutput.WithWarningFormat, matching the existing init / legacy-shape warning style.predeployHandlerbehind a newduplicateAgentNameWarnOnce sync.Once, so the project-wide scan warns at most once per process even though the handler fires per agent service — mirroring the existingdeveloperRBACOncepattern.Tests
TestFindDuplicateAgentNamescovers: no services, unique names, the issue's two-service collision, a three-way collision, multiple groups sorted by agent name, and non-agent-host / unresolvable services being skipped, plus a nil-project case.Validation
From
cli/azd/extensions/azure.ai.agents:gofmtclean,go build ./...,go vet ./internal/cmd/, and the fullinternal/cmdtest suite all pass.