Files
agent-framework/python/samples/getting_started/agents/azure_ai
T
Farzad Sunavala 04e711cd55 Python: Feature/azure ai search agentic rag (search as separate package) (#2328)
* Python: Fix pyright errors and move search provider to core (#1546)

* address pablo coments

* update azure ai search pypi version to latest prev

* init update

* Fix MyPy type annotation errors in search provider

- Add type annotation to DEFAULT_CONTEXT_PROMPT
- Add type annotation to vectorizable_fields
- Add union type annotation to vector_queries

* Fix DEFAULT_CONTEXT_PROMPT MyPy error and update test

- Rename DEFAULT_CONTEXT_PROMPT to _DEFAULT_SEARCH_CONTEXT_PROMPT to avoid conflict with base class Final variable
- Update test to use new constant name
- All core package tests passing (1123 passed)

* Python: Move Azure AI Search to separate package per PR feedback

Addresses reviewer feedback from PR #1546 by isolating the beta dependency
(azure-search-documents==11.7.0b2) into a new agent-framework-aisearch package.

Changes:
- Created new agent-framework-aisearch package with complete structure
- Moved AzureAISearchContextProvider from core to aisearch package
- Added AzureAISearchSettings class for environment variable auto-loading
- Added support for direct API key string (auto-converts to AzureKeyCredential)
- Added azure_openai_api_key parameter for Knowledge Base authentication
- Updated embedding_function type to Callable[[str], Awaitable[list[float]]]
- Moved Role import to top-level imports
- Maintained lazy loading through agent_framework.azure module
- Removed beta dependency from core package
- Updated all tests to use new package location
- All quality checks pass: ruff format/lint, pyright, mypy (0 errors)
- All 21 unit tests pass with 59% coverage

Semantic search mode verified working with both API key and managed identity authentication.

๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Python: Clarify top_k parameter only applies to semantic mode

Updated documentation to clarify that the top_k parameter only affects
semantic search mode. In agentic mode, the server-side Knowledge Base
determines retrieval based on query complexity and reasoning effort.

๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* Python: Add Knowledge Base output mode and retrieval reasoning effort parameters

Added support for configurable Knowledge Base behavior in agentic mode:

- knowledge_base_output_mode: "extractive_data" (default) or "answer_synthesis"
  Some knowledge sources require answer_synthesis mode for proper functionality.

- retrieval_reasoning_effort: "minimal" (default), "medium", or "low"
  Controls query planning complexity and multi-hop reasoning depth.

These parameters give users fine-grained control over Knowledge Base behavior
and enable support for knowledge sources that require answer synthesis.

๐Ÿค– Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

* effort and outputmode query params

* Address PR review feedback for Azure AI Search context provider

* comments eduward

* ed latest comments

---------

Co-authored-by: Farzad Sunavala <farzad.sunavala.enovate.ai>
Co-authored-by: farzad528 <farzad528@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
04e711cd55 ยท 2025-11-20 22:34:46 +00:00
History
..

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. These examples use the AzureAIClient with the azure-ai-projects 2.x (V2) API surface (see changelog). For V1 (azure-ai-agents 1.x) samples using AzureAIAgentClient, see the Azure AI V1 examples folder.

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_agent_to_agent.py Shows how to use Agent-to-Agent (A2A) capabilities with Azure AI agents to enable communication with other agents using the A2A protocol. Requires an A2A connection configured in your Azure AI project.
azure_ai_with_azure_ai_search.py Shows how to use Azure AI Search with Azure AI agents to search through indexed data and answer user questions with proper citations. Requires an Azure AI Search connection and index configured in your Azure AI project.
azure_ai_with_bing_grounding.py Shows how to use Bing Grounding search with Azure AI agents to search the web for current information and provide grounded responses with citations. Requires a Bing connection configured in your Azure AI project.
azure_ai_with_bing_custom_search.py Shows how to use Bing Custom Search with Azure AI agents to search custom search instances and provide responses with relevant results. Requires a Bing Custom Search connection and instance configured in your Azure AI project.
azure_ai_with_browser_automation.py Shows how to use Browser Automation with Azure AI agents to perform automated web browsing tasks and provide responses based on web interactions. Requires a Browser Automation connection configured in your Azure AI project.
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 Demonstrates how to use an existing conversation created on the service side with Azure AI agents. Shows two approaches: specifying conversation ID at the client level and using AgentThread with an existing conversation ID.
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_file_search.py Shows how to use the HostedFileSearchTool with Azure AI agents to upload files, create vector stores, and enable agents to search through uploaded documents to answer user questions.
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_search_context_agentic.py Shows how to use AzureAISearchContextProvider with agentic mode. Uses Knowledge Bases for multi-hop reasoning across documents with query planning. Recommended for most scenarios - slightly slower with more token consumption for query planning, but more accurate results.
azure_ai_with_search_context_semantic.py Shows how to use AzureAISearchContextProvider with semantic mode. Fast hybrid search with vector + keyword search and semantic ranking for RAG. Best for simple queries where speed is critical.
azure_ai_with_sharepoint.py Shows how to use SharePoint grounding with Azure AI agents to search through SharePoint content and answer user questions with proper citations. Requires a SharePoint connection configured in your Azure AI project.
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.
azure_ai_with_image_generation.py Shows how to use the ImageGenTool with Azure AI agents to generate images based on text prompts.
azure_ai_with_microsoft_fabric.py Shows how to use Microsoft Fabric with Azure AI agents to query Fabric data sources and provide responses based on data analysis. Requires a Microsoft Fabric connection configured in your Azure AI project.
azure_ai_with_web_search.py Shows how to use the HostedWebSearchTool with Azure AI agents to perform web searches and retrieve up-to-date information from the internet.

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.