Clean up env vars automatically added to agent.yaml during init#7553
Clean up env vars automatically added to agent.yaml during init#7553
Conversation
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.
|
I ran this branch and it works. |
There was a problem hiding this comment.
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_ENDPOINTandAZURE_AI_PROJECT_ENDPOINTtoagent.yamlduring 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
ServiceNameonServiceRunContextto deriveAGENT_{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. |
cli/azd/extensions/azure.ai.agents/internal/cmd/init_from_code_test.go
Outdated
Show resolved
Hide resolved
…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>
bb4075b to
bd7c8b5
Compare
📋 Prioritization NoteThanks for the contribution! The linked issue isn't in the current milestone yet. |
…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>
jongio
left a comment
There was a problem hiding this comment.
Previous comments addressed. Env var collision handling and process env checks look good. Clean PR.
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.