All skills
microsoft avatar

/azure-ai-projects-py

@4a2873f
by microsoftmicrosoft/skills3.1k stars
351

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.

Use this Skill: https://skilld.dev/gh/microsoft/skills/azure-ai-projects-py

This session only. Nothing lands on disk.

referencesconnections.md

≈1.2k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Connections Operations Reference

Overview

Connections provide access to external Azure services like Azure OpenAI, Azure AI Search, Bing, and more.

List Connections

List All Connections

connections = project_client.connections.list()
for conn in connections:
    print(f"Name: {conn.name}")
    print(f"Type: {conn.connection_type}")
    print(f"ID: {conn.id}")
    print("---")

Filter by Connection Type

from azure.ai.projects.models import ConnectionType

# List Azure OpenAI connections
for conn in project_client.connections.list(
    connection_type=ConnectionType.AZURE_OPEN_AI
):
    print(f"Azure OpenAI: {conn.name}")

# List Azure AI Search connections
for conn in project_client.connections.list(
    connection_type=ConnectionType.AZURE_AI_SEARCH
):
    print(f"AI Search: {conn.name}")

Connection Types

from azure.ai.projects.models import ConnectionType

# Available connection types:
# - ConnectionType.AZURE_OPEN_AI
# - ConnectionType.AZURE_AI_SEARCH
# - ConnectionType.AZURE_BLOB
# - ConnectionType.AZURE_AI_SERVICES
# - ConnectionType.API_KEY
# - ConnectionType.COGNITIVE_SEARCH
# - ConnectionType.COGNITIVE_SERVICE
# - ConnectionType.CUSTOM

Get Connection

Get by Name

connection = project_client.connections.get(connection_name="my-search-connection")
print(f"Name: {connection.name}")
print(f"Type: {connection.connection_type}")

Get with Credentials

connection = project_client.connections.get(
    connection_name="my-search-connection",
    include_credentials=True,
)
print(f"Endpoint: {connection.endpoint_url}")
# Access credentials based on connection type

Get Default Connection

from azure.ai.projects.models import ConnectionType

# Get default Azure OpenAI connection
default_aoai = project_client.connections.get_default(
    connection_type=ConnectionType.AZURE_OPEN_AI
)
print(f"Default Azure OpenAI: {default_aoai.name}")

# Get with credentials
default_aoai = project_client.connections.get_default(
    connection_type=ConnectionType.AZURE_OPEN_AI,
    include_credentials=True,
)

Using Connections with Tools

Bing Grounding

from azure.ai.projects.models import (
    BingGroundingAgentTool,
    BingGroundingSearchToolParameters,
    BingGroundingSearchConfiguration,
)

# Get Bing connection
bing_connection = project_client.connections.get(
    os.environ["BING_CONNECTION_NAME"]
)

# Use in agent
tools = [
    BingGroundingAgentTool(
        bing_grounding=BingGroundingSearchToolParameters(
            search_configurations=[
                BingGroundingSearchConfiguration(
                    project_connection_id=bing_connection.id
                )
            ]
        )
    )
]

Azure AI Search

from azure.ai.projects.models import (
    AzureAISearchAgentTool,
    AzureAISearchToolResource,
    AISearchIndexResource,
    AzureAISearchQueryType,
)

# Get search connection
search_connection = project_client.connections.get(
    os.environ["AI_SEARCH_CONNECTION_NAME"]
)

# Use in agent
tools = [
    AzureAISearchAgentTool(
        azure_ai_search=AzureAISearchToolResource(
            indexes=[
                AISearchIndexResource(
                    project_connection_id=search_connection.id,
                    index_name="my-index",
                    query_type=AzureAISearchQueryType.SEMANTIC,
                )
            ]
        )
    )
]

OpenAI Client from Connection

# Get OpenAI client for a specific Azure OpenAI connection
openai_client = project_client.get_openai_client(
    api_version="2024-10-21",
    connection_name="my-aoai-connection",
)

response = openai_client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
)

Connection Properties

connection = project_client.connections.get(
    connection_name="my-connection",
    include_credentials=True,
)

# Common properties
print(f"ID: {connection.id}")
print(f"Name: {connection.name}")
print(f"Type: {connection.connection_type}")
print(f"Endpoint: {connection.endpoint_url}")

# Check authentication type
if hasattr(connection, 'authentication_type'):
    print(f"Auth Type: {connection.authentication_type}")

Environment Variables Pattern

# Recommended environment variables for connections
BING_CONNECTION_NAME=my-bing-connection
AI_SEARCH_CONNECTION_NAME=my-search-connection
AOAI_CONNECTION_NAME=my-aoai-connection
import os

# Load connections from environment
bing_conn = project_client.connections.get(os.environ["BING_CONNECTION_NAME"])
search_conn = project_client.connections.get(os.environ["AI_SEARCH_CONNECTION_NAME"])

Source: SKILL.md on GitHub

1 warning16d4 checks · Risk SAFE
  • Gen Agent Trust Hub16d

    This skill provides a comprehensive set of examples, reference implementations, and utility scripts for developing applications using the Azure AI Projects Python SDK. The code follows secure practices, such as prioritizing Entra ID token-based authentication (`DefaultAzureCredential`) over raw API keys, and managing credentials securely via standard environment configurations.

  • Socket16d

    No alerts

  • Snyk16d

    Risk: LOW · No issues

  • Runlayer7mo

    13/13 files flagged

Signed by skilld at 4a2873f. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 20 hours ago.

Activeupdated 2 months ago
Other metadata
metadata
{
  "author": "Microsoft",
  "version": "1.0.0",
  "package": "azure-ai-projects"
}

README badge

README badge for microsoft/skills/azure-ai-projects-py