Skip to content

Commit 016daf3

Browse files
authored
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
1 parent 0f81c27 commit 016daf3

69 files changed

Lines changed: 234 additions & 306 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/actions/sample-validation-setup/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ runs:
3434

3535
- name: Test Copilot CLI
3636
shell: bash
37-
run: copilot -p "What can you do in one sentence?"
37+
run: copilot --version && copilot -p "What can you do in one sentence?"
3838

3939
- name: Azure CLI Login
4040
uses: azure/login@v2

.github/workflows/python-sample-validation.yml

Lines changed: 29 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,13 @@ jobs:
6767
# Azure AI configuration
6868
AZURE_AI_PROJECT_ENDPOINT: ${{ vars.AZURE_AI_PROJECT_ENDPOINT }}
6969
AZURE_AI_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }}
70+
FOUNDRY_PROJECT_ENDPOINT: ${{ vars.FOUNDRY_PROJECT_ENDPOINT }}
71+
FOUNDRY_MODEL: ${{ vars.FOUNDRY_MODEL }}
7072
# Azure OpenAI configuration
7173
AZURE_OPENAI_ENDPOINT: ${{ vars.AZUREOPENAI__ENDPOINT }}
7274
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__CHATDEPLOYMENTNAME }}
7375
AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }}
74-
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__EMBEDDINGDEPLOYMENTNAME }}
76+
AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME }}
7577
# OpenAI configuration
7678
OPENAI_API_KEY: ${{ secrets.OPENAI__APIKEY }}
7779
OPENAI_CHAT_MODEL_ID: ${{ vars.OPENAI__CHATMODELID }}
@@ -97,6 +99,8 @@ jobs:
9799

98100
- name: Create .env for samples
99101
run: |
102+
echo "FOUNDRY_PROJECT_ENDPOINT=$FOUNDRY_PROJECT_ENDPOINT" >> .env
103+
echo "FOUNDRY_MODEL=$FOUNDRY_MODEL" >> .env
100104
echo "AZURE_AI_PROJECT_ENDPOINT=$AZURE_AI_PROJECT_ENDPOINT" >> .env
101105
echo "AZURE_AI_MODEL_DEPLOYMENT_NAME=$AZURE_AI_MODEL_DEPLOYMENT_NAME" >> .env
102106
echo "AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT" >> .env
@@ -125,6 +129,7 @@ jobs:
125129
environment: integration
126130
env:
127131
OPENAI_API_KEY: ${{ secrets.OPENAI__APIKEY }}
132+
OPENAI_MODEL: ${{ vars.OPENAI__CHATMODELID }}
128133
OPENAI_CHAT_MODEL_ID: ${{ vars.OPENAI__CHATMODELID }}
129134
OPENAI_RESPONSES_MODEL_ID: ${{ vars.OPENAI__RESPONSESMODELID }}
130135
defaults:
@@ -144,6 +149,7 @@ jobs:
144149
- name: Create .env for samples
145150
run: |
146151
echo "OPENAI_API_KEY=$OPENAI_API_KEY" >> .env
152+
echo "OPENAI_MODEL=$OPENAI_MODEL" >> .env
147153
echo "OPENAI_CHAT_MODEL_ID=$OPENAI_CHAT_MODEL_ID" >> .env
148154
echo "OPENAI_RESPONSES_MODEL_ID=$OPENAI_RESPONSES_MODEL_ID" >> .env
149155
@@ -158,8 +164,8 @@ jobs:
158164
name: validation-report-02-agents-openai
159165
path: python/samples/sample_validation/reports/
160166

