Files
agent-framework/python/samples/02-agents/providers/azure_openai
T
Eduard van Valkenburg cc98d5b6f7 Python: [BREAKING] Scope provider state by source_id and standardize source IDs (#3995)
* Initial plan

* Add FoundryMemoryProvider and tests

Co-authored-by: eavanvalkenburg <13749212+eavanvalkenburg@users.noreply.github.com>

* Add sample and documentation for FoundryMemoryProvider

Co-authored-by: eavanvalkenburg <13749212+eavanvalkenburg@users.noreply.github.com>

* Address code review feedback for FoundryMemoryProvider

Co-authored-by: eavanvalkenburg <13749212+eavanvalkenburg@users.noreply.github.com>

* Address PR review comments: Add DEFAULT_SOURCE_ID, use logging.getLogger, move state to session.state

Co-authored-by: eavanvalkenburg <13749212+eavanvalkenburg@users.noreply.github.com>

* Fix Foundry memory ItemParam usage and exports

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Refactor provider hook state and standardize source IDs

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Support endpoint-based Foundry memory init

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Fix core README workflows link

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* updated implementation and sample

* Split out Foundry memory provider changes

Remove FoundryMemoryProvider implementation/tests/sample plus export and docs mentions from this branch so only non-Foundry changes remain.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

* Trigger CI rerun for PR #3995

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: eavanvalkenburg <13749212+eavanvalkenburg@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
cc98d5b6f7 · 2026-02-17 19:12:28 +00:00
History
..

Azure OpenAI Agent Examples

This folder contains examples demonstrating different ways to create and use agents with the different Azure OpenAI chat client from the agent_framework.azure package.

Examples

File Description
azure_assistants_basic.py The simplest way to create an agent using Agent with AzureOpenAIAssistantsClient. Shows both streaming and non-streaming responses with automatic assistant creation and cleanup.
azure_assistants_with_code_interpreter.py Shows how to use AzureOpenAIAssistantsClient.get_code_interpreter_tool() with Azure agents to write and execute Python code. Includes helper methods for accessing code interpreter data from response chunks.
azure_assistants_with_existing_assistant.py Shows how to work with a pre-existing assistant by providing the assistant ID to the Azure Assistants client. Demonstrates proper cleanup of manually created assistants.
azure_assistants_with_explicit_settings.py Shows how to initialize an agent with a specific assistants client, configuring settings explicitly including endpoint and deployment name.
azure_assistants_with_function_tools.py Demonstrates how to use function tools with agents. Shows both agent-level tools (defined when creating the agent) and query-level tools (provided with specific queries).
azure_assistants_with_session.py Demonstrates session management with Azure agents, including automatic session creation for stateless conversations and explicit session management for maintaining conversation context across multiple interactions.
azure_chat_client_basic.py The simplest way to create an agent using Agent with AzureOpenAIChatClient. Shows both streaming and non-streaming responses for chat-based interactions with Azure OpenAI models.
azure_chat_client_with_explicit_settings.py Shows how to initialize an agent with a specific chat client, configuring settings explicitly including endpoint and deployment name.
azure_chat_client_with_function_tools.py Demonstrates how to use function tools with agents. Shows both agent-level tools (defined when creating the agent) and query-level tools (provided with specific queries).
azure_chat_client_with_session.py Demonstrates session management with Azure agents, including automatic session creation for stateless conversations and explicit session management for maintaining conversation context across multiple interactions.
azure_responses_client_basic.py The simplest way to create an agent using Agent with AzureOpenAIResponsesClient. Shows both streaming and non-streaming responses for structured response generation with Azure OpenAI models.
azure_responses_client_code_interpreter_files.py Demonstrates using AzureOpenAIResponsesClient.get_code_interpreter_tool() with file uploads for data analysis. Shows how to create, upload, and analyze CSV files using Python code execution with Azure OpenAI Responses.
azure_responses_client_image_analysis.py Shows how to use Azure OpenAI Responses for image analysis and vision tasks. Demonstrates multi-modal messages combining text and image content using remote URLs.
azure_responses_client_with_code_interpreter.py Shows how to use AzureOpenAIResponsesClient.get_code_interpreter_tool() with Azure agents to write and execute Python code. Includes helper methods for accessing code interpreter data from response chunks.
azure_responses_client_with_explicit_settings.py Shows how to initialize an agent with a specific responses client, configuring settings explicitly including endpoint and deployment name.
azure_responses_client_with_file_search.py Demonstrates using AzureOpenAIResponsesClient.get_file_search_tool() with Azure OpenAI Responses Client for direct document-based question answering and information retrieval from vector stores.
azure_responses_client_with_foundry.py Shows how to create an agent using an Azure AI Foundry project endpoint instead of a direct Azure OpenAI endpoint. Requires the azure-ai-projects package.
azure_responses_client_with_function_tools.py Demonstrates how to use function tools with agents. Shows both agent-level tools (defined when creating the agent) and query-level tools (provided with specific queries).
azure_responses_client_with_hosted_mcp.py Shows how to integrate Azure OpenAI Responses Client with hosted Model Context Protocol (MCP) servers using AzureOpenAIResponsesClient.get_mcp_tool() for extended functionality.
azure_responses_client_with_local_mcp.py Shows how to integrate Azure OpenAI Responses Client with local Model Context Protocol (MCP) servers using MCPStreamableHTTPTool for extended functionality.
azure_responses_client_with_session.py Demonstrates session management with Azure agents, including automatic session creation for stateless conversations and explicit session management for maintaining conversation context across multiple interactions.

Environment Variables

Make sure to set the following environment variables before running the examples:

  • AZURE_OPENAI_ENDPOINT: Your Azure OpenAI endpoint
  • AZURE_OPENAI_CHAT_DEPLOYMENT_NAME: The name of your Azure OpenAI chat model deployment
  • AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME: The name of your Azure OpenAI Responses deployment

For the Foundry project sample (azure_responses_client_with_foundry.py), also set:

  • AZURE_AI_PROJECT_ENDPOINT: Your Azure AI Foundry project endpoint

Optionally, you can set:

  • AZURE_OPENAI_API_VERSION: The API version to use (default is 2024-02-15-preview)
  • AZURE_OPENAI_API_KEY: Your Azure OpenAI API key (if not using AzureCliCredential)
  • AZURE_OPENAI_BASE_URL: Your Azure OpenAI base URL (if different from the endpoint)

Authentication

All examples use AzureCliCredential for authentication. Run az login in your terminal before running the examples, or replace AzureCliCredential with your preferred authentication method.

Required role-based access control (RBAC) roles

To access the Azure OpenAI API, your Azure account or service principal needs one of the following RBAC roles assigned to the Azure OpenAI resource:

  • Cognitive Services OpenAI User: Provides read access to Azure OpenAI resources and the ability to call the inference APIs. This is the minimum role required for running these examples.
  • Cognitive Services OpenAI Contributor: Provides full access to Azure OpenAI resources, including the ability to create, update, and delete deployments and models.

For most scenarios, the Cognitive Services OpenAI User role is sufficient. You can assign this role through the Azure portal under the Azure OpenAI resource's "Access control (IAM)" section.

For more detailed information about Azure OpenAI RBAC roles, see: Role-based access control for Azure OpenAI Service