Skip to content

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

Draft
Copilot wants to merge 3 commits intomainfrom
copilot/clean-up-env-vars-agent-yaml
Draft

Clean up env vars automatically added to agent.yaml during init#7553
Copilot wants to merge 3 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.

…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>
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.

{"AZURE_AI_PROJECT_ID", "FOUNDRY_PROJECT_ARM_ID"},
}

for _, m := range staticMappings {
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.

[MEDIUM] If FOUNDRY_PROJECT_ENDPOINT is already set in the azd env (or inherited from the shell), this appends a duplicate entry. Most platforms use last-value-wins, so the translation silently overrides the explicit value.

Consider skipping when the foundry key already exists:

Suggested change
for _, m := range staticMappings {
for _, m := range staticMappings {
if v := azdEnv[m.azdKey]; v != "" {
if _, exists := azdEnv[m.foundryKey]; !exists {
env = append(env, fmt.Sprintf("%s=%s", m.foundryKey, v))
}
}
}

Same pattern applies to the agentMappings loop below.

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>
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

4 participants