Skip to content

Clean up env vars automatically added to agent.yaml during init#7553

Merged
JeffreyCA merged 4 commits intomainfrom
copilot/clean-up-env-vars-agent-yaml
Apr 9, 2026
Merged

Clean up env vars automatically added to agent.yaml during init#7553
JeffreyCA merged 4 commits intomainfrom
copilot/clean-up-env-vars-agent-yaml

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 7, 2026

Microsoft samples are migrating to FOUNDRY_PROJECT_ENDPOINT (auto-injected by the hosted agent platform), so azd no longer needs to bake AZURE_AI_PROJECT_ENDPOINT / AZURE_OPENAI_ENDPOINT into agent.yaml during init.

Changes

  • Remove old env vars from agent.yaml init (init_from_code.go): Stop adding AZURE_OPENAI_ENDPOINT and AZURE_AI_PROJECT_ENDPOINT to the environment_variables section. Model-specific vars like AZURE_AI_MODEL_DEPLOYMENT_NAME are still added when applicable.

  • Add FOUNDRY_ env var translation for azd ai agent run* (run.go): Locally running agents now get the same env var names the platform injects into hosted containers:

    AZURE_AI_PROJECT_ENDPOINT  → FOUNDRY_PROJECT_ENDPOINT
    AZURE_AI_PROJECT_ID        → FOUNDRY_PROJECT_ARM_ID
    AGENT_{SVC}_NAME           → FOUNDRY_AGENT_NAME
    AGENT_{SVC}_VERSION        → FOUNDRY_AGENT_VERSION
    

    Per discussion, azd env keys (AGENT_SVC_NAME_NAME, etc.) remain unchanged for multi-agent support — only the process env passed to the running agent gets the FOUNDRY_* aliases.

  • Expose ServiceName on ServiceRunContext (helpers.go): Needed to derive the service-specific AGENT_{SVC}_* keys for the FOUNDRY mapping.

  • appendEnvVar helper (init_from_code.go): Nil-safe append since EnvironmentVariables is now nil by default instead of pre-populated.

Copilot AI linked an issue Apr 7, 2026 that may be closed by this pull request
Copilot AI changed the title [WIP] Clean up env vars in agent.yaml during init Clean up env vars automatically added to agent.yaml during init Apr 7, 2026
Copilot AI requested a review from JeffreyCA April 7, 2026 00:57
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.

Translates azd env keys to FOUNDRY_* aliases for local-dev parity with hosted containers.

Issues to address:

  • run.go:389 - appendFoundryEnvVars can silently override a user-set FOUNDRY_* value when the corresponding AZURE_* key also exists in the azd env

One question: is there a FOUNDRY_* equivalent for AZURE_OPENAI_ENDPOINT? It's dropped from agent.yaml but doesn't appear in the translation mapping.

@therealjohn
Copy link
Copy Markdown
Contributor

I ran this branch and it works.

@JeffreyCA JeffreyCA marked this pull request as ready for review April 9, 2026 18:51
Copilot AI review requested due to automatic review settings April 9, 2026 18:51
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 updates the Azure AI Agents extension to stop writing legacy Azure endpoint environment variables into agent.yaml during init, and instead aligns local azd ai agent run behavior with the hosted agent container environment by translating azd env keys to FOUNDRY_* aliases.

Changes:

  • Stop adding AZURE_OPENAI_ENDPOINT and AZURE_AI_PROJECT_ENDPOINT to agent.yaml during init (model deployment vars still included when applicable).
  • Translate local azd environment values to FOUNDRY_* env vars when running agents locally (azd ai agent run).
  • Expose ServiceName on ServiceRunContext to derive AGENT_{SVC}_* keys for translation.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cli/azd/extensions/azure.ai.agents/internal/cmd/run.go Adds appendFoundryEnvVars and invokes it during local run to supply FOUNDRY_* env aliases.
cli/azd/extensions/azure.ai.agents/internal/cmd/run_test.go Adds unit tests for appendFoundryEnvVars mappings and skip behavior.
cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code.go Removes pre-populated endpoint env vars from generated agent.yaml and adds nil-safe appendEnvVar.
cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code_test.go Updates agent.yaml writing assertions to ensure removed env vars are not emitted.
cli/azd/extensions/azure.ai.agents/internal/cmd/helpers.go Adds ServiceName to ServiceRunContext and populates it during resolution.

Copilot AI and others added 3 commits April 9, 2026 18:57
…cal run

- Remove AZURE_OPENAI_ENDPOINT and AZURE_AI_PROJECT_ENDPOINT from
  environment variables automatically added to agent.yaml during init.
  These are now auto-injected as FOUNDRY_* env vars by the hosted
  agent platform.
- Add appendFoundryEnvVars() to translate azd env keys to FOUNDRY_*
  env vars in `azd ai agent run` so agent code works identically
  locally and in hosted containers.
- Add ServiceName to ServiceRunContext to support service-specific
  env var mapping (AGENT_{SVC}_NAME → FOUNDRY_AGENT_NAME, etc.)
- Add appendEnvVar() helper for nil-safe env var slice appending.
- Update tests to reflect the new behavior.

Agent-Logs-Url: https://github.com/Azure/azure-dev/sessions/aed5afe4-cc68-4bbe-9d1e-baffe28638a1

Co-authored-by: JeffreyCA <9157833+JeffreyCA@users.noreply.github.com>
When the azd environment already contains a FOUNDRY_* key (e.g.
FOUNDRY_PROJECT_ENDPOINT), the translation from the corresponding
AZURE_* key is skipped to avoid appending a duplicate that silently
overrides the user's explicit value. Applied to both static and
service-specific agent mappings.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@JeffreyCA JeffreyCA force-pushed the copilot/clean-up-env-vars-agent-yaml branch from bb4075b to bd7c8b5 Compare April 9, 2026 18:58
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 9, 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.

…fix comment

- appendFoundryEnvVars now also checks the existing env slice (from
  os.Environ()) before appending FOUNDRY_* translations, preventing
  user shell-set values from being silently overridden.
- Extract envSliceHasKey helper for the prefix check.
- Add test covering the process env scenario.
- Fix misleading test comment about AZURE_OPENAI_ENDPOINT auto-injection.

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.

Previous comments addressed. Env var collision handling and process env checks look good. Clean PR.

@JeffreyCA JeffreyCA merged commit 9466925 into main Apr 9, 2026
19 checks passed
@JeffreyCA JeffreyCA deleted the copilot/clean-up-env-vars-agent-yaml branch April 9, 2026 20:44
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.

Clean up env vars automatically added to agent.yaml during init

6 participants