161-
validate-02-agents-azure-openai:
162-
name: Validate 02-agents/providers/azure_openai
167+
validate-02-agents-azure:
168+
name: Validate 02-agents/providers/azure
163169
runs-on: ubuntu-latest
164170
environment: integration
165171
env:
@@ -190,93 +196,13 @@ jobs:
190196
191197
- name: Run sample validation
192198
run: |
193-
cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/azure_openai --save-report --report-name 02-agents-azure-openai
199+
cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/azure --save-report --report-name 02-agents-azure
194200
195201
- name: Upload validation report
196202
uses: actions/upload-artifact@v7
197203
if: always()
198204
with:
199-
name: validation-report-02-agents-azure-openai
200-
path: python/samples/sample_validation/reports/
201-
202-
validate-02-agents-azure-ai:
203-
name: Validate 02-agents/providers/azure_ai
204-
runs-on: ubuntu-latest
205-
environment: integration
206-
env:
207-
AZURE_AI_PROJECT_ENDPOINT: ${{ vars.AZURE_AI_PROJECT_ENDPOINT }}
208-
AZURE_AI_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }}
209-
AZURE_AI_CHAT_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__CHATDEPLOYMENTNAME }}
210-
AZURE_AI_EMBEDDING_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__EMBEDDINGDEPLOYMENTNAME }}
211-
BING_CONNECTION_ID: ${{ secrets.BING_CONNECTION_ID }}
212-
defaults:
213-
run:
214-
working-directory: python
215-
steps:
216-
- uses: actions/checkout@v6
217-
218-
- name: Setup environment
219-
uses: ./.github/actions/sample-validation-setup
220-
with:
221-
azure-client-id: ${{ secrets.AZURE_CLIENT_ID }}
222-
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }}
223-
azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
224-
os: ${{ runner.os }}
225-
226-
- name: Create .env for samples
227-
run: |
228-
echo "AZURE_AI_PROJECT_ENDPOINT=$AZURE_AI_PROJECT_ENDPOINT" >> .env
229-
echo "AZURE_AI_MODEL_DEPLOYMENT_NAME=$AZURE_AI_MODEL_DEPLOYMENT_NAME" >> .env
230-
echo "AZURE_AI_CHAT_MODEL_DEPLOYMENT_NAME=$AZURE_AI_CHAT_MODEL_DEPLOYMENT_NAME" >> .env
231-
echo "AZURE_AI_EMBEDDING_MODEL_DEPLOYMENT_NAME=$AZURE_AI_EMBEDDING_MODEL_DEPLOYMENT_NAME" >> .env
232-
echo "BING_CONNECTION_ID=$BING_CONNECTION_ID" >> .env
233-
234-
- name: Run sample validation
235-
run: |
236-
cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/azure_ai --save-report --report-name 02-agents-azure-ai
237-
238-
- name: Upload validation report
239-
uses: actions/upload-artifact@v7
240-
if: always()
241-
with:
242-
name: validation-report-02-agents-azure-ai
243-
path: python/samples/sample_validation/reports/
244-
245-
validate-02-agents-azure-ai-agent:
246-
name: Validate 02-agents/providers/azure_ai_agent
247-
runs-on: ubuntu-latest
248-
environment: integration
249-
env:
250-
AZURE_AI_PROJECT_ENDPOINT: ${{ vars.AZURE_AI_PROJECT_ENDPOINT }}
251-
AZURE_AI_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }}
252-
defaults:
253-
run:
254-
working-directory: python
255-
steps:
256-
- uses: actions/checkout@v6
257-
258-
- name: Setup environment
259-
uses: ./.github/actions/sample-validation-setup
260-
with:
261-
azure-client-id: ${{ secrets.AZURE_CLIENT_ID }}
262-
azure-tenant-id: ${{ secrets.AZURE_TENANT_ID }}
263-
azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
264-
os: ${{ runner.os }}
265-
266-
- name: Create .env for samples
267-
run: |
268-
echo "AZURE_AI_PROJECT_ENDPOINT=$AZURE_AI_PROJECT_ENDPOINT" >> .env
269-
echo "AZURE_AI_MODEL_DEPLOYMENT_NAME=$AZURE_AI_MODEL_DEPLOYMENT_NAME" >> .env
270-
271-
- name: Run sample validation
272-
run: |
273-
cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/azure_ai_agent --save-report --report-name 02-agents-azure-ai-agent
274-
275-
- name: Upload validation report
276-
uses: actions/upload-artifact@v7
277-
if: always()
278-
with:
279-
name: validation-report-02-agents-azure-ai-agent
205+
name: validation-report-02-agents-azure
280206
path: python/samples/sample_validation/reports/
281207

