Azure AI Agents Client Library

1.1.0 · active · verified Thu Apr 09

The Azure AI Agents Client Library for Python provides tools for building AI agents that can interact with users and other services on the Azure platform. It allows developers to create, configure, and manage conversational AI experiences. The current version is 1.1.0, and it follows the Azure SDK release cadence, with frequent beta updates and less frequent, but regular, stable releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the `AgentClient` using an API key and send a basic chat message. It expects the `AZURE_AGENT_ENDPOINT` and `AZURE_AGENT_API_KEY` environment variables to be set for authentication. For more advanced scenarios, including agent creation, thread management, and different authentication methods like `DefaultAzureCredential`, consult the official Azure AI Agents documentation.

import os
from azure.ai.agents import AgentClient
from azure.core.credentials import AzureKeyCredential

# Set your Azure AI Agent endpoint and API key as environment variables
# AZURE_AGENT_ENDPOINT='https://<your-agent-resource-name>.openai.azure.com'
# AZURE_AGENT_API_KEY='your-api-key'

endpoint = os.environ.get("AZURE_AGENT_ENDPOINT", "")
api_key = os.environ.get("AZURE_AGENT_API_KEY", "")

if not endpoint or not api_key:
    print("Please set AZURE_AGENT_ENDPOINT and AZURE_AGENT_API_KEY environment variables.")
else:
    try:
        client = AgentClient(endpoint=endpoint, credential=AzureKeyCredential(api_key))

        # Example: Create an agent (if not already created)
        # For a full agent creation example, refer to official documentation.
        # This quickstart assumes a basic interaction.

        # Example: Chat with an existing agent or start a new conversation
        # Note: 'context' with 'thread_id' might be required depending on your agent setup.
        # This example uses a simplified chat without explicit thread_id for brevity, 
        # but in real applications, manage thread_ids for conversational continuity.
        chat_response = client.chat(
            input="Hello, what can you do?",
            context={}
        )

        print(f"Agent Output: {chat_response.output}")

    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →