Skip to content

feat: add azd ai agent project commands for Foundry endpoint management#8162

Merged
trangevi merged 4 commits into
mainfrom
hui/ai-project-command
May 14, 2026
Merged

feat: add azd ai agent project commands for Foundry endpoint management#8162
trangevi merged 4 commits into
mainfrom
hui/ai-project-command

Conversation

@huimiu
Copy link
Copy Markdown
Member

@huimiu huimiu commented May 13, 2026

Summary

Adds azd ai agent project command group to the azure.ai.agents extension, enabling users to persist and resolve a Microsoft Foundry project endpoint without requiring an azd environment or explicit flags on every command.

Changes

  • New project command group (project set, project unset, project show): persists the Foundry project endpoint in ~/.azd/config.json under extensions.ai-agents.context.endpoint.
  • 5-level endpoint resolution cascade in agent_context.go: resolves from (1) --project-endpoint flag, (2) active azd env AZURE_AI_PROJECT_ENDPOINT, (3) global config, (4) host env var FOUNDRY_PROJECT_ENDPOINT, then (5) structured error with actionable guidance.
  • Endpoint validation (project_endpoint.go): validates and normalizes Foundry https://*.services.ai.azure.com URLs; surfaces a non-fatal warning when the path doesn't match /api/projects/<name>.
  • Global config persistence (project_context_store.go): read/write helpers for the global config store.
  • Docs: added FOUNDRY_PROJECT_ENDPOINT to environment-variables.md.
  • Tests: unit tests for validation, resolution cascade, and all three subcommands.

Related

Closes #8124
Design spec: #8152

Test

image
  • Set a project endpoint
  • Show the resolved endpoint
  • Show as JSON (stable machine-readable output)
  • Invalid scheme → should reject with structured error
  • Non-Foundry host → should reject
  • Clear the stored endpoint

Copilot AI review requested due to automatic review settings May 13, 2026 09:13
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 13, 2026

📋 Prioritization Note

Thanks for the contribution! The linked issue isn't in the current milestone yet.
Review may take a bit longer — reach out to @rajeshkamal5050 or @kristenwomack if you'd like to discuss prioritization.

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

This PR extends the azure.ai.agents azd extension with a new project command group for managing a persisted Microsoft Foundry project endpoint, and upgrades endpoint resolution for agent commands to use a 5-level cascade (flag → azd env → global config → host env var → structured error). It also adds endpoint URL validation/normalization, introduces a new structured error code, and documents the new host environment variable.

Changes:

  • Added azd ai agent project {set|unset|show} commands to persist/clear/inspect the Foundry project endpoint in ~/.azd/config.json.
  • Implemented a shared 5-level project endpoint resolver and updated agent endpoint resolution to use it.
  • Added endpoint validation helpers, unit tests for validation + parts of the resolver, and documented FOUNDRY_PROJECT_ENDPOINT.

Reviewed changes

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

