Skip to content

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

Merged
JeffreyCA merged 4 commits intoAzure:mainfrom
JeffreyCA:jeffreyca/7351/ext-agents-filter-improve
Apr 7, 2026
Merged

azure.ai.agents - filter out unsupported models and locations from init prompts#7415
JeffreyCA merged 4 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

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.

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.

@rajeshkamal5050 rajeshkamal5050 force-pushed the jeffreyca/7351/ext-agents-filter-improve branch from 856c623 to 4d5e22e Compare April 2, 2026 16:33
@JeffreyCA JeffreyCA force-pushed the jeffreyca/7351/ext-agents-filter-improve branch from 4d5e22e to 6600890 Compare April 6, 2026 16:51
Updated requiredAzdVersion to be greater than 1.23.13.
Copy link
Copy Markdown
Contributor

@wbreza wbreza left a comment

Choose a reason for hiding this comment

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

Code Review — PR #7415

azure.ai.agents — filter out unsupported models and locations from init by @JeffreyCA

Summary

Clean implementation that correctly filters init prompts to supported regions and agentsV2-capable models. The modelSelector extraction elegantly addresses the partial-struct concern from the prior review round. Recovery flow alignment between code-first and manifest-based paths is well-designed.

Prior Review Regression Check

All 7 findings from @jongio's two review rounds are verified resolved:

  • Partial InitAction → ✅ Extracted modelSelector
  • slices.ContainsFunc → ✅ Applied
  • Stale doc comment → ✅ Fixed
  • Test coverage gaps → ✅ Comprehensive tests added
  • Variable shadowing → ✅ Fixed
  • Recovery flow location gap → ✅ supportedModelLocations intersection
  • go.mod replace comment → ✅ N/A (outdated)

✅ What Looks Good

  • modelSelector struct encapsulates exactly the needed dependencies — clean, testable, safe
  • slices.Clone prevents mutation of the supported regions list
  • Table-driven tests cover nil, empty, case-insensitive, whitespace, and mutation safety
  • supportedHostedAgentRegions documented with source link and vNext TODO
  • agentModelFilter always includes agentsV2 capability — correct by construction

Findings: None

No new issues found. Code is well-structured and thoroughly tested.

Overall Assessment: Approve

Note: Merge conflicts need resolution before merge.

Review performed with GitHub Copilot CLI

@JeffreyCA JeffreyCA merged commit 3cd1b3f into Azure:main Apr 7, 2026
18 checks passed
@JeffreyCA JeffreyCA deleted the jeffreyca/7351/ext-agents-filter-improve branch April 7, 2026 23:39
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

4 participants