Skip to content

azure.ai.agents - filter out unsupported models and locations from init prompts#7415

Open
JeffreyCA wants to merge 2 commits intoAzure:mainfrom
JeffreyCA:jeffreyca/7351/ext-agents-filter-improve
Open

azure.ai.agents - filter out unsupported models and locations from init prompts#7415
JeffreyCA wants to merge 2 commits intoAzure:mainfrom
JeffreyCA:jeffreyca/7351/ext-agents-filter-improve

Conversation

@JeffreyCA
Copy link
Copy Markdown
Contributor

@JeffreyCA JeffreyCA commented Mar 31, 2026

Resolves #7351

TODO

This PR builds on #7397 and updates the azure.ai.agents extension to filter out unsupported models (incompatible with agents) and locations from prompts during azd ai agent init. Previously, the prompts would show all Azure locations and available models.

The init flow now limits location selection to these regions via a hardcoded list (due to lack of API). It also filters model selection to ones with the agentsV2 capability so the extension only offers models that are valid for agent scenarios.

This PR also brings the code-first init path in line with the manifest-based flow. When deployment resolution cannot complete directly for the selected model and location, the extension now falls back to the shared recovery flow instead of failing early, which gives users a clearer path to recover from model or region mismatches.

Screenshots

image image image

@JeffreyCA JeffreyCA added the ext-agents azure.ai.agents extension label Mar 31, 2026
@JeffreyCA JeffreyCA force-pushed the jeffreyca/7351/ext-agents-filter-improve branch from f2eb552 to ad084b5 Compare March 31, 2026 21:44
@JeffreyCA JeffreyCA requested a review from Copilot March 31, 2026 21:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the azure.ai.agents extension init experience to avoid offering invalid Azure regions and AI models during azd ai agent init, and aligns the code-first init path with the manifest-based recovery behavior when deployment resolution can’t complete directly.

Changes:

  • Filters AI model prompts/catalog to models with the agentsV2 capability.
  • Restricts location selection during init to a hardcoded “hosted agents supported regions” allow-list via PromptLocationRequest.AllowedLocations.
  • Adjusts code-first init to fall back into the shared recovery flow when deployment candidate selection fails or can’t find a valid no-prompt capacity candidate.

Reviewed changes

Copilot reviewed 8 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
cli/azd/extensions/azure.ai.agents/internal/cmd/init.go Adds agentsV2 capability constant used for filtering models.
cli/azd/extensions/azure.ai.agents/internal/cmd/init_models.go Applies capability-based model filtering and tweaks env location update behavior.
cli/azd/extensions/azure.ai.agents/internal/cmd/init_locations.go Introduces hardcoded hosted-agent supported region allow-list for init.
cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code.go Uses shared recovery flow when direct deployment resolution/candidate selection can’t complete.
cli/azd/extensions/azure.ai.agents/internal/cmd/init_foundry_resources_helpers.go Enforces allowed locations in ensureLocation, adds shared helpers for model filtering and deployment resolution.
cli/azd/extensions/azure.ai.agents/internal/cmd/init_foundry_resources_helpers_test.go Adds unit test for agentModelFilter.
cli/azd/extensions/azure.ai.agents/go.mod Bumps azd dependency, adds local replace, and updates indirect deps.
cli/azd/extensions/azure.ai.agents/go.sum Updates dependency checksums to match go.mod changes.
cli/azd/extensions/azure.ai.agents/extension.yaml Raises required azd version to include needed host prompt features.

google.golang.org/protobuf v1.36.11
gopkg.in/yaml.v3 v3.0.1
)

Copy link

Copilot AI Mar 31, 2026

Choose a reason for hiding this comment

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

go.mod adds a replace github.com/azure/azure-dev/cli/azd => ../.. directive, but unlike some other extensions in this repo there’s no nearby comment explaining that this is for monorepo/CI local resolution. Adding a short comment (similar to extensions/azure.appservice/go.mod) would help future maintainers understand why this replace is intentionally committed and when it should be removed.

Suggested change
// Use the local azd module when developing in the monorepo or running in CI.
// Remove this replace when referencing a published azd module version.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Filters models and locations for the agents init flow. Clean refactoring of deployment resolution into smaller functions.

Findings: 0 critical, 0 high, 2 medium, 2 low

Issues to address:

  • init_from_code.go:643 - partial InitAction construction is fragile; nil-pointer risk if called methods evolve
  • init_foundry_resources_helpers_test.go:298 - test coverage gaps for new helper functions
  • init_foundry_resources_helpers.go:782 - manual loop where slices.ContainsFunc fits
  • init_foundry_resources_helpers.go:865 - doc comment stale after function rename

Note: The recovery paths in promptForModelLocationMismatch pass model.Locations as AllowedLocations rather than intersecting with supportedRegionsForInit(). Users in the recovery flow can pick a location where the model is available but the hosted agent platform is not supported.

Copy link
Copy Markdown
Member

@jongio jongio left a comment

Choose a reason for hiding this comment

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

Previous findings still apply. One more nit:

  • init_models.go:78 - err variable shadow in updateEnvLocation else block

Copy link
Copy Markdown
Member

@jongio jongio left a comment

Choose a reason for hiding this comment

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

All previous findings addressed. The modelSelector extraction is clean - proper encapsulation, lazy init, clear doc comment. The supportedModelLocations intersection fixes the recovery-flow location gap. Tests are thorough with good edge coverage (nil, empty, case-insensitive, mutation safety).

One remaining item: merge conflicts need resolution before this can merge.

JeffreyCA and others added 2 commits April 2, 2026 09:22
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@rajeshkamal5050 rajeshkamal5050 force-pushed the jeffreyca/7351/ext-agents-filter-improve branch from 856c623 to 4d5e22e Compare April 2, 2026 16:33
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.

[Issue] "azd ai agent init" lets you select un-supported locations for AI models

3 participants