Add AI agent init naming safeguards#8189
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
🔗 Linked Issue RequiredThanks for the contribution! Please link a GitHub issue to this PR by adding |
There was a problem hiding this comment.
Pull request overview
This PR enhances the azure.ai.agents extension’s init/deploy UX to reduce accidental “versioning” of an existing Foundry agent by name, by allowing users to choose an explicit agent name during azd ai agent init and warning when a name already exists.
Changes:
- Added
--agent-nametoazd ai agent init, validating and writing the selected agent name into the generatedagent.yaml. - Added “existing agent name” detection and warnings during init (when the Foundry endpoint is available) and during deploy/update flows.
- Added unit tests covering agent existence detection, warning text generation, and init agent-name validation/helpers.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| cli/azd/extensions/azure.ai.agents/internal/project/service_target_agent.go | Adds agent existence check helper + standardized warning for deploy paths when an agent name already exists. |
| cli/azd/extensions/azure.ai.agents/internal/project/service_target_agent_test.go | Adds tests for agent existence detection and warning message content. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/init.go | Adds --agent-name, name validation, manifest template name updates, and init-time existing-agent conflict handling. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/init_test.go | Adds tests for --agent-name flag registration, name validation, and helper behavior. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code.go | Reuses shared agent-name resolution + adds existing-agent conflict check before writing definition name. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code_test.go | Strengthens sanitizeAgentName test by asserting the result is a valid agent name. |
Comments suppressed due to low confidence (1)
cli/azd/extensions/azure.ai.agents/internal/cmd/init.go:369
- resolveExistingAgentNameConflict silently skips the existing-agent check when Environment().GetValue returns an error. This can cause the new naming safeguard to be bypassed without any user feedback (and without logging), even though the Foundry endpoint might be available. Consider either returning an error, or at least emitting a warning/debug log when the env lookup fails so users understand the check could not be performed.
endpointResp, err := azdClient.Environment().GetValue(ctx, &azdext.GetEnvRequest{
EnvName: environment.Name,
Key: "AZURE_AI_PROJECT_ENDPOINT",
})
if err != nil || endpointResp == nil || endpointResp.Value == "" {
return agentName, nil
}
| func existingAgentWarning(agentName string) string { | ||
| return output.WithWarningFormat( | ||
| "An agent named '%s' already exists in this Foundry project. "+ | ||
| "Deploying with this name will create a new version of the existing agent, not a separate agent.\n", | ||
| agentName, | ||
| ) | ||
| } |
| func existingAgentVersionWarning(agentName string) string { | ||
| return output.WithWarningFormat( | ||
| "An agent named '%s' already exists in this Foundry project. "+ | ||
| "Deploying with this name will create a new version of the existing agent, not a separate agent.\n", | ||
| agentName, | ||
| ) | ||
| } |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
@copilot apply changes based on the comments in this thread |
…al/pkg/agents Agent-Logs-Url: https://github.com/Azure/azure-dev/sessions/973eae4f-d50f-4cb3-b9b3-71725592ea3b Co-authored-by: glharper <64209257+glharper@users.noreply.github.com>
Done in c40b49e. Extracted the shared |
|
@copilot resolve the merge conflicts in this pull request |
…t-unique-agent-name # Conflicts: # cli/azd/extensions/azure.ai.agents/internal/project/service_target_agent_test.go Co-authored-by: glharper <64209257+glharper@users.noreply.github.com>
jongio
left a comment
There was a problem hiding this comment.
Reviewed 7 files (+605/-14). Clean approach to the naming safeguards. The existence.go extraction is well-placed, and the init flow integration is solid. A few minor observations below.
| "google.golang.org/grpc/status" | ||
| ) | ||
|
|
||
| type fakeAgentGetter struct { |
There was a problem hiding this comment.
low fakeAgentGetter here and fakeAgentExistenceClient in service_target_agent_test.go are structurally identical - both test agents.AgentExists with the same logic. Since AgentExists lives in the agents package, its unit tests could live in existence_test.go there, and each consumer test file would focus on its own integration.
| EnvName: environment.Name, | ||
| Key: "AZURE_AI_PROJECT_ENDPOINT", | ||
| }) | ||
| if err != nil || endpointResp == nil || endpointResp.Value == "" { |
There was a problem hiding this comment.
low When GetValue fails or returns empty, this silently returns the original name with no signal. A log.Printf here would help debugging when the naming check doesn't fire as expected.
| } | ||
| } | ||
|
|
||
| func nextAgentNameSuggestion(agentName string) string { |
There was a problem hiding this comment.
nit This always suggests -2 as a suffix. If my-agent-2 also exists, the next suggestion becomes my-agent-2-2. Not a big deal since users can type any name, but an increment-aware suffix would be slightly smoother UX.
Summary
Addresses #8107