Show a summary per file
File Description
cli/azd/extensions/azure.ai.agents/internal/exterrors/codes.go Adds missing_project_endpoint error code for structured dependency errors.
cli/azd/extensions/azure.ai.agents/internal/cmd/root.go Wires the new project command group into the extension command tree.
cli/azd/extensions/azure.ai.agents/internal/cmd/project.go Defines the project parent command and registers set/unset/show subcommands.
cli/azd/extensions/azure.ai.agents/internal/cmd/project_set.go Implements project set to validate and persist an endpoint (with warnings).
cli/azd/extensions/azure.ai.agents/internal/cmd/project_unset.go Implements project unset to clear persisted endpoint (idempotent).
cli/azd/extensions/azure.ai.agents/internal/cmd/project_show.go Implements project show to resolve and print endpoint + source (table/json).
cli/azd/extensions/azure.ai.agents/internal/cmd/project_endpoint.go Adds endpoint source enum, host suffix validation, normalization, and missing-endpoint error helper.
cli/azd/extensions/azure.ai.agents/internal/cmd/project_context_store.go Adds global config read/write helpers for persisted endpoint context.
cli/azd/extensions/azure.ai.agents/internal/cmd/agent_endpoint.go Adds guidance comment about keeping host-suffix validation logic in sync.
cli/azd/extensions/azure.ai.agents/internal/cmd/agent_context.go Implements the 5-level resolver and routes resolveAgentEndpoint through it.
cli/azd/extensions/azure.ai.agents/internal/cmd/project_unset_test.go Adds basic command-arg and output-flag configuration tests for unset.
cli/azd/extensions/azure.ai.agents/internal/cmd/project_show_test.go Adds basic command-arg/flag tests plus helper-function tests for show.
cli/azd/extensions/azure.ai.agents/internal/cmd/project_set_test.go Adds basic command-arg and output-flag configuration tests for set.
cli/azd/extensions/azure.ai.agents/internal/cmd/project_resolver_test.go Adds unit tests for resolver flag precedence + host env fallback + error cases.
cli/azd/extensions/azure.ai.agents/internal/cmd/project_endpoint_test.go Adds unit tests for endpoint validation/normalization and missing-endpoint error typing.
cli/azd/docs/environment-variables.md Documents FOUNDRY_PROJECT_ENDPOINT as a host-level fallback source.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/project_show.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/agent_context.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/project_resolver_test.go Outdated
@huimiu huimiu changed the title feat(azure.ai.agents): add azd ai agent project commands for Foundry endpoint management feat: add azd ai agent project commands for Foundry endpoint management May 13, 2026
huimiu and others added 2 commits May 13, 2026 18:48
- project_show.go: use errors.AsType[*azdext.LocalError] per AGENTS.md guidance
- agent_context.go: extract azd-hosted source lookup (levels 2 + 3) into a
  stubbable seam (readAzdHostedSourcesFunc) for testability
- project_resolver_test.go: add unit tests for AZURE_AI_PROJECT_ENDPOINT from
  azd env (success + invalid) and global config (success + invalid), plus a
  hosted-sources error propagation test; isolate non-azd tests from any
  developer-machine AZD_SERVER by clearing the env var and stubbing the seam

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

Clean implementation of the project command group. The 5-level cascade is well-designed, validation is strict at every level (no silent fallthrough on bad values), and the stubbable seams (readAzdHostedSourcesFunc, lookupEnvFunc) make the resolver testable without a running daemon. Tests cover the priority ordering and error cases thoroughly.

Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/agent_context.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/project_endpoint.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/agent_context.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/project_context_store.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/project_set.go Outdated
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/project_show.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/project_unset.go
Comment thread cli/azd/extensions/azure.ai.agents/internal/cmd/project_show.go Outdated
@huimiu
Copy link
Copy Markdown
Member Author

huimiu commented May 14, 2026

Thanks for the thorough review! Addressed all the feedback in this update:

From @jongio:

  • Added a doc comment to containsGRPCCode calling out the single-wrap limitation. Future callers will know it won't traverse errors.Join trees.
  • Unified Foundry host validation: parseAgentEndpoint now calls isFoundryHost instead of its own constant, so the two validators can't silently drift anymore when new suffixes are added.

From @trangevi:

  • Refactored project set, project show, and project unset to follow the action object pattern (ProjectSetAction.Run, etc.), for a clean separation between "prepare" and "do the work".
  • Removed the --project-endpoint flag from project show. You're right that it adds no real value. The command now always shows the fully resolved endpoint from the cascade.
  • Replaced the lookupEnvFunc seam and stubLookupEnv helper with plain t.Setenv. Agreed, mocking os.Getenv at the package level was overkill.
  • Renamed the config path from .context to .project.context so it is clearly scoped and leaves room for future per-agent context without collision.

@trangevi trangevi enabled auto-merge (squash) May 14, 2026 16:38
@trangevi
Copy link
Copy Markdown
Member

/check-enforcer override

The build is showing complete, status is just not being reported

Copy link
Copy Markdown
Contributor

@JeffreyCA JeffreyCA left a comment

Choose a reason for hiding this comment

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

Approving for cli/azd/docs/environment-variables.md change, looks good!

@trangevi trangevi merged commit 444ec22 into main May 14, 2026
30 of 32 checks passed
@huimiu huimiu deleted the hui/ai-project-command branch May 14, 2026 23:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add azd ai project set/unset/show to share a default Foundry project endpoint across azd ai commands

6 participants