282208
validate-02-agents-anthropic:
@@ -409,11 +335,13 @@ jobs:
409335
name: validation-report-02-agents-ollama
410336
path: python/samples/sample_validation/reports/
411337

412-
validate-02-agents-foundry-local:
413-
name: Validate 02-agents/providers/foundry_local
414-
if: false # Temporarily disabled - requires local Foundry setup
338+
validate-02-agents-foundry:
339+
name: Validate 02-agents/providers/foundry
415340
runs-on: ubuntu-latest
416341
environment: integration
342+
env:
343+
FOUNDRY_PROJECT_ENDPOINT: ${{ vars.FOUNDRY_PROJECT_ENDPOINT }}
344+
FOUNDRY_MODEL: ${{ vars.FOUNDRY_MODEL }}
417345
defaults:
418346
run:
419347
working-directory: python
@@ -428,15 +356,20 @@ jobs:
428356
azure-subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
429357
os: ${{ runner.os }}
430358

359+
- name: Create .env for samples
360+
run: |
361+
echo "FOUNDRY_PROJECT_ENDPOINT=$FOUNDRY_PROJECT_ENDPOINT" >> .env
362+
echo "FOUNDRY_MODEL=$FOUNDRY_MODEL" >> .env
363+
431364
- name: Run sample validation
432365
run: |
433-
cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/foundry_local --save-report --report-name 02-agents-foundry-local
366+
cd scripts && uv run python -m sample_validation --subdir 02-agents/providers/foundry --save-report --report-name 02-agents-foundry
434367
435368
- name: Upload validation report
436369
uses: actions/upload-artifact@v7
437370
if: always()
438371
with:
439-
name: validation-report-02-agents-foundry-local
372+
name: validation-report-02-agents-foundry
440373
path: python/samples/sample_validation/reports/
441374

442375
validate-02-agents-copilotstudio:
@@ -516,6 +449,8 @@ jobs:
516449
environment: integration
517450
env:
518451
# Azure AI configuration
452+
FOUNDRY_PROJECT_ENDPOINT: ${{ vars.FOUNDRY_PROJECT_ENDPOINT }}
453+
FOUNDRY_MODEL: ${{ vars.FOUNDRY_MODEL }}
519454
AZURE_AI_PROJECT_ENDPOINT: ${{ vars.AZURE_AI_PROJECT_ENDPOINT }}
520455
AZURE_AI_MODEL_DEPLOYMENT_NAME: ${{ vars.AZUREOPENAI__RESPONSESDEPLOYMENTNAME }}
521456
# Azure OpenAI configuration
@@ -538,6 +473,8 @@ jobs:
538473

539474
- name: Create .env for samples
540475
run: |
476+
echo "FOUNDRY_PROJECT_ENDPOINT=$FOUNDRY_PROJECT_ENDPOINT" >> .env
477+
echo "FOUNDRY_MODEL=$FOUNDRY_MODEL" >> .env
541478
echo "AZURE_AI_PROJECT_ENDPOINT=$AZURE_AI_PROJECT_ENDPOINT" >> .env
542479
echo "AZURE_AI_MODEL_DEPLOYMENT_NAME=$AZURE_AI_MODEL_DEPLOYMENT_NAME" >> .env
543480
echo "AZURE_OPENAI_ENDPOINT=$AZURE_OPENAI_ENDPOINT" >> .env
@@ -759,14 +696,12 @@ jobs:
759696
- validate-01-get-started
760697
- validate-02-agents
761698
- validate-02-agents-openai
762-
- validate-02-agents-azure-openai
763-
- validate-02-agents-azure-ai
764-
- validate-02-agents-azure-ai-agent
699+
- validate-02-agents-azure
765700
- validate-02-agents-anthropic
766701
- validate-02-agents-github-copilot
767702
- validate-02-agents-amazon
768703
- validate-02-agents-ollama
769-
- validate-02-agents-foundry-local
704+
- validate-02-agents-foundry
770705
- validate-02-agents-copilotstudio
771706
- validate-02-agents-custom
772707
- validate-03-workflows

