Skip to content

Python: fix get-started samples env wiring and FunctionalWorkflow.build() removal - #7793

Closed
Linwen (linwendeng) wants to merge 1 commit into
microsoft:mainfrom
linwendeng:fix/get-started-samples
Closed

Python: fix get-started samples env wiring and FunctionalWorkflow.build() removal#7793
Linwen (linwendeng) wants to merge 1 commit into
microsoft:mainfrom
linwendeng:fix/get-started-samples

Conversation

@linwendeng

Copy link
Copy Markdown

Motivation & Context

The python/samples/01-get-started/ samples had two rough edges that blocked a
first-time user from running them out of the box:

  1. Samples 02_add_tools.py, 03_multi_turn.py, and 04_memory.py hard-coded
    project_endpoint="https://your-project.services.ai.azure.com" and
    model="gpt-4o", so they crashed until the reader edited the source. Sample
    01_hello_agent.py already read from FOUNDRY_PROJECT_ENDPOINT / FOUNDRY_MODEL
    — this PR brings the other three in line with it.
  2. Samples 05_functional_workflow_with_agents.py and
    06_functional_workflow_basics.py called poem_workflow.build() /
    text_workflow.build(). With the currently published agent_framework
    package, the @workflow decorator returns a ready-to-run FunctionalWorkflow
    directly, so .build() raises AttributeError.

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(), read FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL
      from the environment, and default the model to gpt-4.1-mini instead of
      gpt-4o.
    • 05_functional_workflow_with_agents.py,
      06_functional_workflow_basics.py: drop the obsolete
      workflow_instance = <name>.build() step and call .run() directly on the
      FunctionalWorkflow returned by the @workflow decorator.
    • README.md: adds a "Configure environment variables" section (endpoint
      shape, .env example, and a note on python-dotenv's upward search plus
      shell-env precedence) and a "Sign in and grant data-plane access" section
      (Foundry project Responses requires AIServices/responses/*; Azure AI
      Developer is not sufficient; role table with Foundry Project Runtime User
      / Foundry User / Cognitive Services User; an az role assignment create
      example; and 401/403/404 troubleshooting bullets).
  • What is the impact of these changes?

    • Samples run against a real Foundry project with just FOUNDRY_PROJECT_ENDPOINT
      (and optionally FOUNDRY_MODEL) in a .env — no source edits required.
    • Samples 05 and 06 no longer raise AttributeError: 'FunctionalWorkflow' object has no attribute 'build' on the published package.
    • No public API changes and no changes outside python/samples/01-get-started/.
  • What do you want reviewers to focus on?

    • Whether gpt-4.1-mini is the right default model to advertise for the
      getting-started flow.
    • Whether the RBAC guidance in the README matches the current Foundry story
      (specifically the claim that Azure AI Developer alone is insufficient for
      project-scoped Responses and that AIServices/responses/* is required).
    • Sanity check of the FunctionalWorkflow .build() removal against the
      current shape of @workflow in python/packages/core/agent_framework/_workflows/_functional.py.

Related Issue

Fixes #

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 balanced review requested due to automatic review settings August 20, 2026 17:05
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Aug 20, 2026

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

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.

Comment thread python/samples/01-get-started/README.md Outdated

```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 thread python/samples/01-get-started/README.md Outdated
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)`.
Comment thread python/samples/01-get-started/README.md Outdated
|------|--------|-------|
| `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 thread python/samples/01-get-started/README.md Outdated
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants