Microsoft Agent Framework: Combining Semantic Kernel + Autogen for Advanced AI Agents




Introduction

Microsoft Agent Framework (MAF) is an open-source SDK for building AI agents and multi-agent workflows using .NET and Python, with Java and JavaScript support coming soon. This new framework represents the convergence of two powerful Microsoft technologies: Semantic Kernel and AG-Autogen.



Microsoft Agent Framework = Semantic Kernel + Autogen

MAF introduces workflows that provide explicit control over multi-agent execution paths and a robust state management system designed for long-running and human-in-the-loop (HITL) use cases. As the next generation of both Semantic Kernel and Autogen, MAF offers a clear migration path for developers who have built agents using either of these frameworks, ensuring your existing work can transition seamlessly to this more powerful platform.

The framework is designed not just to execute tasks but to orchestrate multiple agents, manage state effectively, and handle complex scenarios that require human oversight making it a comprehensive solution for real-world AI applications.



Understanding AI Agents vs. Workflows

To understand the distinction between AI agents and workflows, consider how humans operate.
We function as AI agents: our brain acts like an LLM driving our activities, while our eyes and ears gather external data and provide context to our brain for real-time decision-making—similar to how MCP servers or tools work for AI agents.

However, humans also operate as workflows. Consider the digestive system: it’s a defined workflow where multiple organs (acting as individual agents) work together to accomplish a complex task. This mirrors how business processes function in the real world—multiple specialized components coordinating to achieve an outcome.

Just as humans have both short-term and long-term memory, AI agents in MAF maintain memory across interactions, enabling them to build context and make informed decisions over time.



Orchestration Patterns in Microsoft Agent Framework

MAF supports multiple orchestration modes to handle different scenarios effectively:



1. Sequential Orchestration

Agents execute tasks in sequential steps, passing results or outputs from one agent to the next in a defined order. This pattern is ideal for workflows where each step depends on the completion of the previous one.



2. Concurrent Orchestration

Agents work in parallel to maximize efficiency. A practical example is searching for a user across multiple platforms—LinkedIn, social media, and other sources—simultaneously, then aggregating the results. This dramatically reduces execution time compared to sequential processing.



3. Handoff Orchestration

This workflow operates dynamically based on context and rules. Agents hand off tasks to other agents as needed, allowing the system to adapt in real-time to changing conditions or requirements.



4. Magnetic Orchestration

This pattern represents the closest equivalent to deep agent frameworks like LangGraph, providing sophisticated, context-aware coordination between agents.



5. Complex Multi-Agent Collaboration

Supports complex, generalist multi-agent collaboration where multiple specialized agents work together on sophisticated tasks requiring diverse capabilities.



Now let us build simple chatbot using Microsoft new Agent framework and Azure AI Foundry.

I will show how to create an interactive chatbot using Microsoft’s Agent Framework with Azure AI Foundry. This powerful combination enables the creation of sophisticated AI agents capable of natural, multi-turn conversations, leveraging Azure’s enterprise-grade AI services.

To support multi-turn conversations, we add a thread to the agent, which keeps the conversation history in memory, ensuring context is maintained throughout the interaction.



Prerequisites

Python 3.11 or higher
Azure CLI installed and configured
An Azure subscription with access to Azure AI Foundry
Basic knowledge of Python and async programming



Install Dependencies

uv add agent-framework –prerelease=allow

pip install agent-framework –pre



Create a .env file in your project root:

After creating Azure AI Foundry project you will able to get this below endpoint and the model you deployed part of this AI Foundry project .

AZURE_AI_PROJECT_ENDPOINT=https://your-project-endpoint.cognitiveservices.azure.com/
AZURE_AI_MODEL_DEPLOYMENT_NAME=your-deployment-name


import asyncio
from agent_framework import ChatAgent
from agent_framework.azure import AzureAIAgentClient
from azure.identity.aio import AzureCliCredential

async def main():
    credential = AzureCliCredential()
    print("=" * 50)
    print("CREDENTIAL INFORMATION:")
    print("=" * 50)
    print(f"Credential Type: {type(credential).__name__}")
    print(f"Module: {type(credential).__module__}")
    print(f"Full Class: {type(credential)}")

    # Try to get more info about the credential
    try:
        # Get token to see what account is being used
        token = await credential.get_token("https://cognitiveservices.azure.com/.default")
        print(f"Token Type: {type(token)}")
        print(f"Token Expires: {token.expires_on}")
        print("Authentication: SUCCESSFUL")
    except Exception as e:
        print(f"Authentication Error: {e}")

    print("=" * 50)

    # Ask user for mode selection
    print("Select mode:")
    print("1. Normal mode (complete response)")
    print("2. Streaming mode (real-time response)")
    mode_choice = input("Enter choice (1 or 2): ").strip()

    streaming_mode = mode_choice == "2"
    print(f"Selected: {'Streaming' if streaming_mode else 'Normal'} mode")
    print("=" * 50)

    async with (
        credential,
        ChatAgent(
            chat_client=AzureAIAgentClient(async_credential=credential),
            instructions="You are a helpful and friendly chatbot. You can answer questions, have conversations, and assist with various topics."
        ) as agent,
    ):
        print("Chatbot: Hello! I'm your friendly chatbot. Type 'exit' or 'quit' to end the conversation.")
        thread = agent.get_new_thread()

        while True:
            user_input = input("\nYou: ").strip()

            if user_input.lower() in ['exit', 'quit']:
                print("Chatbot: Goodbye! Have a great day!")
                break

            if not user_input:
                continue

            if streaming_mode:
                print("Chatbot: ", end="", flush=True)
                async for chunk in agent.run_stream(user_input, thread=thread):
                    if chunk.text:
                        print(chunk.text, end="", flush=True)
                print()  # New line after streaming
            else:
                result = await agent.run(user_input, thread=thread)
                print(f"Chatbot: {result.text}")

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

Exit fullscreen mode



Understanding the Key Components



AzureAIAgentClient

The AzureAIAgentClient is the core component that connects your application to Azure AI Foundry:

AzureAIAgentClient(
async_credential=credential,
# Optional parameters:
# project_endpoint=”https://your-endpoint.cognitiveservices.azure.com/“,
# model_deployment_name=”your-deployment-name”,
# agent_id=”existing-agent-id”
)



ChatAgent

The ChatAgent wraps the client and provides the conversational interface:

ChatAgent(
chat_client=AzureAIAgentClient(async_credential=credential),
instructions=”Your custom instructions for the agent”
)



Thread Management

Threads maintain conversation context:

thread = agent.get_new_thread()
result = await agent.run(user_input, thread=thread)



Testing the Chatbot



Conclusion

We’ve successfully created an interactive chatbot using Microsoft Agent Framework and Azure AI Foundry! This foundation provides:

✅ Enterprise-grade AI capabilities
✅ Secure authentication with Azure
✅ Streaming and normal response modes
✅ Conversation thread management
✅ Extensible architecture

The Microsoft Agent Framework makes it easy to build sophisticated AI applications while leveraging Azure’s robust infrastructure. You can now extend this chatbot with additional features, integrate it into larger systems, or deploy it to production environments.

The upcoming blogs i will show how to build AI Agents and Workflow based AI agents using Microsoft Agent Framework which uses Tools (MCP Servers ), connecting to External Datasources.

Thanks
Sreeni Ramadorai



Source link

Leave a Reply

Your email address will not be published. Required fields are marked *