Files
agent-framework/python/samples/getting_started/agents/azure_ai
T

Azure AI Agent Examples

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

Examples

File Description
azure_ai_basic.py The simplest way to create an agent using AzureAIClient. Demonstrates both streaming and non-streaming responses with function tools. Shows automatic agent creation and basic weather functionality.
azure_ai_use_latest_version.py Demonstrates how to reuse the latest version of an existing agent instead of creating a new agent version on each instantiation using the use_latest_version=True parameter.
azure_ai_with_code_interpreter.py Shows how to use the HostedCodeInterpreterTool with Azure AI agents to write and execute Python code for mathematical problem solving and data analysis.
azure_ai_with_existing_agent.py Shows how to work with a pre-existing agent by providing the agent name and version to the Azure AI client. Demonstrates agent reuse patterns for production scenarios.
azure_ai_with_existing_conversation.py Shows how to work with a pre-existing conversation by providing the conversation ID to continue existing chat sessions.
azure_ai_with_explicit_settings.py Shows how to create an agent with explicitly configured AzureAIClient settings, including project endpoint, model deployment, and credentials rather than relying on environment variable defaults.
azure_ai_with_hosted_mcp.py Shows how to integrate hosted Model Context Protocol (MCP) tools with Azure AI Agent.
azure_ai_with_response_format.py Shows how to use structured outputs (response format) with Azure AI agents using Pydantic models to enforce specific response schemas.
azure_ai_with_thread.py Demonstrates thread management with Azure AI agents, including automatic thread creation for stateless conversations and explicit thread management for maintaining conversation context across multiple interactions.

Environment Variables

Before running the examples, you need to set up your environment variables. You can do this in one of two ways:

  1. Copy the .env.example file from the python directory to create a .env file:

    cp ../../../../.env.example ../../../../.env
    
  2. Edit the .env file and add your values:

    AZURE_AI_PROJECT_ENDPOINT="your-project-endpoint"
    AZURE_AI_MODEL_DEPLOYMENT_NAME="your-model-deployment-name"
    

Option 2: Using environment variables directly

Set the environment variables in your shell:

export AZURE_AI_PROJECT_ENDPOINT="your-project-endpoint"
export AZURE_AI_MODEL_DEPLOYMENT_NAME="your-model-deployment-name"

Required Variables

  • AZURE_AI_PROJECT_ENDPOINT: Your Azure AI project endpoint (required for all examples)
  • AZURE_AI_MODEL_DEPLOYMENT_NAME: The name of your model deployment (required for all examples)

Authentication

All examples use AzureCliCredential for authentication by default. Before running the examples:

  1. Install the Azure CLI
  2. Run az login to authenticate with your Azure account
  3. Ensure you have appropriate permissions to the Azure AI project

Alternatively, you can replace AzureCliCredential with other authentication options like DefaultAzureCredential or environment-based credentials.

Running the Examples

Each example can be run independently. Navigate to this directory and run any example:

python azure_ai_basic.py
python azure_ai_with_code_interpreter.py
# ... etc

The examples demonstrate various patterns for working with Azure AI agents, from basic usage to advanced scenarios like thread management and structured outputs.