Skip to content

Python: Add load_dotenv to get-started samples and fix chat_response_… - #6691

Merged
Giles Odigwe (giles17) merged 3 commits into
microsoft:mainfrom
amit12cool:fix/samples-dotenv-and-docs
Jun 23, 2026
Merged

Python: Add load_dotenv to get-started samples and fix chat_response_…#6691
Giles Odigwe (giles17) merged 3 commits into
microsoft:mainfrom
amit12cool:fix/samples-dotenv-and-docs

Conversation

@amit12cool

Copy link
Copy Markdown
Contributor

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

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR is linked to an issue and there is no other open PR for this issue (see Related Issue above).
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

Copilot AI review requested due to automatic review settings June 23, 2026 16:29
@moonbox3 Evan Mattson (moonbox3) added the python Usage: [Issues, PRs], Target: Python label Jun 23, 2026
@amit12cool

Copy link
Copy Markdown
Contributor Author
@microsoft-github-policy-service agree

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 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-dotenv loading (load_dotenv()) to 05_functional_workflow_with_agents.py so FOUNDRY_PROJECT_ENDPOINT / FOUNDRY_MODEL can be supplied via a .env file.
  • Update chat_response_cancellation.py docstring 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.

Comment thread python/samples/01-get-started/05_functional_workflow_with_agents.py
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@giles17
Giles Odigwe (giles17) added this pull request to the merge queue Jun 23, 2026
Merged via the queue into microsoft:main with commit 5fff0df Jun 23, 2026
36 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants