Clean up env vars automatically added to agent.yaml during init#7553
Draft
Clean up env vars automatically added to agent.yaml during init#7553
Conversation
…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
jongio
reviewed
Apr 7, 2026
Member
jongio
left a comment
There was a problem hiding this comment.
Translates azd env keys to FOUNDRY_* aliases for local-dev parity with hosted containers.
Issues to address:
- run.go:389 -
appendFoundryEnvVarscan silently override a user-setFOUNDRY_*value when the correspondingAZURE_*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 { |
Member
There was a problem hiding this comment.
[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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Microsoft samples are migrating to
FOUNDRY_PROJECT_ENDPOINT(auto-injected by the hosted agent platform), so azd no longer needs to bakeAZURE_AI_PROJECT_ENDPOINT/AZURE_OPENAI_ENDPOINTintoagent.yamlduring init.Changes
Remove old env vars from agent.yaml init (
init_from_code.go): Stop addingAZURE_OPENAI_ENDPOINTandAZURE_AI_PROJECT_ENDPOINTto theenvironment_variablessection. Model-specific vars likeAZURE_AI_MODEL_DEPLOYMENT_NAMEare 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: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
ServiceNameonServiceRunContext(helpers.go): Needed to derive the service-specificAGENT_{SVC}_*keys for the FOUNDRY mapping.appendEnvVarhelper (init_from_code.go): Nil-safe append sinceEnvironmentVariablesis now nil by default instead of pre-populated.