Agent Framework Orchestrations
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
-
ModuleNotFoundError: No module named 'agent_framework.orchestrations'
cause The `agent-framework-orchestrations` package is not installed, or the `agent-framework` umbrella package (which includes orchestrations) is missing.fix`pip install agent-framework-orchestrations` or `pip install agent-framework` -
Failed to create FoundryChatClient: <specific_error_message>
cause Environment variables for `FOUNDRY_PROJECT_ENDPOINT` or `AZURE_AI_MODEL_DEPLOYMENT_NAME` are missing or incorrect, or Azure CLI authentication (`az login`) has not been performed.fixEnsure `FOUNDRY_PROJECT_ENDPOINT` and `AZURE_AI_MODEL_DEPLOYMENT_NAME` are set in your environment variables or `.env` file. Run `az login` to authenticate with Azure if using `AzureCliCredential`. -
Agent enters infinite loop or produces repetitive output
cause Poorly defined termination conditions, ambiguous agent instructions, or issues with shared context leading agents to repeatedly attempt the same action.fixRefine agent instructions to be precise, implement explicit termination criteria in the workflow, and review how context is shared or mutated between agents to prevent circular reasoning.
Warnings
- breaking Microsoft Agent Framework is the direct successor and unified platform for both Semantic Kernel and AutoGen. Users of these older frameworks will need to migrate their existing agent and workflow implementations to the new Agent Framework APIs.
- gotcha The framework's `WorkflowBuilder` and specialized builders (like `SequentialBuilder`) define graph-based, explicit execution paths. This differs from dynamic, LLM-driven agent interactions and requires upfront design.
- gotcha In multi-agent systems, unmanaged shared memory can lead to 'context pollution' where agents overwrite or misinterpret shared state, making workflows unreliable and hard to debug.
- gotcha Agentic workflows can incur unexpected cloud costs if not properly designed. Inefficient agent calls, loops, and redundant LLM interactions can rapidly increase token consumption and expenses.
- gotcha Handling long-running tasks, particularly those requiring human intervention or spanning extended periods, necessitates explicit checkpointing and state persistence to ensure recovery from interruptions.
Install
-
pip install agent-framework-orchestrations -
pip install agent-framework
Imports
- SequentialBuilder
from agent_framework.orchestrations import SequentialBuilder
- ConcurrentBuilder
from agent_framework.orchestrations import ConcurrentBuilder
- HandoffBuilder
from agent_framework.orchestrations import HandoffBuilder
- GroupChatBuilder
from agent_framework.orchestrations import GroupChatBuilder
- MagenticBuilder
from agent_framework import MagenticBuilder
- WorkflowBuilder
from agent_framework import WorkflowBuilder
Quickstart
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())