{"slug":"azure-ai-projects-py","title":"azure-ai-projects-py","summary":"Build AI applications using the Azure AI Projects Python SDK (azure-ai-projects). Use when working with Foundry project clients, creating versioned agents with PromptAgentDefinition, running evaluations, managing connections/deployments/datasets/indexes, or using OpenAI-compatibl","platform":"GitHub Copilot","tags":[],"authorName":"Ciza","authorSlug":"ciza","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-08-12T21:05:05.073271Z","repo":{"url":"https://github.com/microsoft/skills","stars":3052,"forks":351,"license":"MIT","updatedAt":"2026-09-24T16:38:17Z"},"bodyHtml":"<hr>\n<h2>name: azure-ai-projects-py\ndescription: Build AI applications using the Azure AI Projects Python SDK (azure-ai-projects). Use when working with Foundry project clients, creating versioned agents with PromptAgentDefinition, running evaluations, managing connections/deployments/datasets/indexes, or using OpenAI-compatible clients. This is the high-level Foundry SDK - for low-level agent operations, use azure-ai-agents-python skill.\nlicense: MIT\nmetadata:\nauthor: Microsoft\nversion: \"1.0.0\"\npackage: azure-ai-projects</h2>\n<h1>Azure AI Projects Python SDK (Foundry SDK)</h1>\n<p>Build AI applications on Microsoft Foundry using the <code>azure-ai-projects</code> SDK.</p>\n<h2>Installation</h2>\n<pre><code>pip install azure-ai-projects azure-identity\n</code></pre>\n<h2>Environment Variables</h2>\n<pre><code>AZURE_AI_PROJECT_ENDPOINT=\"https://&lt;resource&gt;.services.ai.azure.com/api/projects/&lt;project&gt;\"  # Required for all auth methods\nAZURE_AI_MODEL_DEPLOYMENT_NAME=\"gpt-4o-mini\"  # Required for all auth methods\nAZURE_TOKEN_CREDENTIALS=prod # Required only if DefaultAzureCredential is used in production\n</code></pre>\n<h2>Authentication &amp; Lifecycle</h2>\n<blockquote>\n<p><strong>\uD83D\uDD11 Two rules apply to every code sample below:</strong></p>\n<ol>\n<li><strong>Prefer <code>DefaultAzureCredential</code>.</strong> It works locally (Azure CLI / VS Code / Developer CLI) and in Azure (managed identity, workload identity) with no code change. Avoid connection strings, account/API keys — they bypass Entra audit and rotation.\n<ul>\n<li>Local dev: <code>DefaultAzureCredential</code> works as-is.</li>\n<li>Production: set <code>AZURE_TOKEN_CREDENTIALS=prod</code> (or <code>AZURE_TOKEN_CREDENTIALS=&lt;specific_credential&gt;</code>) to constrain the credential chain to production-safe credentials.</li>\n</ul>\n</li>\n<li><strong>Wrap every client in a context manager</strong> so HTTP transports, sockets, and token caches are released deterministically:\n<ul>\n<li>Sync: <code>with &lt;Client&gt;(...) as client:</code></li>\n<li>Async: <code>async with &lt;Client&gt;(...) as client:</code> <strong>and</strong> <code>async with DefaultAzureCredential() as credential:</code> (from <code>azure.identity.aio</code>)</li>\n</ul>\n</li>\n</ol>\n<p>Snippets may abbreviate this setup, but production code should always follow both rules.</p>\n</blockquote>\n<pre><code>import os\nfrom azure.identity import DefaultAzureCredential, ManagedIdentityCredential\nfrom azure.ai.projects import AIProjectClient\n\n# Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=&lt;specific_credential&gt;\ncredential = DefaultAzureCredential()\n# Or use a specific credential directly in production:\n# See https://learn.microsoft.com/python/api/overview/azure/identity-readme?view=azure-python#credential-classes\n# credential = ManagedIdentityCredential()\nwith AIProjectClient(\n    endpoint=os.environ[\"AZURE_AI_PROJECT_ENDPOINT\"],\n    credential=credential,\n) as client:\n    deployments = list(client.deployments.list())\n</code></pre>\n<h2>Client Operations Overview</h2>\n<table>\n<thead>\n<tr>\n<th>Operation</th>\n<th>Access</th>\n<th>Purpose</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>client.agents</code></td>\n<td><code>.agents.*</code></td>\n<td>Agent CRUD, versions, threads, runs</td>\n</tr>\n<tr>\n<td><code>client.connections</code></td>\n<td><code>.connections.*</code></td>\n<td>List/get project connections</td>\n</tr>\n<tr>\n<td><code>client.deployments</code></td>\n<td><code>.deployments.*</code></td>\n<td>List model deployments</td>\n</tr>\n<tr>\n<td><code>client.datasets</code></td>\n<td><code>.datasets.*</code></td>\n<td>Dataset management</td>\n</tr>\n<tr>\n<td><code>client.indexes</code></td>\n<td><code>.indexes.*</code></td>\n<td>Index management</td>\n</tr>\n<tr>\n<td><code>client.evaluations</code></td>\n<td><code>.evaluations.*</code></td>\n<td>Run evaluations</td>\n</tr>\n<tr>\n<td><code>client.red_teams</code></td>\n<td><code>.red_teams.*</code></td>\n<td>Red team operations</td>\n</tr>\n</tbody>\n</table>\n<h2>Two Client Approaches</h2>\n<h3>1. AIProjectClient (Native Foundry)</h3>\n<pre><code>from azure.ai.projects import AIProjectClient\n\nwith AIProjectClient(\n    endpoint=os.environ[\"AZURE_AI_PROJECT_ENDPOINT\"],\n    credential=DefaultAzureCredential(),\n) as client:\n    # Use Foundry-native operations\n    agent = client.agents.create_agent(\n        model=os.environ[\"AZURE_AI_MODEL_DEPLOYMENT_NAME\"],\n        name=\"my-agent\",\n        instructions=\"You are helpful.\",\n    )\n</code></pre>\n<h3>2. OpenAI-Compatible Client</h3>\n<pre><code># Get OpenAI-compatible client from project\nopenai_client = client.get_openai_client()\n\n# Use standard OpenAI API\nresponse = openai_client.chat.completions.create(\n    model=os.environ[\"AZURE_AI_MODEL_DEPLOYMENT_NAME\"],\n    messages=[{\"role\": \"user\", \"content\": \"Hello!\"}],\n)\n</code></pre>\n<h2>Agent Operations</h2>\n<h3>Create Agent (Basic)</h3>\n<pre><code>agent = client.agents.create_agent(\n    model=os.environ[\"AZURE_AI_MODEL_DEPLOYMENT_NAME\"],\n    name=\"my-agent\",\n    instructions=\"You are a helpful assistant.\",\n)\n</code></pre>\n<h3>Create Agent with Tools</h3>\n<pre><code>from azure.ai.agents.models import CodeInterpreterTool, FileSearchTool\n\nagent = client.agents.create_agent(\n    model=os.environ[\"AZURE_AI_MODEL_DEPLOYMENT_NAME\"],\n    name=\"tool-agent\",\n    instructions=\"You can execute code and search files.\",\n    tools=[CodeInterpreterTool(), FileSearchTool()],\n)\n</code></pre>\n<h3>Versioned Agents with PromptAgentDefinition</h3>\n<pre><code>from azure.ai.projects.models import PromptAgentDefinition\n\n# Create a versioned agent\nagent_version = client.agents.create_version(\n    agent_name=\"customer-support-agent\",\n    definition=PromptAgentDefinition(\n        model=os.environ[\"AZURE_AI_MODEL_DEPLOYMENT_NAME\"],\n        instructions=\"You are a customer support specialist.\",\n        tools=[],  # Add tools as needed\n    ),\n    version_label=\"v1.0\",\n)\n</code></pre>\n<p>See <a href=\"references/agents.md\">references/agents.md</a> for detailed agent patterns.</p>\n<h2>Tools Overview</h2>\n<table>\n<thead>\n<tr>\n<th>Tool</th>\n<th>Class</th>\n<th>Use Case</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Code Interpreter</td>\n<td><code>CodeInterpreterTool</code></td>\n<td>Execute Python, generate files</td>\n</tr>\n<tr>\n<td>File Search</td>\n<td><code>FileSearchTool</code></td>\n<td>RAG over uploaded documents</td>\n</tr>\n<tr>\n<td>Bing Grounding</td>\n<td><code>BingGroundingTool</code></td>\n<td>Web search (requires connection)</td>\n</tr>\n<tr>\n<td>Azure AI Search</td>\n<td><code>AzureAISearchTool</code></td>\n<td>Search your indexes</td>\n</tr>\n<tr>\n<td>Function Calling</td>\n<td><code>FunctionTool</code></td>\n<td>Call your Python functions</td>\n</tr>\n<tr>\n<td>OpenAPI</td>\n<td><code>OpenApiTool</code></td>\n<td>Call REST APIs</td>\n</tr>\n<tr>\n<td>MCP</td>\n<td><code>McpTool</code></td>\n<td>Model Context Protocol servers</td>\n</tr>\n<tr>\n<td>Memory Search</td>\n<td><code>MemorySearchTool</code></td>\n<td>Search agent memory stores</td>\n</tr>\n<tr>\n<td>SharePoint</td>\n<td><code>SharepointGroundingTool</code></td>\n<td>Search SharePoint content</td>\n</tr>\n</tbody>\n</table>\n<p>See <a href=\"references/tools.md\">references/tools.md</a> for all tool patterns.</p>\n<h2>Thread and Message Flow</h2>\n<pre><code># 1. Create thread\nthread = client.agents.threads.create()\n\n# 2. Add message\nclient.agents.messages.create(\n    thread_id=thread.id,\n    role=\"user\",\n    content=\"What's the weather like?\",\n)\n\n# 3. Create and process run\nrun = client.agents.runs.create_and_process(\n    thread_id=thread.id,\n    agent_id=agent.id,\n)\n\n# 4. Get response\nif run.status == \"completed\":\n    messages = client.agents.messages.list(thread_id=thread.id)\n    for msg in messages:\n        if msg.role == \"assistant\":\n            print(msg.content[0].text.value)\n</code></pre>\n<h2>Connections</h2>\n<pre><code># List all connections\nconnections = client.connections.list()\nfor conn in connections:\n    print(f\"{conn.name}: {conn.connection_type}\")\n\n# Get specific connection\nconnection = client.connections.get(connection_name=\"my-search-connection\")\n</code></pre>\n<p>See <a href=\"references/connections.md\">references/connections.md</a> for connection patterns.</p>\n<h2>Deployments</h2>\n<pre><code># List available model deployments\ndeployments = client.deployments.list()\nfor deployment in deployments:\n    print(f\"{deployment.name}: {deployment.model}\")\n</code></pre>\n<p>See <a href=\"references/deployments.md\">references/deployments.md</a> for deployment patterns.</p>\n<h2>Datasets and Indexes</h2>\n<pre><code># List datasets\ndatasets = client.datasets.list()\n\n# List indexes\nindexes = client.indexes.list()\n</code></pre>\n<p>See <a href=\"references/datasets-indexes.md\">references/datasets-indexes.md</a> for data operations.</p>\n<h2>Evaluation</h2>\n<pre><code># Using OpenAI client for evals\nopenai_client = client.get_openai_client()\n\n# Create evaluation with built-in evaluators\neval_run = openai_client.evals.runs.create(\n    eval_id=\"my-eval\",\n    name=\"quality-check\",\n    data_source={\n        \"type\": \"custom\",\n        \"item_references\": [{\"item_id\": \"test-1\"}],\n    },\n    testing_criteria=[\n        {\"type\": \"fluency\"},\n        {\"type\": \"task_adherence\"},\n    ],\n)\n</code></pre>\n<p>See <a href=\"references/evaluation.md\">references/evaluation.md</a> for evaluation patterns.</p>\n<h2>Async Client</h2>\n<pre><code>from azure.ai.projects.aio import AIProjectClient\n\nasync with AIProjectClient(\n    endpoint=os.environ[\"AZURE_AI_PROJECT_ENDPOINT\"],\n    credential=DefaultAzureCredential(),\n) as client:\n    agent = await client.agents.create_agent(...)\n    # ... async operations\n</code></pre>\n<p>See <a href=\"references/async-patterns.md\">references/async-patterns.md</a> for async patterns.</p>\n<h2>Memory Stores</h2>\n<pre><code># Create memory store for agent\nmemory_store = client.agents.create_memory_store(\n    name=\"conversation-memory\",\n)\n\n# Attach to agent for persistent memory\nagent = client.agents.create_agent(\n    model=os.environ[\"AZURE_AI_MODEL_DEPLOYMENT_NAME\"],\n    name=\"memory-agent\",\n    tools=[MemorySearchTool()],\n    tool_resources={\"memory\": {\"store_ids\": [memory_store.id]}},\n)\n</code></pre>\n<h2>Best Practices</h2>\n<ol>\n<li><strong>Pick sync OR async and stay consistent.</strong> Do not mix <code>azure.ai.projects</code> sync clients with <code>azure.ai.projects.aio</code> async clients in the same call path. Choose one mode per module.</li>\n<li><strong>Always use context managers for clients and async credentials.</strong> Wrap every client in <code>with AIProjectClient(...) as client:</code> (sync) or <code>async with AIProjectClient(...) as client:</code> (async). For async <code>DefaultAzureCredential</code> from <code>azure.identity.aio</code>, also use <code>async with credential:</code> so tokens and transports are cleaned up.</li>\n<li><strong>Clean up agents</strong> when done: <code>client.agents.delete_agent(agent.id)</code></li>\n<li><strong>Use <code>create_and_process</code></strong> for simple runs, <strong>streaming</strong> for real-time UX</li>\n<li><strong>Use versioned agents</strong> for production deployments</li>\n<li><strong>Prefer connections</strong> for external service integration (AI Search, Bing, etc.)</li>\n</ol>\n<h2>SDK Comparison</h2>\n<table>\n<thead>\n<tr>\n<th>Feature</th>\n<th><code>azure-ai-projects</code></th>\n<th><code>azure-ai-agents</code></th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td>Level</td>\n<td>High-level (Foundry)</td>\n<td>Low-level (Agents)</td>\n</tr>\n<tr>\n<td>Client</td>\n<td><code>AIProjectClient</code></td>\n<td><code>AgentsClient</code></td>\n</tr>\n<tr>\n<td>Versioning</td>\n<td><code>create_version()</code></td>\n<td>Not available</td>\n</tr>\n<tr>\n<td>Connections</td>\n<td>Yes</td>\n<td>No</td>\n</tr>\n<tr>\n<td>Deployments</td>\n<td>Yes</td>\n<td>No</td>\n</tr>\n<tr>\n<td>Datasets/Indexes</td>\n<td>Yes</td>\n<td>No</td>\n</tr>\n<tr>\n<td>Evaluation</td>\n<td>Via OpenAI client</td>\n<td>No</td>\n</tr>\n<tr>\n<td>When to use</td>\n<td>Full Foundry integration</td>\n<td>Standalone agent apps</td>\n</tr>\n</tbody>\n</table>\n<h2>Reference Files</h2>\n<ul>\n<li><a href=\"references/agents.md\">references/agents.md</a>: Agent operations with PromptAgentDefinition</li>\n<li><a href=\"references/tools.md\">references/tools.md</a>: All agent tools with examples</li>\n<li><a href=\"references/evaluation.md\">references/evaluation.md</a>: Evaluation operations overview</li>\n<li><a href=\"references/built-in-evaluators.md\">references/built-in-evaluators.md</a>: Complete built-in evaluator reference</li>\n<li><a href=\"references/custom-evaluators.md\">references/custom-evaluators.md</a>: Code and prompt-based evaluator patterns</li>\n<li><a href=\"references/connections.md\">references/connections.md</a>: Connection operations</li>\n<li><a href=\"references/deployments.md\">references/deployments.md</a>: Deployment enumeration</li>\n<li><a href=\"references/datasets-indexes.md\">references/datasets-indexes.md</a>: Dataset and index operations</li>\n<li><a href=\"references/async-patterns.md\">references/async-patterns.md</a>: Async client usage</li>\n<li><a href=\"references/api-reference.md\">references/api-reference.md</a>: Complete API reference for all 373 SDK exports (v2.0.0b4)</li>\n<li><a href=\"scripts/run_batch_evaluation.py\">scripts/run_batch_evaluation.py</a>: CLI tool for batch evaluations</li>\n</ul>\n","files":[{"path":"references/agents.md","sizeBytes":6869,"isText":true},{"path":"references/api-reference.md","sizeBytes":27988,"isText":true},{"path":"references/async-patterns.md","sizeBytes":7009,"isText":true},{"path":"references/built-in-evaluators.md","sizeBytes":11759,"isText":true},{"path":"references/connections.md","sizeBytes":4767,"isText":true},{"path":"references/custom-evaluators.md","sizeBytes":14411,"isText":true},{"path":"references/datasets-indexes.md","sizeBytes":4272,"isText":true},{"path":"references/deployments.md","sizeBytes":3569,"isText":true},{"path":"references/evaluation.md","sizeBytes":10975,"isText":true},{"path":"references/tools.md","sizeBytes":12016,"isText":true},{"path":"scripts/run_batch_evaluation.py","sizeBytes":12507,"isText":true},{"path":"SKILL.md","sizeBytes":11058,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-08-12T21:49:43.689265Z","sha256":"D5504FF8116A4CB0F9A06998A82A4953FD4298056691BAFB56C4AE4084C82BD8","sizeBytes":35773},"review":null,"source":{"repositoryUrl":"https://github.com/microsoft/skills","path":".github/plugins/azure-sdk-python/skills/azure-ai-projects-py","license":"MIT","commit":"23d0dac5f83f268166a17f0bc7dc6c73dc348a33","subtreeSha":"127ABA26D3A0796A4AB552D9C90468D78E433119F249EBF3E558733D7D1EF360","lastSyncedAt":"2026-09-25T06:48:53.330584Z"},"reviewedAt":"2026-08-12T21:51:41.895233Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-python/skills/azure-ai-projects-py"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install microsoft-skills@llmmart"},{"target":"git","command":"git clone https://github.com/microsoft/skills.git"}]}