Agent Framework Orchestrations

1.0.0b260409 · active · verified Thu Apr 16

This library, part of the broader Microsoft Agent Framework, provides high-level orchestration patterns for coordinating AI agents and executors. It includes builders for sequential, concurrent, handoff, group chat, and Magentic workflows, enabling developers to create structured multi-agent systems. The framework unifies concepts from Semantic Kernel and AutoGen, focusing on robust and auditable AI automation. The main framework recently reached version 1.0, with this sub-package being actively developed, currently at `1.0.0b260409`.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to set up a basic sequential workflow using `SequentialBuilder`. It defines two agents (a 'writer' and a 'reviewer') and orchestrates them to process a task in a linear fashion, passing the conversation history between them. It uses `FoundryChatClient` requiring Azure AI Foundry credentials via environment variables and Azure CLI authentication.

import asyncio
import os
from dotenv import load_dotenv
from agent_framework import Agent
from agent_framework.foundry import FoundryChatClient
from agent_framework.orchestrations import SequentialBuilder
from azure.identity import AzureCliCredential

load_dotenv() # Load environment variables from .env file

async def main():
    # Ensure environment variables are set for FoundryChatClient
    foundry_endpoint = os.environ.get("FOUNDRY_PROJECT_ENDPOINT", "")
    model_deployment_name = os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "")

    if not foundry_endpoint or not model_deployment_name:
        print("Please set FOUNDRY_PROJECT_ENDPOINT and AZURE_AI_MODEL_DEPLOYMENT_NAME environment variables.")
        print("Also ensure you are authenticated via 'az login' if using AzureCliCredential.")
        return

    # 1) Create a chat client (e.g., FoundryChatClient for Azure AI Foundry)
    try:
        client = FoundryChatClient(
            project_endpoint=foundry_endpoint,
            model=model_deployment_name,
            credential=AzureCliCredential(),
        )
    except Exception as e:
        print(f"Failed to create FoundryChatClient: {e}")
        print("Ensure 'az login' is performed and environment variables are correctly configured.")
        return

    # 2) Define your agents
    writer = Agent(
        client=client,
        instructions="You are a concise copywriter. Provide a single, punchy marketing sentence based on the prompt.",
        name="writer",
    )
    reviewer = Agent(
        client=client,
        instructions="You are a thoughtful reviewer. Give brief feedback on the previous assistant message.",
        name="reviewer",
    )

    # 3) Build a sequential workflow (writer -> reviewer)
    workflow = SequentialBuilder(participants=[writer, reviewer]).build()

    # 4) Run the workflow
    print("\n--- Running Sequential Workflow ---")
    async for event in workflow.run_stream("Write a tagline for a budget-friendly eBike."):
        if event.type == "output":
            print("\nFinal Conversation History:")
            for message in event.data:
                print(f"  {message.role.capitalize()}: {message.content}")

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

view raw JSON →