python/samples/01-get-started/README.md

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,6 @@ concepts of **Agent Framework** one step at a time.
99
pip install agent-framework --pre
1010
```
1111

12-
Set the required environment variables:
13-
14-
```bash
15-
export AZURE_AI_PROJECT_ENDPOINT="https://your-project-endpoint"
16-
export AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME="gpt-4o" # optional, defaults to gpt-4o
17-
```
18-
1912
## Samples
2013

2114
| # | File | What you'll learn |

python/samples/02-agents/compaction/compaction_provider.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ async def log_model_input(context: ChatContext, call_next: Any) -> None:
7070

7171

7272
async def main() -> None:
73-
client = OpenAIChatClient(model_id="gpt-4o-mini")
73+
client = OpenAIChatClient(model="gpt-4o-mini")
7474

7575
# History provider loads/stores conversation messages in session.state.
7676
# skip_excluded=True means get_messages() will omit messages that were

python/samples/02-agents/context_providers/redis/redis_conversation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
from agent_framework.foundry import FoundryChatClient
2626
from agent_framework.redis import RedisContextProvider
2727
from azure.identity import AzureCliCredential
28+
from dotenv import load_dotenv
2829
from redisvl.extensions.cache.embeddings import EmbeddingsCache
2930
from redisvl.utils.vectorize import OpenAITextVectorizer
3031

31-
# Copyright (c) Microsoft. All rights reserved.
32-
32+
load_dotenv()
3333

3434
# Default Redis URL for local Redis Stack.
3535
# Override via the REDIS_URL environment variable for remote or authenticated instances.

python/samples/02-agents/typed_options.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import asyncio
44
from typing import Literal
55

6-
from agent_framework import Agent
6+
from agent_framework import Agent, Message
77
from agent_framework.anthropic import AnthropicClient
88
from agent_framework.foundry import FoundryChatClient
99
from agent_framework.openai import OpenAIChatClient, OpenAIChatOptions
@@ -40,11 +40,11 @@ async def demo_anthropic_chat_client() -> None:
4040
print("\n=== Anthropic ChatClient with TypedDict Options ===\n")
4141

4242
# Create Anthropic client
43-
client = AnthropicClient(model="claude-sonnet-4-5-20250929")
43+
client = AnthropicClient(model_id="claude-sonnet-4-5-20250929")
4444

4545
# Standard options work great:
4646
response = await client.get_response(
47-
"What is the capital of France?",
47+
[Message("user", text="What is the capital of France?")],
4848
options={
4949
"temperature": 0.5,
5050
"max_tokens": 1000,
@@ -62,7 +62,7 @@ async def demo_anthropic_agent() -> None:
6262
"""Demonstrate Agent with Anthropic client and typed options."""
6363
print("\n=== Agent with Anthropic and Typed Options ===\n")
6464

65-
client = AnthropicClient(model="claude-sonnet-4-5-20250929")
65+
client = AnthropicClient(model_id="claude-sonnet-4-5-20250929")
6666

6767
# Create a typed agent for Anthropic - IDE knows Anthropic-specific options!
6868
agent = Agent(
@@ -119,12 +119,12 @@ async def demo_openai_chat_client_reasoning_models() -> None:
119119
print("\n=== OpenAI ChatClient with TypedDict Options ===\n")
120120

121121
# Create OpenAI client
122-
client = OpenAIChatClient[OpenAIReasoningChatOptions](model_id="o3")
122+
client = OpenAIChatClient[OpenAIReasoningChatOptions](model="o3")
123123

124124
# With specific options, you get full IDE autocomplete!
125125
# Try typing `client.get_response("Hello", options={` and see the suggestions
126126
response = await client.get_response(
127-
"What is 2 + 2?",
127+
[Message("user", text="What is 2 + 2?")],
128128
options={
129129
"max_tokens": 100,
130130
"allow_multiple_tool_calls": True,

python/samples/03-workflows/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ Workflow and orchestration samples use `AzureOpenAIResponsesClient` rather than
172172

173173
Workflow samples that use `AzureOpenAIResponsesClient` expect:
174174

175-
- `AZURE_AI_PROJECT_ENDPOINT` (Azure AI Foundry Agent Service (V2) project endpoint)
176-
- `AZURE_AI_MODEL_DEPLOYMENT_NAME` (model deployment name)
175+
- `FOUNDRY_PROJECT_ENDPOINT` (Azure AI Foundry Agent Service (V2) project endpoint)
176+
- `FOUNDRY_MODEL` (model deployment name)
177177

178178
These values are passed directly into the client constructor via `os.getenv()` in sample code.

python/samples/03-workflows/_start-here/step2_agents_in_a_workflow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
Prerequisites:
2626
- FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint.
27-
- Azure OpenAI configured for FoundryChatClient with required environment variables.
27+
- FOUNDRY_MODEL must be the deployment name of a model in your Foundry project.
2828
- Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample.
2929
- Basic familiarity with WorkflowBuilder, edges, events, and streaming or non-streaming runs.
3030
"""
@@ -35,7 +35,7 @@ async def main():
3535
# Create the Azure chat client. AzureCliCredential uses your current az login.
3636
client = FoundryChatClient(
3737
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
38-
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
38+
model=os.environ["FOUNDRY_MODEL"],
3939
credential=AzureCliCredential(),
4040
)
4141
writer_agent = Agent(

python/samples/03-workflows/_start-here/step3_streaming.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
2424
Prerequisites:
2525
- FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint.
26-
- Azure OpenAI configured for FoundryChatClient with required environment variables.
26+
- FOUNDRY_MODEL must be the deployment name of a model in your Foundry project.
2727
- Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample.
2828
- Basic familiarity with WorkflowBuilder, executors, edges, events, and streaming runs.
2929
"""
@@ -34,7 +34,7 @@ async def main():
3434
# Create the Azure chat client. AzureCliCredential uses your current az login.
3535
client = FoundryChatClient(
3636
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
37-
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
37+
model=os.environ["FOUNDRY_MODEL"],
3838
credential=AzureCliCredential(),
3939
)
4040
writer_agent = Agent(

python/samples/03-workflows/agents/azure_ai_agents_streaming.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
1919
Prerequisites:
2020
- FOUNDRY_PROJECT_ENDPOINT must be your Azure AI Foundry Agent Service (V2) project endpoint.
21-
- AZURE_AI_MODEL_DEPLOYMENT_NAME must be set to your Azure OpenAI model deployment name.
21+
- FOUNDRY_MODEL must be the deployment name of a model in your Foundry project.
2222
- Authentication via azure-identity. Use AzureCliCredential and run az login before executing the sample.
2323
- Basic familiarity with WorkflowBuilder, edges, events, and streaming runs.
2424
"""
@@ -27,7 +27,7 @@
2727
async def main() -> None:
2828
client = FoundryChatClient(
2929
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
30-
model=os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"],
30+
model=os.environ["FOUNDRY_MODEL"],
3131
credential=AzureCliCredential(),
3232
)
3333

0 commit comments

Comments
 (0)