Skip to content

fix: add option to select existing deployment when choosing a different model#8869

Merged
huimiu merged 2 commits into
mainfrom
trangevi/fix-select-existing-model-deployment
Jun 30, 2026
Merged

fix: add option to select existing deployment when choosing a different model#8869
huimiu merged 2 commits into
mainfrom
trangevi/fix-select-existing-model-deployment

Conversation

@trangevi

@trangevi trangevi commented Jun 29, 2026

Copy link
Copy Markdown
Member

Problem

When azd ai agent init finds 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 getModelDetails prompt 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 with isNew=false, skipping the new-deployment configuration flow entirely.

Key design decisions:

  • allDeployments field on modelSelector -- populated by getModelDeploymentDetails before calling getModelDetails, so the model selector has visibility into what is already deployed without requiring a second API call.
  • existingDeploymentError sentinel -- carries the selected *project.Deployment back to the caller via the error return. This follows the existing errModelSkipped pattern and avoids changing the getModelDetails return signature.
  • No impact on --no-prompt mode -- the new option is interactive-only; headless/CI flows are unchanged.

Changes

  • init.go: Added allDeployments field to modelSelector struct
  • init_models.go: Added sentinel type, deployment picker method, new prompt choice, and caller handling
  • init_models_test.go: Added unit tests for the sentinel error type (unwrapping, message, non-interference with errModelSkipped)

Fixes: #8854

image

…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>
Copilot AI review requested due to automatic review settings June 29, 2026 21:59
@github-actions

Copy link
Copy Markdown

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Thank you for logging this issue; our team is reviewing it. If you need urgent prioritization, tag @RickWinter and @kristenwomack to let us know.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 allDeployments to the init model-selection state so prompts can offer existing deployments without an extra API call.
  • Introduced an existingDeploymentError sentinel to return a selected existing deployment from getModelDetails without 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.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/init_models.go
@github-actions github-actions Bot added the ext-agents azure.ai.agents extension label Jun 29, 2026

@jongio jongio left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/init_models.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/init_models.go
- 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>
@huimiu huimiu merged commit 6403b74 into main Jun 30, 2026
26 checks passed
@huimiu huimiu deleted the trangevi/fix-select-existing-model-deployment branch June 30, 2026 11:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ext-agents azure.ai.agents extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.

There's no option to select an existing model deployment

4 participants