fix: add option to select existing deployment when choosing a different model#8869
Conversation
…nt model When 'azd ai agent init' finds no matching deployment for the manifest model and the user picks 'Choose a different model', they were only shown the model catalog for new deployments. Now a 'Use an existing deployment from this project' option appears (when deployments exist), letting the user pick from already-deployed models. Changes: - Add allDeployments field to modelSelector, populated from getModelDeploymentDetails before calling getModelDetails - Add existingDeploymentError sentinel to propagate existing deployment selection back to the caller with isNew=false - Add promptExistingDeployment method for the deployment picker UI - Add 'use_existing' choice in getModelDetails prompt - Add unit tests for the sentinel error type Fixes #8854 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
📋 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
This PR improves the azd ai agent init interactive model-selection flow by adding an option to pick an existing Foundry deployment when the user chooses a different model than the one referenced in the manifest.
Changes:
- Added
allDeploymentsto the init model-selection state so prompts can offer existing deployments without an extra API call. - Introduced an
existingDeploymentErrorsentinel to return a selected existing deployment fromgetModelDetailswithout changing its return signature. - Added unit tests validating the sentinel error behavior (unwrapping/message/non-interference with
errModelSkipped).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| cli/azd/extensions/azure.ai.agents/internal/cmd/init.go | Extends modelSelector state to carry the project’s existing deployments into the model prompt flow. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/init_models.go | Adds the “use existing deployment” selection path, deployment picker, and sentinel error handling in the caller. |
| cli/azd/extensions/azure.ai.agents/internal/cmd/init_models_test.go | Adds tests for the new sentinel error type and its interaction with Go error APIs. |
jongio
left a comment
There was a problem hiding this comment.
The sentinel error pattern for carrying the selected deployment back through the error return is consistent with the existing errModelSkipped approach and avoids changing the getModelDetails signature. The scoping change to allDeployments and the listErr rename are correct.
A few observations:
- The use_existing option only appears in the else-if !a.flags.noPrompt branch (model found in catalog). If the model is not in the catalog, users go through promptForAlternativeModel and cannot pick an existing deployment. This seems intentional per the issue scope, but worth confirming.
- The label change from 'Choose a different model' to 'Choose a different model to deploy' is a nice clarity improvement given the new sibling option.
- Return cancellation errors unwrapped from promptExistingDeployment to preserve structured error metadata during gRPC serialization - Add empty-slice guard at the top of promptExistingDeployment to make the function self-contained Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Problem
When
azd ai agent initfinds no existing deployment for the manifest model (e.g.gpt-4.1) and the user picks "Choose a different model", they are only shown the model catalog for deploying a new model. There is no way to select from models already deployed in the Foundry project.Approach
The
getModelDetailsprompt now includes a "Use an existing deployment from this project" option (shown only when the project has deployments). Selecting it shows a sorted picker of all existing deployments and returns the chosen one withisNew=false, skipping the new-deployment configuration flow entirely.Key design decisions:
allDeploymentsfield onmodelSelector-- populated bygetModelDeploymentDetailsbefore callinggetModelDetails, so the model selector has visibility into what is already deployed without requiring a second API call.existingDeploymentErrorsentinel -- carries the selected*project.Deploymentback to the caller via the error return. This follows the existingerrModelSkippedpattern and avoids changing thegetModelDetailsreturn signature.--no-promptmode -- the new option is interactive-only; headless/CI flows are unchanged.Changes
init.go: AddedallDeploymentsfield tomodelSelectorstructinit_models.go: Added sentinel type, deployment picker method, new prompt choice, and caller handlinginit_models_test.go: Added unit tests for the sentinel error type (unwrapping, message, non-interference witherrModelSkipped)Fixes: #8854