From 016daf3b982a3d5c6893791c9becc09b3809042f Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Tue, 31 Mar 2026 08:20:35 -0700 Subject: [PATCH] Python: Fix samples (#4980) * First samples 1st batch * Fix sample paths * Fix workflow samples * Fix workflow dependency * Correct env vars * Increase idle timeout * Fix workflows HIL sample * Fix more workflow samples --- .../sample-validation-setup/action.yml | 2 +- .../workflows/python-sample-validation.yml | 123 +++++------------- python/samples/01-get-started/README.md | 7 - .../compaction/compaction_provider.py | 2 +- .../redis/redis_conversation.py | 4 +- python/samples/02-agents/typed_options.py | 12 +- python/samples/03-workflows/README.md | 4 +- .../_start-here/step2_agents_in_a_workflow.py | 4 +- .../_start-here/step3_streaming.py | 4 +- .../agents/azure_ai_agents_streaming.py | 4 +- .../azure_ai_agents_with_shared_session.py | 4 +- .../agents/azure_chat_agents_and_executor.py | 6 +- .../agents/azure_chat_agents_streaming.py | 6 +- ...re_chat_agents_tool_calls_with_feedback.py | 16 +-- .../agents/concurrent_workflow_as_agent.py | 6 +- .../agents/custom_agent_executors.py | 6 +- .../agents/group_chat_workflow_as_agent.py | 8 +- .../agents/handoff_workflow_as_agent.py | 35 +++-- .../agents/magentic_workflow_as_agent.py | 10 +- .../agents/sequential_workflow_as_agent.py | 6 +- .../workflow_as_agent_human_in_the_loop.py | 12 +- .../agents/workflow_as_agent_kwargs.py | 6 +- .../workflow_as_agent_reflection_pattern.py | 11 +- .../agents/workflow_as_agent_with_session.py | 10 +- .../checkpoint_with_human_in_the_loop.py | 2 +- .../workflow_as_agent_checkpoint.py | 14 +- .../composition/sub_workflow_kwargs.py | 4 +- .../control-flow/edge_condition.py | 4 +- .../multi_selection_edge_group.py | 6 +- .../03-workflows/control-flow/simple_loop.py | 4 +- .../control-flow/switch_case_edge_group.py | 4 +- .../agent_to_function_tool/main.py | 2 +- .../declarative/customer_support/main.py | 2 +- .../declarative/deep_research/main.py | 7 +- .../declarative/function_tools/main.py | 2 +- .../declarative/marketing/main.py | 2 +- .../declarative/student_teacher/main.py | 8 +- .../human-in-the-loop/agents_with_HITL.py | 16 +-- .../agents_with_approval_requests.py | 4 +- .../agents_with_declaration_only_tools.py | 2 +- .../concurrent_request_info.py | 4 +- .../group_chat_request_info.py | 4 +- .../guessing_game_with_human_input.py | 4 +- .../sequential_request_info.py | 4 +- .../orchestrations/concurrent_agents.py | 4 +- .../concurrent_custom_agent_executors.py | 4 +- .../concurrent_custom_aggregator.py | 4 +- .../group_chat_agent_manager.py | 4 +- .../group_chat_philosophical_debate.py | 4 +- .../group_chat_simple_selector.py | 4 +- .../orchestrations/handoff_autonomous.py | 2 +- .../orchestrations/handoff_simple.py | 4 +- .../handoff_with_code_interpreter_file.py | 4 +- ...ff_with_tool_approval_checkpoint_resume.py | 4 +- .../03-workflows/orchestrations/magentic.py | 4 +- .../orchestrations/magentic_checkpoint.py | 8 +- .../magentic_human_plan_review.py | 4 +- .../orchestrations/sequential_agents.py | 4 +- .../sequential_chain_only_agent_responses.py | 23 ++-- .../sequential_custom_executors.py | 4 +- .../parallelism/fan_out_fan_in_edges.py | 8 +- .../state-management/state_with_agents.py | 6 +- .../state-management/workflow_kwargs.py | 4 +- .../concurrent_builder_tool_approval.py | 4 +- .../group_chat_builder_tool_approval.py | 4 +- .../sequential_builder_tool_approval.py | 4 +- .../concurrent_with_visualization.py | 8 +- python/samples/README.md | 8 +- .../create_dynamic_workflow_executor.py | 2 +- 69 files changed, 234 insertions(+), 306 deletions(-) diff --git a/.github/actions/sample-validation-setup/action.yml b/.github/actions/sample-validation-setup/action.yml index 2920aaa5bd..14c92694ff 100644 --- a/.github/actions/sample-validation-setup/action.yml +++ b/.github/actions/sample-validation-setup/action.yml @@ -34,7 +34,7 @@ runs: - name: Test Copilot CLI shell: bash - run: copilot -p "What can you do in one sentence?" + run: copilot --version && copilot -p "What can you do in one sentence?" - name: Azure CLI Login uses: azure/login@v2 diff --git a/.github/workflows/python-sample-validation.yml b/.github/workflows/python-sample-validation.yml index 63f95a78c3..7ce2219573 100644 --- a/.github/workflows/python-sample-validation.yml +++ b/.github/workflows/python-sample-validation.yml @@ -67,11 +67,13 @@ jobs: # Azure AI configuration AZURE_AI_PROJECT_ENDPOINT: ${{ vars.AZURE_AI_PROJECT_ENDPOINT }} AZURE_AI_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }} + FOUNDRY_PROJECT_ENDPOINT: ${{ vars.FOUNDRY_PROJECT_ENDPOINT }} + FOUNDRY_MODEL: ${{ vars.FOUNDRY_MODEL }} # Azure OpenAI configuration AZURE_OPENAI_ENDPOINT: ${{ vars.AZUREOPENAI__ENDPOINT }} AZURE_OPENAI_CHAT_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__CHATDEPLOYMENTNAME }} AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }} - AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__EMBEDDINGDEPLOYMENTNAME }} + AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME }} # OpenAI configuration OPENAI_API_KEY: ${{ secrets.OPENAI__APIKEY }} OPENAI_CHAT_MODEL_ID: ${{ vars.OPENAI__CHATMODELID }} @@ -97,6 +99,8 @@ jobs: - name: Create .env for samples run: | + echo "FOUNDRY_PROJECT_ENDPOINT=$FOUNDRY_PROJECT_ENDPOINT" >> .env + echo "FOUNDRY_MODEL=$FOUNDRY_MODEL" >> .env echo "AZURE_AI_PROJECT_ENDPOINT=$AZURE_AI_PROJECT_ENDPOINT" >> .env echo "AZURE_AI_MODEL_DEPLOYMENT_NAME=$AZURE_AI_MODEL_DEPLOYMENT_NAME" >> .env echo "AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT" >> .env @@ -125,6 +129,7 @@ jobs: environment: integration env: OPENAI_API_KEY: ${{ secrets.OPENAI__APIKEY }} + OPENAI_MODEL: ${{ vars.OPENAI__CHATMODELID }} OPENAI_CHAT_MODEL_ID: ${{ vars.OPENAI__CHATMODELID }} OPENAI_RESPONSES_MODEL_ID: ${{ vars.OPENAI__RESPONSESMODELID }} defaults: @@ -144,6 +149,7 @@ jobs: - name: Create .env for samples run: | echo "OPENAI_API_KEY=$OPENAI_API_KEY" >> .env + echo "OPENAI_MODEL=$OPENAI_MODEL" >> .env echo "OPENAI_CHAT_MODEL_ID=$OPENAI_CHAT_MODEL_ID" >> .env echo "OPENAI_RESPONSES_MODEL_ID=$OPENAI_RESPONSES_MODEL_ID" >> .env @@ -158,8 +164,8 @@ jobs: name: validation-report-02-agents-openai path: python/samples/sample_validation/reports/ - validate-02-agents-azure-openai: - name: Validate 02-agents/providers/azure_openai + validate-02-agents-azure: + name: Validate 02-agents/providers/azure runs-on: ubuntu-latest environment: integration env: @@ -190,93 +196,13 @@ jobs: - name: Run sample validation run: | - cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/azure_openai --save-report --report-name 02-agents-azure-openai + cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/azure --save-report --report-name 02-agents-azure - name: Upload validation report uses: actions/upload-artifact@v7 if: always() with: - name: validation-report-02-agents-azure-openai - path: python/samples/sample_validation/reports/ - - validate-02-agents-azure-ai: - name: Validate 02-agents/providers/azure_ai - runs-on: ubuntu-latest - environment: integration - env: - AZURE_AI_PROJECT_ENDPOINT: ${{ vars.AZURE_AI_PROJECT_ENDPOINT }} - AZURE_AI_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }} - AZURE_AI_CHAT_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__CHATDEPLOYMENTNAME }} - AZURE_AI_EMBEDDING_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__EMBEDDINGDEPLOYMENTNAME }} - BING_CONNECTION_ID: ${{ secrets.BING_CONNECTION_ID }} - defaults: - run: - working-directory: python - steps: - - uses: actions/checkout@v6 - - - name: Setup environment - uses: ./.github/actions/sample-validation-setup - with: - azure-client-id: ${{ secrets.AZURE_CLIENT_ID }} - azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} - azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - os: ${{ runner.os }} - - - name: Create .env for samples - run: | - echo "AZURE_AI_PROJECT_ENDPOINT=$AZURE_AI_PROJECT_ENDPOINT" >> .env - echo "AZURE_AI_MODEL_DEPLOYMENT_NAME=$AZURE_AI_MODEL_DEPLOYMENT_NAME" >> .env - echo "AZURE_AI_CHAT_MODEL_DEPLOYMENT_NAME=$AZURE_AI_CHAT_MODEL_DEPLOYMENT_NAME" >> .env - echo "AZURE_AI_EMBEDDING_MODEL_DEPLOYMENT_NAME=$AZURE_AI_EMBEDDING_MODEL_DEPLOYMENT_NAME" >> .env - echo "BING_CONNECTION_ID=$BING_CONNECTION_ID" >> .env - - - name: Run sample validation - run: | - cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/azure_ai --save-report --report-name 02-agents-azure-ai - - - name: Upload validation report - uses: actions/upload-artifact@v7 - if: always() - with: - name: validation-report-02-agents-azure-ai - path: python/samples/sample_validation/reports/ - - validate-02-agents-azure-ai-agent: - name: Validate 02-agents/providers/azure_ai_agent - runs-on: ubuntu-latest - environment: integration - env: - AZURE_AI_PROJECT_ENDPOINT: ${{ vars.AZURE_AI_PROJECT_ENDPOINT }} - AZURE_AI_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }} - defaults: - run: - working-directory: python - steps: - - uses: actions/checkout@v6 - - - name: Setup environment - uses: ./.github/actions/sample-validation-setup - with: - azure-client-id: ${{ secrets.AZURE_CLIENT_ID }} - azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }} - azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} - os: ${{ runner.os }} - - - name: Create .env for samples - run: | - echo "AZURE_AI_PROJECT_ENDPOINT=$AZURE_AI_PROJECT_ENDPOINT" >> .env - echo "AZURE_AI_MODEL_DEPLOYMENT_NAME=$AZURE_AI_MODEL_DEPLOYMENT_NAME" >> .env - - - name: Run sample validation - run: | - cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/azure_ai_agent --save-report --report-name 02-agents-azure-ai-agent - - - name: Upload validation report - uses: actions/upload-artifact@v7 - if: always() - with: - name: validation-report-02-agents-azure-ai-agent + name: validation-report-02-agents-azure path: python/samples/sample_validation/reports/ validate-02-agents-anthropic: @@ -409,11 +335,13 @@ jobs: name: validation-report-02-agents-ollama path: python/samples/sample_validation/reports/ - validate-02-agents-foundry-local: - name: Validate 02-agents/providers/foundry_local - if: false # Temporarily disabled - requires local Foundry setup + validate-02-agents-foundry: + name: Validate 02-agents/providers/foundry runs-on: ubuntu-latest environment: integration + env: + FOUNDRY_PROJECT_ENDPOINT: ${{ vars.FOUNDRY_PROJECT_ENDPOINT }} + FOUNDRY_MODEL: ${{ vars.FOUNDRY_MODEL }} defaults: run: working-directory: python @@ -428,15 +356,20 @@ jobs: azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }} os: ${{ runner.os }} + - name: Create .env for samples + run: | + echo "FOUNDRY_PROJECT_ENDPOINT=$FOUNDRY_PROJECT_ENDPOINT" >> .env + echo "FOUNDRY_MODEL=$FOUNDRY_MODEL" >> .env + - name: Run sample validation run: | - cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/foundry_local --save-report --report-name 02-agents-foundry-local + cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/foundry --save-report --report-name 02-agents-foundry - name: Upload validation report uses: actions/upload-artifact@v7 if: always() with: - name: validation-report-02-agents-foundry-local + name: validation-report-02-agents-foundry path: python/samples/sample_validation/reports/ validate-02-agents-copilotstudio: @@ -516,6 +449,8 @@ jobs: environment: integration env: # Azure AI configuration + FOUNDRY_PROJECT_ENDPOINT: ${{ vars.FOUNDRY_PROJECT_ENDPOINT }} + FOUNDRY_MODEL: ${{ vars.FOUNDRY_MODEL }} AZURE_AI_PROJECT_ENDPOINT: ${{ vars.AZURE_AI_PROJECT_ENDPOINT }} AZURE_AI_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }} # Azure OpenAI configuration @@ -538,6 +473,8 @@ jobs: - name: Create .env for samples run: | + echo "FOUNDRY_PROJECT_ENDPOINT=$FOUNDRY_PROJECT_ENDPOINT" >> .env + echo "FOUNDRY_MODEL=$FOUNDRY_MODEL" >> .env echo "AZURE_AI_PROJECT_ENDPOINT=$AZURE_AI_PROJECT_ENDPOINT" >> .env echo "AZURE_AI_MODEL_DEPLOYMENT_NAME=$AZURE_AI_MODEL_DEPLOYMENT_NAME" >> .env echo "AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT" >> .env @@ -759,14 +696,12 @@ jobs: - validate-01-get-started - validate-02-agents - validate-02-agents-openai - - validate-02-agents-azure-openai - - validate-02-agents-azure-ai - - validate-02-agents-azure-ai-agent + - validate-02-agents-azure - validate-02-agents-anthropic - validate-02-agents-github-copilot - validate-02-agents-amazon - validate-02-agents-ollama - - validate-02-agents-foundry-local + - validate-02-agents-foundry - validate-02-agents-copilotstudio - validate-02-agents-custom - validate-03-workflows diff --git a/python/samples/01-get-started/README.md b/python/samples/01-get-started/README.md index e1bae20b32..7d696ba528 100644 --- a/python/samples/01-get-started/README.md +++ b/python/samples/01-get-started/README.md @@ -9,13 +9,6 @@ concepts of **Agent Framework** one step at a time. pip install agent-framework --pre ``` -Set the required environment variables: - -```bash -export AZURE_AI_PROJECT_ENDPOINT="https://your-project-endpoint" -export AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="gpt-4o" # optional, defaults to gpt-4o -``` - ## Samples | # | File | What you'll learn | diff --git a/python/samples/02-agents/compaction/compaction_provider.py b/python/samples/02-agents/compaction/compaction_provider.py index d91fa42d7c..23483017c2 100644 --- a/python/samples/02-agents/compaction/compaction_provider.py +++ b/python/samples/02-agents/compaction/compaction_provider.py @@ -70,7 +70,7 @@ async def log_model_input(context: ChatContext, call_next: Any) -> None: async def main() -> None: - client = OpenAIChatClient(model_id="gpt-4o-mini") + client = OpenAIChatClient(model="gpt-4o-mini") # History provider loads/stores conversation messages in session.state. # skip_excluded=True means get_messages() will omit messages that were diff --git a/python/samples/02-agents/context_providers/redis/redis_conversation.py b/python/samples/02-agents/context_providers/redis/redis_conversation.py index ad95b141a1..d3abf86394 100644 --- a/python/samples/02-agents/context_providers/redis/redis_conversation.py +++ b/python/samples/02-agents/context_providers/redis/redis_conversation.py @@ -25,11 +25,11 @@ from agent_framework import Agent from agent_framework.foundry import FoundryChatClient from agent_framework.redis import RedisContextProvider from azure.identity import AzureCliCredential +from dotenv import load_dotenv from redisvl.extensions.cache.embeddings import EmbeddingsCache from redisvl.utils.vectorize import OpenAITextVectorizer -# Copyright (c) Microsoft. All rights reserved. - +load_dotenv() # Default Redis URL for local Redis Stack. # Override via the REDIS_URL environment variable for remote or authenticated instances. diff --git a/python/samples/02-agents/typed_options.py b/python/samples/02-agents/typed_options.py index f33cc21186..9f2862a65a 100644 --- a/python/samples/02-agents/typed_options.py +++ b/python/samples/02-agents/typed_options.py @@ -3,7 +3,7 @@ import asyncio from typing import Literal -from agent_framework import Agent +from agent_framework import Agent, Message from agent_framework.anthropic import AnthropicClient from agent_framework.foundry import FoundryChatClient from agent_framework.openai import OpenAIChatClient, OpenAIChatOptions @@ -40,11 +40,11 @@ async def demo_anthropic_chat_client() -> None: print("\n=== Anthropic ChatClient with TypedDict Options ===\n") # Create Anthropic client - client = AnthropicClient(model="claude-sonnet-4-5-20250929") + client = AnthropicClient(model_id="claude-sonnet-4-5-20250929") # Standard options work great: response = await client.get_response( - "What is the capital of France?", + [Message("user", text="What is the capital of France?")], options={ "temperature": 0.5, "max_tokens": 1000, @@ -62,7 +62,7 @@ async def demo_anthropic_agent() -> None: """Demonstrate Agent with Anthropic client and typed options.""" print("\n=== Agent with Anthropic and Typed Options ===\n") - client = AnthropicClient(model="claude-sonnet-4-5-20250929") + client = AnthropicClient(model_id="claude-sonnet-4-5-20250929") # Create a typed agent for Anthropic - IDE knows Anthropic-specific options! agent = Agent( @@ -119,12 +119,12 @@ async def demo_openai_chat_client_reasoning_models() -> None: print("\n=== OpenAI ChatClient with TypedDict Options ===\n") # Create OpenAI client - client = OpenAIChatClient[OpenAIReasoningChatOptions](model_id="o3") + client = OpenAIChatClient[OpenAIReasoningChatOptions](model="o3") # With specific options, you get full IDE autocomplete! # Try typing `client.get_response("Hello", options={` and see the suggestions response = await client.get_response( - "What is 2 + 2?", + [Message("user", text="What is 2 + 2?")], options={ "max_tokens": 100, "allow_multiple_tool_calls": True, diff --git a/python/samples/03-workflows/README.md b/python/samples/03-workflows/README.md index 4dfdd68157..0e5dbaa9c0 100644 --- a/python/samples/03-workflows/README.md +++ b/python/samples/03-workflows/README.md @@ -172,7 +172,7 @@ Workflow and orchestration samples use `AzureOpenAIResponsesClient` rather than Workflow samples that use `AzureOpenAIResponsesClient` expect: -- `AZURE_AI_PROJECT_ENDPOINT` (Azure AI Foundry Agent Service (V2) project endpoint) -- `AZURE_AI_MODEL_DEPLOYMENT_NAME` (model deployment name) +- `FOUNDRY_PROJECT_ENDPOINT` (Azure AI Foundry Agent Service (V2) project endpoint) +- `FOUNDRY_MODEL` (model deployment name) These values are passed directly into the client constructor via `os.getenv()` in sample code. diff --git a/python/samples/03-workflows/_start-here/step2_agents_in_a_workflow.py b/python/samples/03-workflows/_start-here/step2_agents_in_a_workflow.py index 326bd717ed..51a138429f 100644 --- a/python/samples/03-workflows/_start-here/step2_agents_in_a_workflow.py +++ b/python/samples/03-workflows/_start-here/step2_agents_in_a_workflow.py @@ -24,7 +24,7 @@ how agents can be used in a workflow. Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be the deployment name of a model in your Foundry project. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Basic familiarity with WorkflowBuilder, edges, events, and streaming or non-streaming runs. """ @@ -35,7 +35,7 @@ async def main(): # Create the Azure chat client. AzureCliCredential uses your current az login. client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) writer_agent = Agent( diff --git a/python/samples/03-workflows/_start-here/step3_streaming.py b/python/samples/03-workflows/_start-here/step3_streaming.py index 7d66e1f137..d2c29b56fc 100644 --- a/python/samples/03-workflows/_start-here/step3_streaming.py +++ b/python/samples/03-workflows/_start-here/step3_streaming.py @@ -23,7 +23,7 @@ how agents can be used in a workflow. Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be the deployment name of a model in your Foundry project. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Basic familiarity with WorkflowBuilder, executors, edges, events, and streaming runs. """ @@ -34,7 +34,7 @@ async def main(): # Create the Azure chat client. AzureCliCredential uses your current az login. client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) writer_agent = Agent( diff --git a/python/samples/03-workflows/agents/azure_ai_agents_streaming.py b/python/samples/03-workflows/agents/azure_ai_agents_streaming.py index e54dd1b8f4..9777e26f5a 100644 --- a/python/samples/03-workflows/agents/azure_ai_agents_streaming.py +++ b/python/samples/03-workflows/agents/azure_ai_agents_streaming.py @@ -18,7 +18,7 @@ This sample shows how to create agents backed by Azure OpenAI Responses and use Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- AZURE_AI_MODEL_DEPLOYMENT_NAME must be set to your Azure OpenAI model deployment name. +- FOUNDRY_MODEL must be the deployment name of a model in your Foundry project. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Basic familiarity with WorkflowBuilder, edges, events, and streaming runs. """ @@ -27,7 +27,7 @@ Prerequisites: async def main() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/agents/azure_ai_agents_with_shared_session.py b/python/samples/03-workflows/agents/azure_ai_agents_with_shared_session.py index bc4167d466..3600c8ce33 100644 --- a/python/samples/03-workflows/agents/azure_ai_agents_with_shared_session.py +++ b/python/samples/03-workflows/agents/azure_ai_agents_with_shared_session.py @@ -39,7 +39,7 @@ Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- AZURE_AI_MODEL_DEPLOYMENT_NAME must be set to your Azure OpenAI model deployment name. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Basic familiarity with agents, workflows, and executors in the agent framework. """ @@ -60,7 +60,7 @@ async def intercept_agent_response( async def main() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/agents/azure_chat_agents_and_executor.py b/python/samples/03-workflows/agents/azure_chat_agents_and_executor.py index 9655781522..d658abe3b1 100644 --- a/python/samples/03-workflows/agents/azure_chat_agents_and_executor.py +++ b/python/samples/03-workflows/agents/azure_chat_agents_and_executor.py @@ -37,7 +37,7 @@ Demonstrates: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Run `az login` before executing. """ @@ -104,7 +104,7 @@ async def main() -> None: research_agent = Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), name="research_agent", @@ -116,7 +116,7 @@ async def main() -> None: final_editor_agent = Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), name="final_editor_agent", diff --git a/python/samples/03-workflows/agents/azure_chat_agents_streaming.py b/python/samples/03-workflows/agents/azure_chat_agents_streaming.py index a7fe68f27f..39a7777663 100644 --- a/python/samples/03-workflows/agents/azure_chat_agents_streaming.py +++ b/python/samples/03-workflows/agents/azure_chat_agents_streaming.py @@ -18,7 +18,7 @@ This sample shows how to create AzureOpenAI Chat Agents and use them in a workfl Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Basic familiarity with WorkflowBuilder, edges, events, and streaming runs. """ @@ -29,7 +29,7 @@ async def main(): # Create the agents _writer_client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) writer_agent = Agent( @@ -42,7 +42,7 @@ async def main(): _reviewer_client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) reviewer_agent = Agent( diff --git a/python/samples/03-workflows/agents/azure_chat_agents_tool_calls_with_feedback.py b/python/samples/03-workflows/agents/azure_chat_agents_tool_calls_with_feedback.py index 5c1d3027b0..1034039a34 100644 --- a/python/samples/03-workflows/agents/azure_chat_agents_tool_calls_with_feedback.py +++ b/python/samples/03-workflows/agents/azure_chat_agents_tool_calls_with_feedback.py @@ -49,7 +49,7 @@ Demonstrates: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Run `az login` before executing. """ @@ -122,11 +122,7 @@ class Coordinator(Executor): # Writer agent response; request human feedback. # Preserve the full conversation so the final editor # can see tool traces and the initial prompt. - conversation: list[Message] - if draft.full_conversation is not None: - conversation = list(draft.full_conversation) - else: - conversation = list(draft.agent_response.messages) + conversation = list(draft.full_conversation) draft_text = draft.agent_response.text.strip() if not draft_text: draft_text = "No draft text was produced." @@ -178,7 +174,7 @@ def create_writer_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), name="writer_agent", @@ -188,7 +184,9 @@ def create_writer_agent() -> Agent: "produce a 3-sentence draft." ), tools=[fetch_product_brief, get_brand_voice_profile], - tool_choice="required", + default_options={ + "tool_choice": "required", + }, ) @@ -197,7 +195,7 @@ def create_final_editor_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), name="final_editor_agent", diff --git a/python/samples/03-workflows/agents/concurrent_workflow_as_agent.py b/python/samples/03-workflows/agents/concurrent_workflow_as_agent.py index acee104c86..42538e31a4 100644 --- a/python/samples/03-workflows/agents/concurrent_workflow_as_agent.py +++ b/python/samples/03-workflows/agents/concurrent_workflow_as_agent.py @@ -25,7 +25,7 @@ Demonstrates: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI access configured for FoundryChatClient (use az login + env vars) +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Familiarity with Workflow events (WorkflowEvent with type "output") """ @@ -34,7 +34,7 @@ async def main() -> None: # 1) Create three domain agents using FoundryChatClient client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -69,7 +69,7 @@ async def main() -> None: workflow = ConcurrentBuilder(participants=[researcher, marketer, legal]).build() # 3) Expose the concurrent workflow as an agent for easy reuse - agent = Agent(client=workflow, name="ConcurrentWorkflowAgent") + agent = workflow.as_agent() prompt = "We are launching a new budget-friendly electric bike for urban commuters." agent_response = await agent.run(prompt) diff --git a/python/samples/03-workflows/agents/custom_agent_executors.py b/python/samples/03-workflows/agents/custom_agent_executors.py index 95d1d8dca8..af12db1cf5 100644 --- a/python/samples/03-workflows/agents/custom_agent_executors.py +++ b/python/samples/03-workflows/agents/custom_agent_executors.py @@ -33,7 +33,7 @@ Note: When an agent is passed to a workflow, the workflow wraps the agent in a m Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Basic familiarity with WorkflowBuilder, executors, edges, events, and streaming or non streaming runs. """ @@ -54,7 +54,7 @@ class Writer(Executor): self.agent = Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( @@ -101,7 +101,7 @@ class Reviewer(Executor): self.agent = Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( diff --git a/python/samples/03-workflows/agents/group_chat_workflow_as_agent.py b/python/samples/03-workflows/agents/group_chat_workflow_as_agent.py index 3c03a2fb57..b503f7574f 100644 --- a/python/samples/03-workflows/agents/group_chat_workflow_as_agent.py +++ b/python/samples/03-workflows/agents/group_chat_workflow_as_agent.py @@ -32,7 +32,7 @@ async def main() -> None: instructions="Gather concise facts that help a teammate answer the question.", client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) @@ -43,14 +43,14 @@ async def main() -> None: instructions="Compose clear and structured answers using any notes provided.", client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) _orch_client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -72,7 +72,7 @@ async def main() -> None: print(f"Input: {task}\n") try: - workflow_agent = Agent(client=workflow, name="GroupChatWorkflowAgent") + workflow_agent = workflow.as_agent() agent_result = await workflow_agent.run(task) if agent_result.messages: diff --git a/python/samples/03-workflows/agents/handoff_workflow_as_agent.py b/python/samples/03-workflows/agents/handoff_workflow_as_agent.py index 6c56d3d66b..c7d06b535a 100644 --- a/python/samples/03-workflows/agents/handoff_workflow_as_agent.py +++ b/python/samples/03-workflows/agents/handoff_workflow_as_agent.py @@ -31,7 +31,7 @@ them to transfer control to each other based on the conversation context. Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. - `az login` (Azure CLI authentication) - - Environment variables configured for FoundryChatClient (AZURE_AI_MODEL_DEPLOYMENT_NAME) + - Environment variables configured for FoundryChatClient (FOUNDRY_MODEL) Key Concepts: - Auto-registered handoff tools: HandoffBuilder automatically creates handoff tools @@ -159,7 +159,7 @@ async def main() -> None: # Initialize the Azure OpenAI chat client client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -174,21 +174,20 @@ async def main() -> None: # Without this, the default behavior continues requesting user input until max_turns # is reached. Here we use a custom condition that checks if the conversation has ended # naturally (when one of the agents says something like "you're welcome"). - agent = Agent( - client=( - HandoffBuilder( - name="customer_support_handoff", - participants=[triage, refund, order, support], - # Custom termination: Check if one of the agents has provided a closing message. - # This looks for the last message containing "welcome", which indicates the - # conversation has concluded naturally. - termination_condition=lambda conversation: ( - len(conversation) > 0 and "welcome" in conversation[-1].text.lower() - ), - ) - .with_start_agent(triage) - .build() - ), + agent = ( + HandoffBuilder( + name="customer_support_handoff", + participants=[triage, refund, order, support], + # Custom termination: Check if one of the agents has provided a closing message. + # This looks for the last message containing "welcome", which indicates the + # conversation has concluded naturally. + termination_condition=lambda conversation: ( + len(conversation) > 0 and "welcome" in conversation[-1].text.lower() + ), + ) + .with_start_agent(triage) + .build() + .as_agent() ) # Scripted user responses for reproducible demo @@ -226,7 +225,7 @@ async def main() -> None: responses = {req_id: HandoffAgentUserRequest.create_response(user_response) for req_id in pending_requests} function_results = [ - Content.from_function_result(call_id=req_id, result=response) for req_id, response in responses.items() + Content("function_result", call_id=req_id, result=response) for req_id, response in responses.items() ] response = await agent.run(Message("tool", function_results)) pending_requests = handle_response_and_requests(response) diff --git a/python/samples/03-workflows/agents/magentic_workflow_as_agent.py b/python/samples/03-workflows/agents/magentic_workflow_as_agent.py index 7ce8c496df..6cc91a9dcd 100644 --- a/python/samples/03-workflows/agents/magentic_workflow_as_agent.py +++ b/python/samples/03-workflows/agents/magentic_workflow_as_agent.py @@ -23,7 +23,7 @@ like any other agent while still emitting callback telemetry. Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- OpenAI credentials configured for `FoundryChatClient` and `FoundryChatClient`. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. """ @@ -37,7 +37,7 @@ async def main() -> None: # This agent requires the gpt-4o-search-preview model to perform web searches. client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) @@ -45,7 +45,7 @@ async def main() -> None: # Create code interpreter tool using instance method coder_client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) code_interpreter_tool = coder_client.get_code_interpreter_tool() @@ -65,7 +65,7 @@ async def main() -> None: instructions="You coordinate a team to complete complex tasks efficiently.", client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) @@ -98,7 +98,7 @@ async def main() -> None: try: # Wrap the workflow as an agent for composition scenarios print("\nWrapping workflow as an agent and running...") - workflow_agent = Agent(client=workflow, name="MagenticWorkflowAgent") + workflow_agent = workflow.as_agent() last_response_id: str | None = None async for update in workflow_agent.run(task, stream=True): diff --git a/python/samples/03-workflows/agents/sequential_workflow_as_agent.py b/python/samples/03-workflows/agents/sequential_workflow_as_agent.py index dcc4d9fad9..52de975173 100644 --- a/python/samples/03-workflows/agents/sequential_workflow_as_agent.py +++ b/python/samples/03-workflows/agents/sequential_workflow_as_agent.py @@ -27,7 +27,7 @@ Note on internal adapters: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI access configured for FoundryChatClient (use az login + env vars) +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. """ @@ -35,7 +35,7 @@ async def main() -> None: # 1) Create agents client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -55,7 +55,7 @@ async def main() -> None: workflow = SequentialBuilder(participants=[writer, reviewer]).build() # 3) Treat the workflow itself as an agent for follow-up invocations - agent = Agent(client=workflow, name="SequentialWorkflowAgent") + agent = workflow.as_agent() prompt = "Write a tagline for a budget-friendly eBike." agent_response = await agent.run(prompt) diff --git a/python/samples/03-workflows/agents/workflow_as_agent_human_in_the_loop.py b/python/samples/03-workflows/agents/workflow_as_agent_human_in_the_loop.py index d5a5e1f4e2..3b8ccc0faa 100644 --- a/python/samples/03-workflows/agents/workflow_as_agent_human_in_the_loop.py +++ b/python/samples/03-workflows/agents/workflow_as_agent_human_in_the_loop.py @@ -8,7 +8,6 @@ from dataclasses import dataclass from pathlib import Path from typing import Any -from agent_framework import Agent from agent_framework.foundry import FoundryChatClient from azure.identity import AzureCliCredential from dotenv import load_dotenv @@ -50,7 +49,7 @@ to the Worker. The workflow completes when idle. Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- OpenAI account configured and accessible for FoundryChatClient. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Familiarity with WorkflowBuilder, Executor, and WorkflowContext from agent_framework. - Understanding of request-response message handling in executors. - (Optional) Review of reflection and escalation patterns, such as those in @@ -113,14 +112,14 @@ async def main() -> None: id="worker", client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) reviewer = ReviewerWithHumanInTheLoop(worker_id="worker") - agent = Agent( - client=(WorkflowBuilder(start_executor=worker).add_edge(worker, reviewer).add_edge(reviewer, worker).build()), + agent = ( + WorkflowBuilder(start_executor=worker).add_edge(worker, reviewer).add_edge(reviewer, worker).build().as_agent() ) print("Running workflow agent with user query...") @@ -165,7 +164,8 @@ async def main() -> None: human_response = ReviewResponse(request_id=request_id, feedback="", approved=True) # Create the function call result object to send back to the agent. - human_review_function_result = Content.from_function_result( + human_review_function_result = Content( + "function_result", call_id=human_review_function_call.call_id, # type: ignore result=human_response, ) diff --git a/python/samples/03-workflows/agents/workflow_as_agent_kwargs.py b/python/samples/03-workflows/agents/workflow_as_agent_kwargs.py index 1b8a875773..7c30106cc8 100644 --- a/python/samples/03-workflows/agents/workflow_as_agent_kwargs.py +++ b/python/samples/03-workflows/agents/workflow_as_agent_kwargs.py @@ -35,7 +35,7 @@ When to use Agent(client=workflow,): Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Environment variables configured +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. """ @@ -89,7 +89,7 @@ async def main() -> None: # Create chat client client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -109,7 +109,7 @@ async def main() -> None: workflow = SequentialBuilder(participants=[agent]).build() # Expose the workflow as an agent Agent(client=using,) - workflow_agent = Agent(client=workflow, name="WorkflowAgent") + workflow_agent = workflow.as_agent() # Define custom context that will flow to tools via kwargs custom_data = { diff --git a/python/samples/03-workflows/agents/workflow_as_agent_reflection_pattern.py b/python/samples/03-workflows/agents/workflow_as_agent_reflection_pattern.py index 2d37778b84..d2d02c9581 100644 --- a/python/samples/03-workflows/agents/workflow_as_agent_reflection_pattern.py +++ b/python/samples/03-workflows/agents/workflow_as_agent_reflection_pattern.py @@ -6,7 +6,6 @@ from dataclasses import dataclass from uuid import uuid4 from agent_framework import ( - Agent, AgentResponse, Executor, Message, @@ -41,7 +40,7 @@ Key Concepts Demonstrated: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- OpenAI account configured and accessible for FoundryChatClient. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Familiarity with WorkflowBuilder, Executor, WorkflowContext, and event handling. - Understanding of how agent messages are generated, reviewed, and re-submitted. """ @@ -198,7 +197,7 @@ async def main() -> None: id="worker", client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) @@ -206,13 +205,13 @@ async def main() -> None: id="reviewer", client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) - agent = Agent( - client=(WorkflowBuilder(start_executor=worker).add_edge(worker, reviewer).add_edge(reviewer, worker).build()), + agent = ( + WorkflowBuilder(start_executor=worker).add_edge(worker, reviewer).add_edge(reviewer, worker).build().as_agent() ) print("Running workflow agent with user query...") diff --git a/python/samples/03-workflows/agents/workflow_as_agent_with_session.py b/python/samples/03-workflows/agents/workflow_as_agent_with_session.py index 469568f000..7d65b36492 100644 --- a/python/samples/03-workflows/agents/workflow_as_agent_with_session.py +++ b/python/samples/03-workflows/agents/workflow_as_agent_with_session.py @@ -38,7 +38,7 @@ Use cases: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Environment variables configured for FoundryChatClient +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. """ @@ -46,7 +46,7 @@ async def main() -> None: # Create a chat client client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -72,7 +72,7 @@ async def main() -> None: workflow = SequentialBuilder(participants=[assistant, summarizer]).build() # Wrap the workflow as an agent - agent = Agent(client=workflow, name="ConversationalWorkflowAgent") + agent = workflow.as_agent() # Create a session to maintain history session = agent.create_session() @@ -133,7 +133,7 @@ async def demonstrate_session_serialization() -> None: """ client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -144,7 +144,7 @@ async def demonstrate_session_serialization() -> None: ) workflow = SequentialBuilder(participants=[memory_assistant]).build() - agent = Agent(client=workflow, name="MemoryWorkflowAgent") + agent = workflow.as_agent() # Create initial session and have a conversation session = agent.create_session() diff --git a/python/samples/03-workflows/checkpoint/checkpoint_with_human_in_the_loop.py b/python/samples/03-workflows/checkpoint/checkpoint_with_human_in_the_loop.py index 86c07cfa47..547bb1c6d3 100644 --- a/python/samples/03-workflows/checkpoint/checkpoint_with_human_in_the_loop.py +++ b/python/samples/03-workflows/checkpoint/checkpoint_with_human_in_the_loop.py @@ -182,7 +182,7 @@ def create_workflow(checkpoint_storage: FileCheckpointStorage) -> Workflow: writer_agent = Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions="Write concise, warm release notes that sound human and helpful.", diff --git a/python/samples/03-workflows/checkpoint/workflow_as_agent_checkpoint.py b/python/samples/03-workflows/checkpoint/workflow_as_agent_checkpoint.py index bb50e9f0a6..95f7d54b5b 100644 --- a/python/samples/03-workflows/checkpoint/workflow_as_agent_checkpoint.py +++ b/python/samples/03-workflows/checkpoint/workflow_as_agent_checkpoint.py @@ -21,7 +21,7 @@ Key concepts: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Environment variables configured for FoundryChatClient +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. """ import asyncio @@ -50,7 +50,7 @@ async def basic_checkpointing() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -67,7 +67,7 @@ async def basic_checkpointing() -> None: ) workflow = SequentialBuilder(participants=[assistant, reviewer]).build() - agent = Agent(client=workflow, name="CheckpointedAgent") + agent = workflow.as_agent() # Create checkpoint storage checkpoint_storage = InMemoryCheckpointStorage() @@ -97,7 +97,7 @@ async def checkpointing_with_thread() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -108,7 +108,7 @@ async def checkpointing_with_thread() -> None: ) workflow = SequentialBuilder(participants=[assistant]).build() - agent = Agent(client=workflow, name="MemoryAgent") + agent = workflow.as_agent() # Create both session (for conversation) and checkpoint storage (for workflow state) session = agent.create_session() @@ -145,7 +145,7 @@ async def streaming_with_checkpoints() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) @@ -156,7 +156,7 @@ async def streaming_with_checkpoints() -> None: ) workflow = SequentialBuilder(participants=[assistant]).build() - agent = Agent(client=workflow, name="StreamingCheckpointAgent") + agent = workflow.as_agent() checkpoint_storage = InMemoryCheckpointStorage() diff --git a/python/samples/03-workflows/composition/sub_workflow_kwargs.py b/python/samples/03-workflows/composition/sub_workflow_kwargs.py index 4404cf7b13..d3991e0218 100644 --- a/python/samples/03-workflows/composition/sub_workflow_kwargs.py +++ b/python/samples/03-workflows/composition/sub_workflow_kwargs.py @@ -34,7 +34,7 @@ Key Concepts: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Environment variables configured +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. """ @@ -84,7 +84,7 @@ async def main() -> None: # Create chat client client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/control-flow/edge_condition.py b/python/samples/03-workflows/control-flow/edge_condition.py index 89999ecaa3..e7969b21aa 100644 --- a/python/samples/03-workflows/control-flow/edge_condition.py +++ b/python/samples/03-workflows/control-flow/edge_condition.py @@ -139,7 +139,7 @@ def create_spam_detector_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( @@ -158,7 +158,7 @@ def create_email_assistant_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( diff --git a/python/samples/03-workflows/control-flow/multi_selection_edge_group.py b/python/samples/03-workflows/control-flow/multi_selection_edge_group.py index a5a96ad14f..36c7180642 100644 --- a/python/samples/03-workflows/control-flow/multi_selection_edge_group.py +++ b/python/samples/03-workflows/control-flow/multi_selection_edge_group.py @@ -191,7 +191,7 @@ def create_email_analysis_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( @@ -209,7 +209,7 @@ def create_email_assistant_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=("You are an email assistant that helps users draft responses to emails with professionalism."), @@ -223,7 +223,7 @@ def create_email_summary_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=("You are an assistant that helps users summarize emails."), diff --git a/python/samples/03-workflows/control-flow/simple_loop.py b/python/samples/03-workflows/control-flow/simple_loop.py index 3adc75625e..2f0734401d 100644 --- a/python/samples/03-workflows/control-flow/simple_loop.py +++ b/python/samples/03-workflows/control-flow/simple_loop.py @@ -33,7 +33,7 @@ What it does: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure AI/ Azure OpenAI for `FoundryChatClient` agent. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via `azure-identity` — uses `AzureCliCredential()` (run `az login`). """ @@ -126,7 +126,7 @@ def create_judge_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=("You strictly respond with one of: MATCHED, ABOVE, BELOW based on the given target and guess."), diff --git a/python/samples/03-workflows/control-flow/switch_case_edge_group.py b/python/samples/03-workflows/control-flow/switch_case_edge_group.py index b7c1ece95e..9036081a4d 100644 --- a/python/samples/03-workflows/control-flow/switch_case_edge_group.py +++ b/python/samples/03-workflows/control-flow/switch_case_edge_group.py @@ -162,7 +162,7 @@ def create_spam_detection_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( @@ -181,7 +181,7 @@ def create_email_assistant_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=("You are an email assistant that helps users draft responses to emails with professionalism."), diff --git a/python/samples/03-workflows/declarative/agent_to_function_tool/main.py b/python/samples/03-workflows/declarative/agent_to_function_tool/main.py index 8f931d4bf5..54e393ee14 100644 --- a/python/samples/03-workflows/declarative/agent_to_function_tool/main.py +++ b/python/samples/03-workflows/declarative/agent_to_function_tool/main.py @@ -204,7 +204,7 @@ async def main(): # Create Azure OpenAI Responses client chat_client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/declarative/customer_support/main.py b/python/samples/03-workflows/declarative/customer_support/main.py index 03bd68cff5..374825871d 100644 --- a/python/samples/03-workflows/declarative/customer_support/main.py +++ b/python/samples/03-workflows/declarative/customer_support/main.py @@ -173,7 +173,7 @@ async def main() -> None: project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], # This sample has been tested only on `gpt-5.1` and may not work as intended on other models # This sample is known to fail on `gpt-5-mini` reasoning input (GH issue #4059) - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/declarative/deep_research/main.py b/python/samples/03-workflows/declarative/deep_research/main.py index d6dbb4d65d..49e9b86b8a 100644 --- a/python/samples/03-workflows/declarative/deep_research/main.py +++ b/python/samples/03-workflows/declarative/deep_research/main.py @@ -29,10 +29,11 @@ from agent_framework import Agent from agent_framework.declarative import WorkflowFactory from agent_framework.foundry import FoundryChatClient from azure.identity import AzureCliCredential +from dotenv import load_dotenv from pydantic import BaseModel, Field -# Copyright (c) Microsoft. All rights reserved. - +# Load environment variables from .env file +load_dotenv() # Agent Instructions RESEARCH_INSTRUCTIONS = """In order to help begin addressing the user request, please answer the following pre-survey to the best of your ability. @@ -126,7 +127,7 @@ async def main() -> None: # Create Azure OpenAI client client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/declarative/function_tools/main.py b/python/samples/03-workflows/declarative/function_tools/main.py index b8f4ec44f9..8ee4b08e9d 100644 --- a/python/samples/03-workflows/declarative/function_tools/main.py +++ b/python/samples/03-workflows/declarative/function_tools/main.py @@ -71,7 +71,7 @@ async def main(): # Create agent with tools client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) menu_agent = Agent( diff --git a/python/samples/03-workflows/declarative/marketing/main.py b/python/samples/03-workflows/declarative/marketing/main.py index 66a121e5b1..17a7eaacfe 100644 --- a/python/samples/03-workflows/declarative/marketing/main.py +++ b/python/samples/03-workflows/declarative/marketing/main.py @@ -56,7 +56,7 @@ async def main() -> None: """Run the marketing workflow with real Azure AI agents.""" client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/declarative/student_teacher/main.py b/python/samples/03-workflows/declarative/student_teacher/main.py index 415625a300..f9c47fd151 100644 --- a/python/samples/03-workflows/declarative/student_teacher/main.py +++ b/python/samples/03-workflows/declarative/student_teacher/main.py @@ -16,7 +16,7 @@ Prerequisites: - Azure OpenAI deployment with chat completion capability - Environment variables: FOUNDRY_PROJECT_ENDPOINT: Your Azure AI Foundry Agent Service (V2) project endpoint - AZURE_AI_MODEL_DEPLOYMENT_NAME: Your model deployment name + FOUNDRY_MODEL: Your model deployment name """ import asyncio @@ -27,8 +27,10 @@ from agent_framework import Agent from agent_framework.declarative import WorkflowFactory from agent_framework.foundry import FoundryChatClient from azure.identity import AzureCliCredential +from dotenv.main import load_dotenv -# Copyright (c) Microsoft. All rights reserved. +# Load environment variables from .env file +load_dotenv() STUDENT_INSTRUCTIONS = """You are a curious math student working on understanding mathematical concepts. @@ -58,7 +60,7 @@ async def main() -> None: # Create chat client client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/human-in-the-loop/agents_with_HITL.py b/python/samples/03-workflows/human-in-the-loop/agents_with_HITL.py index 42e58083c0..4d45047139 100644 --- a/python/samples/03-workflows/human-in-the-loop/agents_with_HITL.py +++ b/python/samples/03-workflows/human-in-the-loop/agents_with_HITL.py @@ -44,7 +44,7 @@ Demonstrates: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Run `az login` before executing. """ @@ -78,11 +78,7 @@ class Coordinator(Executor): # Writer agent response; request human feedback. # Preserve the full conversation so that the final editor has context. - conversation: list[Message] - if draft.full_conversation is not None: - conversation = list(draft.full_conversation) - else: - conversation = list(draft.agent_response.messages) + conversation = list(draft.full_conversation) prompt = ( "Review the draft from the writer and provide a short directional note " @@ -172,18 +168,20 @@ async def main() -> None: writer_agent = Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), name="writer_agent", instructions=("You are a marketing writer."), - tool_choice="required", + default_options={ + "tool_choice": "required", + }, ) final_editor_agent = Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), name="final_editor_agent", diff --git a/python/samples/03-workflows/human-in-the-loop/agents_with_approval_requests.py b/python/samples/03-workflows/human-in-the-loop/agents_with_approval_requests.py index 85850e78ce..adb1fff4d5 100644 --- a/python/samples/03-workflows/human-in-the-loop/agents_with_approval_requests.py +++ b/python/samples/03-workflows/human-in-the-loop/agents_with_approval_requests.py @@ -53,7 +53,7 @@ Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure AI Agent Service configured, along with the required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Basic familiarity with WorkflowBuilder, edges, events, request_info events (type='request_info'), and streaming runs. """ @@ -228,7 +228,7 @@ async def main() -> None: email_writer_agent = Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), name="EmailWriter", diff --git a/python/samples/03-workflows/human-in-the-loop/agents_with_declaration_only_tools.py b/python/samples/03-workflows/human-in-the-loop/agents_with_declaration_only_tools.py index 1ab0ea81e7..0c55fb2fc2 100644 --- a/python/samples/03-workflows/human-in-the-loop/agents_with_declaration_only_tools.py +++ b/python/samples/03-workflows/human-in-the-loop/agents_with_declaration_only_tools.py @@ -53,7 +53,7 @@ get_user_location = FunctionTool( async def main() -> None: _client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) agent = Agent( diff --git a/python/samples/03-workflows/human-in-the-loop/concurrent_request_info.py b/python/samples/03-workflows/human-in-the-loop/concurrent_request_info.py index ea5717f337..96dd8ccc52 100644 --- a/python/samples/03-workflows/human-in-the-loop/concurrent_request_info.py +++ b/python/samples/03-workflows/human-in-the-loop/concurrent_request_info.py @@ -18,7 +18,7 @@ Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity (run az login before executing) """ @@ -151,7 +151,7 @@ async def main() -> None: global _chat_client _chat_client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/human-in-the-loop/group_chat_request_info.py b/python/samples/03-workflows/human-in-the-loop/group_chat_request_info.py index c5364d8d47..ff108002ca 100644 --- a/python/samples/03-workflows/human-in-the-loop/group_chat_request_info.py +++ b/python/samples/03-workflows/human-in-the-loop/group_chat_request_info.py @@ -19,7 +19,7 @@ Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity (run az login before executing) """ @@ -99,7 +99,7 @@ async def process_event_stream(stream: AsyncIterable[WorkflowEvent]) -> dict[str async def main() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/human-in-the-loop/guessing_game_with_human_input.py b/python/samples/03-workflows/human-in-the-loop/guessing_game_with_human_input.py index 801d95c8fa..14f6fa2cb0 100644 --- a/python/samples/03-workflows/human-in-the-loop/guessing_game_with_human_input.py +++ b/python/samples/03-workflows/human-in-the-loop/guessing_game_with_human_input.py @@ -44,7 +44,7 @@ Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Basic familiarity with WorkflowBuilder, executors, edges, events, and streaming runs. """ @@ -200,7 +200,7 @@ async def main() -> None: guessing_agent = Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), name="GuessingAgent", diff --git a/python/samples/03-workflows/human-in-the-loop/sequential_request_info.py b/python/samples/03-workflows/human-in-the-loop/sequential_request_info.py index d5294afe01..3b9d1f0e33 100644 --- a/python/samples/03-workflows/human-in-the-loop/sequential_request_info.py +++ b/python/samples/03-workflows/human-in-the-loop/sequential_request_info.py @@ -18,7 +18,7 @@ Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity (run az login before executing) """ @@ -96,7 +96,7 @@ async def process_event_stream(stream: AsyncIterable[WorkflowEvent]) -> dict[str async def main() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/concurrent_agents.py b/python/samples/03-workflows/orchestrations/concurrent_agents.py index 74e53f3970..7e90ff1bda 100644 --- a/python/samples/03-workflows/orchestrations/concurrent_agents.py +++ b/python/samples/03-workflows/orchestrations/concurrent_agents.py @@ -28,7 +28,7 @@ Demonstrates: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Familiarity with Workflow events (WorkflowEvent) """ @@ -38,7 +38,7 @@ async def main() -> None: # 1) Create three domain agents using FoundryChatClient client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/concurrent_custom_agent_executors.py b/python/samples/03-workflows/orchestrations/concurrent_custom_agent_executors.py index 968247f850..4ebdf4ceca 100644 --- a/python/samples/03-workflows/orchestrations/concurrent_custom_agent_executors.py +++ b/python/samples/03-workflows/orchestrations/concurrent_custom_agent_executors.py @@ -38,7 +38,7 @@ Demonstrates: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -109,7 +109,7 @@ class LegalExec(Executor): async def main() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/concurrent_custom_aggregator.py b/python/samples/03-workflows/orchestrations/concurrent_custom_aggregator.py index ad3c849afe..74afd5df85 100644 --- a/python/samples/03-workflows/orchestrations/concurrent_custom_aggregator.py +++ b/python/samples/03-workflows/orchestrations/concurrent_custom_aggregator.py @@ -30,7 +30,7 @@ Demonstrates: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -38,7 +38,7 @@ Prerequisites: async def main() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/group_chat_agent_manager.py b/python/samples/03-workflows/orchestrations/group_chat_agent_manager.py index c1929f8fb1..dea82a4352 100644 --- a/python/samples/03-workflows/orchestrations/group_chat_agent_manager.py +++ b/python/samples/03-workflows/orchestrations/group_chat_agent_manager.py @@ -27,7 +27,7 @@ What it does: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -45,7 +45,7 @@ async def main() -> None: # Create a Responses client using Azure OpenAI and Azure CLI credentials for all agents client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/group_chat_philosophical_debate.py b/python/samples/03-workflows/orchestrations/group_chat_philosophical_debate.py index 902bd271c6..867bbd7bc3 100644 --- a/python/samples/03-workflows/orchestrations/group_chat_philosophical_debate.py +++ b/python/samples/03-workflows/orchestrations/group_chat_philosophical_debate.py @@ -40,7 +40,7 @@ Participants represent: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -51,7 +51,7 @@ load_dotenv() def _get_chat_client() -> FoundryChatClient: return FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/group_chat_simple_selector.py b/python/samples/03-workflows/orchestrations/group_chat_simple_selector.py index 99d7e1a963..2fceaa98d0 100644 --- a/python/samples/03-workflows/orchestrations/group_chat_simple_selector.py +++ b/python/samples/03-workflows/orchestrations/group_chat_simple_selector.py @@ -26,7 +26,7 @@ What it does: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -42,7 +42,7 @@ async def main() -> None: # Create a Responses client using Azure OpenAI and Azure CLI credentials for all agents client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/handoff_autonomous.py b/python/samples/03-workflows/orchestrations/handoff_autonomous.py index 7fcb8842f2..355a782f9d 100644 --- a/python/samples/03-workflows/orchestrations/handoff_autonomous.py +++ b/python/samples/03-workflows/orchestrations/handoff_autonomous.py @@ -84,7 +84,7 @@ async def main() -> None: """Run an autonomous handoff workflow with specialist iteration enabled.""" client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) coordinator, research_agent, summary_agent = create_agents(client) diff --git a/python/samples/03-workflows/orchestrations/handoff_simple.py b/python/samples/03-workflows/orchestrations/handoff_simple.py index d288b51c0d..b804c5e63a 100644 --- a/python/samples/03-workflows/orchestrations/handoff_simple.py +++ b/python/samples/03-workflows/orchestrations/handoff_simple.py @@ -27,7 +27,7 @@ them to transfer control to each other based on the conversation context. Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. - - Azure OpenAI configured for FoundryChatClient with required environment variables. + - FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run `az login` before executing the sample. Key Concepts: @@ -201,7 +201,7 @@ async def main() -> None: # Initialize the Azure OpenAI Responses client client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/handoff_with_code_interpreter_file.py b/python/samples/03-workflows/orchestrations/handoff_with_code_interpreter_file.py index d6de4efcb5..ced94109a2 100644 --- a/python/samples/03-workflows/orchestrations/handoff_with_code_interpreter_file.py +++ b/python/samples/03-workflows/orchestrations/handoff_with_code_interpreter_file.py @@ -13,8 +13,8 @@ HandoffBuilder workflows can be properly retrieved. Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. + - FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - `az login` (Azure CLI authentication) - - AZURE_AI_MODEL_DEPLOYMENT_NAME """ import asyncio @@ -93,7 +93,7 @@ async def main() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/handoff_with_tool_approval_checkpoint_resume.py b/python/samples/03-workflows/orchestrations/handoff_with_tool_approval_checkpoint_resume.py index e1e01c0415..4b65561532 100644 --- a/python/samples/03-workflows/orchestrations/handoff_with_tool_approval_checkpoint_resume.py +++ b/python/samples/03-workflows/orchestrations/handoff_with_tool_approval_checkpoint_resume.py @@ -46,8 +46,8 @@ Pattern: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Azure CLI authentication (az login). -- Environment variables configured for FoundryChatClient. """ CHECKPOINT_DIR = Path(__file__).parent / "tmp" / "handoff_checkpoints" @@ -102,7 +102,7 @@ def create_workflow(checkpoint_storage: FileCheckpointStorage) -> Workflow: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) triage, refund, order = create_agents(client) diff --git a/python/samples/03-workflows/orchestrations/magentic.py b/python/samples/03-workflows/orchestrations/magentic.py index 07ca80a61d..f7a472049c 100644 --- a/python/samples/03-workflows/orchestrations/magentic.py +++ b/python/samples/03-workflows/orchestrations/magentic.py @@ -43,7 +43,7 @@ events, and prints the final answer. The workflow completes when idle. Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -54,7 +54,7 @@ load_dotenv() async def main() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/magentic_checkpoint.py b/python/samples/03-workflows/orchestrations/magentic_checkpoint.py index fba3da09d1..df606a5a43 100644 --- a/python/samples/03-workflows/orchestrations/magentic_checkpoint.py +++ b/python/samples/03-workflows/orchestrations/magentic_checkpoint.py @@ -40,7 +40,7 @@ Concepts highlighted here: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -66,7 +66,7 @@ def build_workflow(checkpoint_storage: FileCheckpointStorage): instructions=("You are the research lead. Gather crisp bullet points the team should know."), client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) @@ -77,7 +77,7 @@ def build_workflow(checkpoint_storage: FileCheckpointStorage): instructions=("You convert the research notes into a structured brief with milestones and risks."), client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) @@ -89,7 +89,7 @@ def build_workflow(checkpoint_storage: FileCheckpointStorage): instructions="You coordinate a team to complete complex tasks efficiently.", client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), ) diff --git a/python/samples/03-workflows/orchestrations/magentic_human_plan_review.py b/python/samples/03-workflows/orchestrations/magentic_human_plan_review.py index acfe43a750..e44e2a44ca 100644 --- a/python/samples/03-workflows/orchestrations/magentic_human_plan_review.py +++ b/python/samples/03-workflows/orchestrations/magentic_human_plan_review.py @@ -38,7 +38,7 @@ Plan review options: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -102,7 +102,7 @@ async def process_event_stream(stream: AsyncIterable[WorkflowEvent]) -> dict[str async def main() -> None: client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/sequential_agents.py b/python/samples/03-workflows/orchestrations/sequential_agents.py index 8a64b22368..70a25d9f58 100644 --- a/python/samples/03-workflows/orchestrations/sequential_agents.py +++ b/python/samples/03-workflows/orchestrations/sequential_agents.py @@ -30,7 +30,7 @@ Note on internal adapters: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -39,7 +39,7 @@ async def main() -> None: # 1) Create agents client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/orchestrations/sequential_chain_only_agent_responses.py b/python/samples/03-workflows/orchestrations/sequential_chain_only_agent_responses.py index 2bef81ebe5..f4723a205d 100644 --- a/python/samples/03-workflows/orchestrations/sequential_chain_only_agent_responses.py +++ b/python/samples/03-workflows/orchestrations/sequential_chain_only_agent_responses.py @@ -3,8 +3,8 @@ import asyncio import os -from agent_framework import AgentResponseUpdate -from agent_framework.azure import AzureOpenAIResponsesClient +from agent_framework import Agent, AgentResponseUpdate +from agent_framework.foundry import FoundryChatClient from agent_framework.orchestrations import SequentialBuilder from azure.identity import AzureCliCredential from dotenv import load_dotenv @@ -25,8 +25,8 @@ Compare with `sequential_agents.py`, which uses the default behavior where the f conversation context is passed to each agent. Prerequisites: -- AZURE_AI_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for AzureOpenAIResponsesClient with required environment variables. +- FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. +- FOUNDRY_MODEL must be the deployment name of a model in your Foundry project. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -36,23 +36,26 @@ load_dotenv() async def main() -> None: # 1) Create agents - client = AzureOpenAIResponsesClient( - project_endpoint=os.environ["AZURE_AI_PROJECT_ENDPOINT"], - deployment_name=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + client = FoundryChatClient( + project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) - writer = client.as_agent( + writer = Agent( + client=client, instructions="You are a concise copywriter. Provide a single, punchy marketing sentence based on the prompt.", name="writer", ) - translator = client.as_agent( + translator = Agent( + client=client, instructions="You are a translator. Translate the given text into French. Output only the translation.", name="translator", ) - reviewer = client.as_agent( + reviewer = Agent( + client=client, instructions="You are a reviewer. Evaluate the quality of the marketing tagline.", name="reviewer", ) diff --git a/python/samples/03-workflows/orchestrations/sequential_custom_executors.py b/python/samples/03-workflows/orchestrations/sequential_custom_executors.py index 79823ea643..a4fb2d602b 100644 --- a/python/samples/03-workflows/orchestrations/sequential_custom_executors.py +++ b/python/samples/03-workflows/orchestrations/sequential_custom_executors.py @@ -35,7 +35,7 @@ Custom executor contract: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. """ @@ -68,7 +68,7 @@ async def main() -> None: # 1) Create a content agent client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) content = Agent( diff --git a/python/samples/03-workflows/parallelism/fan_out_fan_in_edges.py b/python/samples/03-workflows/parallelism/fan_out_fan_in_edges.py index 3eaeb21ea0..456ff7e212 100644 --- a/python/samples/03-workflows/parallelism/fan_out_fan_in_edges.py +++ b/python/samples/03-workflows/parallelism/fan_out_fan_in_edges.py @@ -37,8 +37,8 @@ Show how to construct a parallel branch pattern in workflows. Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Familiarity with WorkflowBuilder, executors, edges, events, and streaming runs. -- Azure OpenAI access configured for FoundryChatClient. Log in with Azure CLI and set any required environment variables. - Comfort reading AgentExecutorResponse.agent_response.text for assistant output aggregation. """ @@ -118,7 +118,7 @@ async def main() -> None: Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( @@ -132,7 +132,7 @@ async def main() -> None: Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( @@ -146,7 +146,7 @@ async def main() -> None: Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( diff --git a/python/samples/03-workflows/state-management/state_with_agents.py b/python/samples/03-workflows/state-management/state_with_agents.py index b9e800ba04..3c51b6fb9e 100644 --- a/python/samples/03-workflows/state-management/state_with_agents.py +++ b/python/samples/03-workflows/state-management/state_with_agents.py @@ -40,7 +40,7 @@ Show how to: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure OpenAI configured for FoundryChatClient with required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample. - Familiarity with WorkflowBuilder, executors, conditional edges, and streaming runs. """ @@ -165,7 +165,7 @@ def create_spam_detection_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( @@ -183,7 +183,7 @@ def create_email_assistant_agent() -> Agent: return Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( diff --git a/python/samples/03-workflows/state-management/workflow_kwargs.py b/python/samples/03-workflows/state-management/workflow_kwargs.py index 630eaafc52..0d50b8710d 100644 --- a/python/samples/03-workflows/state-management/workflow_kwargs.py +++ b/python/samples/03-workflows/state-management/workflow_kwargs.py @@ -29,7 +29,7 @@ Key Concepts: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Environment variables configured +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. """ @@ -83,7 +83,7 @@ async def main() -> None: # Create chat client client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/tool-approval/concurrent_builder_tool_approval.py b/python/samples/03-workflows/tool-approval/concurrent_builder_tool_approval.py index d11e4d3525..b9a0e7d229 100644 --- a/python/samples/03-workflows/tool-approval/concurrent_builder_tool_approval.py +++ b/python/samples/03-workflows/tool-approval/concurrent_builder_tool_approval.py @@ -46,7 +46,7 @@ Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- OpenAI or Azure OpenAI configured with the required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Basic familiarity with ConcurrentBuilder and streaming workflow events. """ @@ -136,7 +136,7 @@ async def main() -> None: # 3. Create two agents focused on different stocks but with the same tool sets client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/tool-approval/group_chat_builder_tool_approval.py b/python/samples/03-workflows/tool-approval/group_chat_builder_tool_approval.py index 8fff4b7dd3..371ff20294 100644 --- a/python/samples/03-workflows/tool-approval/group_chat_builder_tool_approval.py +++ b/python/samples/03-workflows/tool-approval/group_chat_builder_tool_approval.py @@ -45,7 +45,7 @@ Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- OpenAI or Azure OpenAI configured with the required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Basic familiarity with GroupChatBuilder and streaming workflow events. """ @@ -136,7 +136,7 @@ async def main() -> None: # 3. Create specialized agents client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) diff --git a/python/samples/03-workflows/tool-approval/sequential_builder_tool_approval.py b/python/samples/03-workflows/tool-approval/sequential_builder_tool_approval.py index a6272b196c..318506316e 100644 --- a/python/samples/03-workflows/tool-approval/sequential_builder_tool_approval.py +++ b/python/samples/03-workflows/tool-approval/sequential_builder_tool_approval.py @@ -46,7 +46,7 @@ Demonstrate: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- OpenAI or Azure OpenAI configured with the required environment variables. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Basic familiarity with SequentialBuilder and streaming workflow events. """ @@ -109,7 +109,7 @@ async def main() -> None: # 2. Create the agent with tools (approval mode is set per-tool via decorator) client = FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ) database_agent = Agent( diff --git a/python/samples/03-workflows/visualization/concurrent_with_visualization.py b/python/samples/03-workflows/visualization/concurrent_with_visualization.py index f11b8d291b..d59268540e 100644 --- a/python/samples/03-workflows/visualization/concurrent_with_visualization.py +++ b/python/samples/03-workflows/visualization/concurrent_with_visualization.py @@ -34,7 +34,7 @@ What it does: Prerequisites: - FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint. -- Azure AI/ Azure OpenAI for `FoundryChatClient` agents. +- FOUNDRY_MODEL must be set to your Azure OpenAI model deployment name. - Authentication via `azure-identity` — uses `AzureCliCredential()` (run `az login`). - For visualization export: `pip install graphviz>=0.20.0` and install GraphViz binaries. """ @@ -100,7 +100,7 @@ async def main() -> None: Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( @@ -115,7 +115,7 @@ async def main() -> None: Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( @@ -130,7 +130,7 @@ async def main() -> None: Agent( client=FoundryChatClient( project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"], - model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"], + model=os.environ["FOUNDRY_MODEL"], credential=AzureCliCredential(), ), instructions=( diff --git a/python/samples/README.md b/python/samples/README.md index 82a008504c..33a385a4f9 100644 --- a/python/samples/README.md +++ b/python/samples/README.md @@ -44,8 +44,8 @@ Samples call `load_dotenv()` to automatically load environment variables from a **Option 2: Export environment variables directly**: ```bash -export AZURE_AI_PROJECT_ENDPOINT="your-foundry-project-endpoint" -export AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="gpt-4o" +export FOUNDRY_PROJECT_ENDPOINT="your-foundry-project-endpoint" +export FOUNDRY_MODEL="gpt-4o" ``` **Option 3: Using `env_file_path` parameter** (for per-client configuration): @@ -73,8 +73,8 @@ you pass an explicit Azure input. For the getting-started samples, you'll need at minimum: ```bash -AZURE_AI_PROJECT_ENDPOINT="your-foundry-project-endpoint" -AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="gpt-4o" +FOUNDRY_PROJECT_ENDPOINT="your-foundry-project-endpoint" +FOUNDRY_MODEL="gpt-4o" ``` **Note for production**: In production environments, set environment variables through your deployment platform (e.g., Azure App Settings, Kubernetes ConfigMaps/Secrets) rather than using `.env` files. The `load_dotenv()` call in samples will have no effect when a `.env` file is not present, allowing environment variables to be loaded from the system. diff --git a/python/scripts/sample_validation/create_dynamic_workflow_executor.py b/python/scripts/sample_validation/create_dynamic_workflow_executor.py index 4cffd5c71b..44a7e5a0c5 100644 --- a/python/scripts/sample_validation/create_dynamic_workflow_executor.py +++ b/python/scripts/sample_validation/create_dynamic_workflow_executor.py @@ -292,7 +292,7 @@ class CreateConcurrentValidationWorkflowExecutor(Executor): instructions=AgentInstruction, default_options={ "on_permission_request": prompt_permission, - "timeout": 60, + "timeout": 120, }, # type: ignore ) agents.append(agent)