Python: Add load_dotenv to get-started samples and fix chat_response_… - #6691
Merged
Giles Odigwe (giles17) merged 3 commits intoJun 23, 2026
Merged
Conversation
…cancellation docs
Contributor
Author
@microsoft-github-policy-service agree |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves the Python samples’ “zero-config via env vars” experience for Azure AI Foundry by ensuring .env files are actually loaded in the get-started workflow sample, and by correcting configuration guidance in the cancellation sample to match the Foundry-based client it uses (Fixes #6689).
Changes:
- Add
python-dotenvloading (load_dotenv()) to05_functional_workflow_with_agents.pysoFOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODELcan be supplied via a.envfile. - Update
chat_response_cancellation.pydocstring configuration instructions to reference Foundry env vars and Azure CLI auth instead of OpenAI env vars.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| python/samples/02-agents/chat_client/chat_response_cancellation.py | Updates configuration docs to correctly describe Foundry env vars + az login for AzureCliCredential. |
| python/samples/01-get-started/05_functional_workflow_with_agents.py | Loads .env at startup so Foundry client can pick up FOUNDRY_* settings without explicit constructor args. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
chetantoshniwal
approved these changes
Jun 23, 2026
Giles Odigwe (giles17)
approved these changes
Jun 23, 2026
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.
Motivation & Context
05_functional_workflow_with_agents.py calls FoundryChatClient(credential=AzureCliCredential()) without explicit project_endpoint/model arguments, relying on FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL environment variables. However, the sample never calls load_dotenv(), so users storing credentials in a .env file get a cryptic ValueError at runtime (Model is required. Set via 'model' parameter or 'FOUNDRY_MODEL' environment variable).
Additionally, chat_response_cancellation.py had an outdated docstring referencing OPENAI_MODEL/OPENAI_API_KEY even though the sample uses FoundryChatClient with AzureCliCredential — which requires Foundry env vars, not OpenAI ones.
Description & Review Guide
What are the major changes? Added from dotenv import load_dotenv and load_dotenv() to 05_functional_workflow_with_agents.py. Fixed the configuration docstring in chat_response_cancellation.py to reference FOUNDRY_PROJECT_ENDPOINT, FOUNDRY_MODEL, and az login instead of the incorrect OpenAI env vars.
What is the impact of these changes? Sample 05 now works out of the box for users with a .env file, consistent with how chat_response_cancellation.py and other env-var-based samples already behave. The cancellation sample no longer misleads users about which credentials to set.
What do you want reviewers to focus on? Placement of load_dotenv() relative to imports in sample 05.
Related Issue
Fixes # 6689
Contribution Checklist
breaking changelabel (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.