Python: fix get-started samples env wiring and FunctionalWorkflow.build() removal - #7793
Closed
Linwen (linwendeng) wants to merge 1 commit into
Closed
Python: fix get-started samples env wiring and FunctionalWorkflow.build() removal#7793Linwen (linwendeng) wants to merge 1 commit into
Linwen (linwendeng) wants to merge 1 commit into
Conversation
Linwen (linwendeng)
requested review from
chetantoshniwal and
Eduard van Valkenburg (eavanvalkenburg)
as code owners
August 20, 2026 17:05
Linwen (linwendeng)
requested review from
Tao Chen (TaoChenOSU),
Giles Odigwe (giles17) and
Evan Mattson (moonbox3)
as code owners
August 20, 2026 17:05
Linwen (linwendeng)
temporarily deployed
to
github-app-auth
August 20, 2026 17:05 — with
GitHub Actions
Inactive
Linwen (linwendeng)
had a problem deploying
to
github-app-auth
August 20, 2026 17:05 — with
GitHub Actions
Error
Linwen (linwendeng)
temporarily deployed
to
github-app-auth
August 20, 2026 17:05 — with
GitHub Actions
Inactive
Linwen (linwendeng)
temporarily deployed
to
github-app-auth
August 20, 2026 17:11 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
Pull request overview
Updates Python getting-started samples to use environment-based Foundry configuration and expands setup guidance.
Changes:
- Loads Foundry endpoint/model settings from
.env. - Removes workflow
.build()calls. - Adds Foundry authentication, RBAC, and troubleshooting documentation.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
README.md |
Documents environment configuration and Foundry RBAC. |
01_hello_agent.py |
Loads Foundry settings from environment variables. |
02_add_tools.py |
Adds environment-based client configuration. |
03_multi_turn.py |
Adds environment-based client configuration. |
04_memory.py |
Adds environment-based client configuration. |
05_functional_workflow_with_agents.py |
Runs the decorated workflow directly. |
06_functional_workflow_basics.py |
Runs the decorated workflow directly. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
|
|
||
| ```bash | ||
| export FOUNDRY_PROJECT_ENDPOINT="https://<account>.services.ai.azure.com/api/projects/<project>" | ||
| export FOUNDRY_MODEL="gpt-4.1-mini" # optional, defaults to gpt-4.1-mini |
Comment on lines
+33
to
+37
| > `load_dotenv()` walks upward from the sample file, so a stale `.env` higher | ||
| > in the tree (for example `python/samples/.env` vs `python/.env`) will win. | ||
| > If a value looks wrong at runtime, check every `.env` on the path. | ||
| > Also note that already-set shell env vars take precedence over `.env` unless | ||
| > you pass `load_dotenv(override=True)`. |
| |------|--------|-------| | ||
| | `Foundry Project Runtime User` | `Microsoft.CognitiveServices/accounts/AIServices/responses/*` | Minimal role for the Responses API. | | ||
| | `Foundry User` | `Microsoft.CognitiveServices/*` | Broader; covers all Foundry data-plane calls. | | ||
| | `Cognitive Services User` | `Microsoft.CognitiveServices/*` | Equivalent breadth if `Foundry User` isn't available. | |
Comment on lines
+50
to
+52
| The path is served by the **AIServices** RBAC namespace, so the | ||
| `Azure AI Developer` role — which only grants | ||
| `Microsoft.CognitiveServices/accounts/OpenAI/*` — is **not** sufficient. |
| async def main() -> None: | ||
| workflow_instance = poem_workflow.build() | ||
| result = await workflow_instance.run("a cat learning to code") | ||
| result = await poem_workflow.run("a cat learning to code") |
| # <run_workflow> | ||
| workflow_instance = text_workflow.build() | ||
| result = await workflow_instance.run("hello world") | ||
| result = await text_workflow.run("hello world") |
… FunctionalWorkflow build Address Copilot review comments on PR microsoft#7793. - 01-04: require FOUNDRY_MODEL via os.environ[...] to match python/samples/AGENTS.md contract (no default). - README: document load_dotenv first-match behavior (nearest .env wins). - README: correct Azure AI Developer wording — it lacks AIServices/responses/*, not just 'OpenAI wildcard'. - README: drop 'Cognitive Services User' from the role table (not a Foundry-native role). - 05, 06: restore FunctionalWorkflowDefinition.build() before .run() — @workflow returns the stateless definition.
Linwen (linwendeng)
force-pushed
the
fix/get-started-samples
branch
from
August 20, 2026 20:01
b2b132e to
92114ae
Compare
Linwen (linwendeng)
temporarily deployed
to
github-app-auth
August 20, 2026 20:01 — with
GitHub Actions
Inactive
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
The
python/samples/01-get-started/samples had two rough edges that blocked afirst-time user from running them out of the box:
02_add_tools.py,03_multi_turn.py, and04_memory.pyhard-codedproject_endpoint="https://your-project.services.ai.azure.com"andmodel="gpt-4o", so they crashed until the reader edited the source. Sample01_hello_agent.pyalready read fromFOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL— this PR brings the other three in line with it.
05_functional_workflow_with_agents.pyand06_functional_workflow_basics.pycalledpoem_workflow.build()/text_workflow.build(). With the currently publishedagent_frameworkpackage, the
@workflowdecorator returns a ready-to-runFunctionalWorkflowdirectly, so
.build()raisesAttributeError.The README in the same folder didn't cover the Foundry data-plane RBAC needed to
call the project-scoped Responses endpoint, so users landed on a 401/403 with no
in-repo pointer.
Description & Review Guide
What are the major changes?
01_hello_agent.py,02_add_tools.py,03_multi_turn.py,04_memory.py:call
load_dotenv(), readFOUNDRY_PROJECT_ENDPOINTandFOUNDRY_MODELfrom the environment, and default the model to
gpt-4.1-miniinstead ofgpt-4o.05_functional_workflow_with_agents.py,06_functional_workflow_basics.py: drop the obsoleteworkflow_instance = <name>.build()step and call.run()directly on theFunctionalWorkflowreturned by the@workflowdecorator.README.md: adds a "Configure environment variables" section (endpointshape,
.envexample, and a note onpython-dotenv's upward search plusshell-env precedence) and a "Sign in and grant data-plane access" section
(Foundry project Responses requires
AIServices/responses/*; Azure AIDeveloper is not sufficient; role table with
Foundry Project Runtime User/
Foundry User/Cognitive Services User; anaz role assignment createexample; and 401/403/404 troubleshooting bullets).
What is the impact of these changes?
FOUNDRY_PROJECT_ENDPOINT(and optionally
FOUNDRY_MODEL) in a.env— no source edits required.AttributeError: 'FunctionalWorkflow' object has no attribute 'build'on the published package.python/samples/01-get-started/.What do you want reviewers to focus on?
gpt-4.1-miniis the right default model to advertise for thegetting-started flow.
(specifically the claim that Azure AI Developer alone is insufficient for
project-scoped Responses and that
AIServices/responses/*is required).FunctionalWorkflow.build()removal against thecurrent shape of
@workflowinpython/packages/core/agent_framework/_workflows/_functional.py.Related Issue
Fixes #
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.