From 5f68216863daac2375674ba3314f237d9e65be4a Mon Sep 17 00:00:00 2001 From: Tao Chen Date: Wed, 25 Mar 2026 11:00:17 -0700 Subject: [PATCH] First samples 1st batch --- .github/actions/sample-validation-setup/action.yml | 2 +- .github/workflows/python-sample-validation.yml | 10 ++++++++-- python/samples/01-get-started/README.md | 7 ------- .../02-agents/compaction/compaction_provider.py | 2 +- .../context_providers/redis/redis_conversation.py | 4 ++-- python/samples/02-agents/providers/openai/README.md | 3 +-- python/samples/02-agents/typed_options.py | 12 ++++++------ python/samples/README.md | 8 ++++---- 8 files changed, 23 insertions(+), 25 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..61715b76c9 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 @@ -207,7 +213,7 @@ jobs: 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 }} + AZURE_AI_EMBEDDING_MODEL_DEPLOYMENT_NAME: ${{ vars.AZURE_OPENAI_EMBEDDING_DEPLOYMENT_NAME }} BING_CONNECTION_ID: ${{ secrets.BING_CONNECTION_ID }} defaults: run: 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/providers/openai/README.md b/python/samples/02-agents/providers/openai/README.md index 20e757d421..f9ffce4561 100644 --- a/python/samples/02-agents/providers/openai/README.md +++ b/python/samples/02-agents/providers/openai/README.md @@ -45,8 +45,7 @@ This folder contains examples demonstrating different ways to create and use age Make sure to set the following environment variables before running the examples: - `OPENAI_API_KEY`: Your OpenAI API key -- `OPENAI_CHAT_MODEL_ID`: The OpenAI model to use (e.g., `gpt-4o`, `gpt-4o-mini`, `gpt-3.5-turbo`) -- `OPENAI_RESPONSES_MODEL_ID`: The OpenAI model to use (e.g., `gpt-4o`, `gpt-4o-mini`, `gpt-3.5-turbo`) +- `OPENAI_MODEL`: The OpenAI model to use (e.g., `gpt-4o`, `gpt-4o-mini`, `gpt-3.5-turbo`) - For image processing examples, use a vision-capable model like `gpt-4o` or `gpt-4o-mini` Optionally, you can set: 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/README.md b/python/samples/README.md index fa091b78bc..083be479fb 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): @@ -63,8 +63,8 @@ This allows different clients to use different configuration files if needed. 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.