Microsoft Agent Framework

1.0.1 · active · verified Wed Apr 15

Microsoft Agent Framework is a comprehensive Python library for building, orchestrating, and deploying AI agents and multi-agent workflows. It provides core abstractions, implementations, and integrations with various LLM providers. Version 1.0.1 is the current stable release, offering production-ready APIs with a commitment to long-term support. The project maintains an active development and release cadence.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a simple AI agent using the Microsoft Agent Framework with Azure OpenAI. It requires `azure-identity` for authentication (e.g., via `az login`) and environment variables for Azure project endpoint and deployment name. All agent operations are asynchronous and must be run using `asyncio.run()`.

import asyncio
import os
from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential
# from dotenv import load_dotenv # Uncomment and install if using .env file locally

async def main():
    # Load environment variables from .env file if uncommented above
    # load_dotenv()

    # Ensure AZURE_AI_PROJECT_ENDPOINT and AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME are set
    # and you are authenticated via Azure CLI (e.g., `az login`)
    project_endpoint = os.environ.get("AZURE_AI_PROJECT_ENDPOINT", "https://your-project.services.ai.azure.com")
    deployment_name = os.environ.get("AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME", "gpt-4o")

    if not all([project_endpoint, deployment_name]):
        print("Please set AZURE_AI_PROJECT_ENDPOINT and AZURE_OPENAI_RESPONSES_DEPLOYMENT_NAME environment variables.")
        print("Ensure you have authenticated via Azure CLI (`az login`).")
        return

    # Create an Azure CLI credential for authentication
    credential = AzureCliCredential()

    # Initialize the Azure OpenAI Responses client
    client = AzureOpenAIResponsesClient(
        project_endpoint=project_endpoint,
        deployment_name=deployment_name,
        credential=credential,
    )

    # Create an agent with instructions
    agent = client.as_agent(
        name="HelloAgent",
        instructions="You are a friendly assistant. Keep your answers brief.",
    )

    # Run the agent
    print("Agent: Thinking...")
    result = await agent.run("What is the capital of France?")
    print(f"Agent: {result}")

    # Example of streaming response (optional)
    # print("\nAgent (streaming): Thinking...")
    # async for token in agent.run("Tell me a short story about a brave knight.", stream=True):
    #     print(token, end="", flush=True)
    # print()

if __name__ == "__main__":
    asyncio.run(main())

view raw JSON →