-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Python: fix: use workflow factory to avoid RuntimeError under parallel requests #5212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,72 @@ | ||||||||||||||||||
| # Copyright (c) Microsoft. All rights reserved. | ||||||||||||||||||
|
|
||||||||||||||||||
| import asyncio | ||||||||||||||||||
| import os | ||||||||||||||||||
| from contextlib import asynccontextmanager | ||||||||||||||||||
|
|
||||||||||||||||||
| from agent_framework import Agent, WorkflowBuilder | ||||||||||||||||||
| from agent_framework.foundry import FoundryChatClient | ||||||||||||||||||
| from azure.ai.agentserver.agentframework import from_agent_framework | ||||||||||||||||||
| from azure.identity.aio import AzureCliCredential, ManagedIdentityCredential | ||||||||||||||||||
| from dotenv import load_dotenv | ||||||||||||||||||
|
|
||||||||||||||||||
| load_dotenv(override=True) | ||||||||||||||||||
|
|
||||||||||||||||||
| # Configure these for your Foundry project | ||||||||||||||||||
| # Read the explicit variables present in the .env file | ||||||||||||||||||
| FOUNDRY_PROJECT_ENDPOINT = os.getenv( | ||||||||||||||||||
| "FOUNDRY_PROJECT_ENDPOINT" | ||||||||||||||||||
| ) # e.g., "https://<project>.services.ai.azure.com/api/projects/<project-name>" | ||||||||||||||||||
|
||||||||||||||||||
| ) # e.g., "https://<project>.services.ai.azure.com/api/projects/<project-name>" | |
| ) # e.g., "https://<project>.services.ai.azure.com/api/projects/<project-name>" | |
| if not FOUNDRY_PROJECT_ENDPOINT: | |
| raise RuntimeError( | |
| "FOUNDRY_PROJECT_ENDPOINT environment variable is required. " | |
| 'Set it to your Foundry project endpoint, for example: ' | |
| '"https://<project>.services.ai.azure.com/api/projects/<project-name>".' | |
| ) |
Copilot
AI
Apr 10, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
create_workflow() wraps a Workflow inside Agent(client=workflow), but Workflow is not a chat client and doesn't implement the get_response API expected by Agent. Use workflow.as_agent(...) (returns WorkflowAgent) to expose a workflow as an agent for from_agent_framework(...).
| return Agent( | |
| client=workflow, | |
| ) | |
| return workflow.as_agent(name="WriterReviewerWorkflow") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agent_framework.foundry/FoundryChatClientdoesn't exist in this repo's Python packages (there is noagent_framework/foundrymodule), so this sample will fail at import time. Please switch to a supported client (e.g.,agent_framework.azure.AzureOpenAIResponsesClientusingproject_endpoint=...for Foundry, or another existing chat client) and update the env var names accordingly.