Microsoft Agent Framework

repository·main·Indexed 11 days ago

https://github.com/microsoft/agent-framework

An open, multi-language framework for building production-grade AI agents and multi-agent workflows in .NET and Python. Version 1.13.0 supports complex orchestration patterns (sequential, concurrent, group collaboration) and provides abstractions for vector stores and embedding generators compatible with Semantic Kernel. It includes support for 13+ connectors such as Azure AI Search, Qdrant, Pinecone, and MongoDB, and offers tools like `create_search_tool` to enable vector search capabilities for agents.

Tokens
558.6K
Snippets
1.4K
Records
2.2K
Agent score
94%

What's inside MAF

  1. Overview of agent-framework-hosting-a2a

    main

    The agent-framework-hosting-a2a package provides helpers for composing Microsoft Agent Framework agents and workflows with an application-owned native A2A (Agent-to-Agent) server.

    It focuses on:

    • Converting protocol values between A2A and Agent Framework formats.
    • Generating common discovery fields for a native AgentCard.

    Note: This package does not provide an AgentExecutor, task lifecycle management, event queues, task stores, routes, session policies, authentication, or deployment mechanisms. These must be managed by your application.

  2. Overview of Microsoft Agent Framework for .NET

    main

    Microsoft Agent Framework is a .NET library designed for building, orchestrating, and deploying AI agents and multi-agent workflows. It supports a range of complexity from simple chat agents to sophisticated multi-agent systems using graph-based orchestration.

    Core Capabilities:

    • Multi-Agent Orchestration: Supports sequential, concurrent, group chat, and handoff patterns.
    • Graph-based Workflows: Enables connecting agents and functions with features like streaming, checkpointing, and human-in-the-loop capabilities. Workflows can be defined using either imperative or declarative approaches.
    • Provider Integration: Supports multiple LLM providers.
    • Extensibility: Includes middleware for custom request/response processing pipelines and exception handling.
    • Observability: Built-in OpenTelemetry integration for distributed tracing, monitoring, and debugging.
    • Compatibility: Works with .NET 8.0, .NET Standard 2.0, and .NET Framework.
  3. Overview of Vector Stores and Embeddings in Agent Framework

    main

    Agent Framework provides ported abstractions for vector stores and embedding generators, designed to be compatible with Semantic Kernel (SK) data models while following AF's native coding standards.

    Key Capabilities:

    • Embedding Generation: Generic client abstraction supporting text, image, and audio inputs.
    • Vector Store Collections: CRUD operations including upsert, get, and delete.
    • Vector Search: A unified interface using the search_type parameter (supports "vector" and "keyword_hybrid").
    • Data Modeling: Use the @vectorstoremodel decorator to define models (supports Pydantic, dataclasses, plain classes, and dicts).
    • Agent Tools: Pre-built tools for agents via create_search_tool, create_upsert_tool, create_get_tool, and create_delete_tool.
    • Connectors: Supports 13+ providers including Azure AI Search, Qdrant, Redis, PostgreSQL, MongoDB, Cosmos DB, Pinecone, Chroma, Weaviate, Oracle, SQL Server, and FAISS. An in-memory store is available for testing.
  4. Understand the Conditional Workflow Sample structure

    main

    The sample consists of two primary files that separate the workflow logic from the execution environment:

    • workflow.yaml: Contains the declarative definition of the workflow, including the conditional logic (if/else branching and nested conditions).
    • main.py: The Python entry point used to trigger and execute the defined workflow.

    Workflow Logic:

    1. Accepts a user's age as an input.
    2. Evaluates conditions to categorize the age.
    3. Executes specific branches to send messages corresponding to the determined age category.
  5. Create an AIAgent with various providers

    main

    The Microsoft Agent Framework allows you to instantiate an AIAgent using a wide variety of model providers. This enables you to switch between different LLM backends (like Anthropic, Azure OpenAI, OpenAI, or Google Gemini) while maintaining a consistent agent interface.

    Available provider implementations include:

    • Anthropic: Using Claude models, including support for reasoning, function tools, and skills.
    • Azure: Integration with Azure AI Projects, Microsoft Foundry models, and Azure OpenAI (via ChatCompletion or Responses).
    • OpenAI: Standard ChatCompletion, Responses, reasoning capabilities, and Code Interpreter support.
    • GitHub Copilot: Using the GitHub Copilot SDK or BYOK (Bring Your Own Key) routing.
    • Google Gemini: Using Google's Gemini models.
    • Ollama: For local model execution.
    • Dapr: Using Dapr's Conversation building block.
    • ONNX: Using ONNX Runtime.
    • Custom: Implementing your own provider logic.
    • A2A: For existing A2A agents.
  6. GitHub Copilot Agent usage examples overview

    main

    The following examples demonstrate various capabilities and configurations for the GitHubCopilotAgent:

    • Basic Usage: github_copilot_basic.py demonstrates simple streaming and non-streaming responses with function tools.
    • Session Management: github_copilot_with_session.py shows automatic session creation, persistence via session objects, and resuming sessions by ID.
    • Shell Permissions: github_copilot_with_shell.py demonstrates enabling shell command execution (e.g., listing files).
    • File Operations: github_copilot_with_file_operations.py shows enabling file read and write permissions.
    • URL Fetching: github_copilot_with_url.py demonstrates enabling URL fetching permissions to process web content.
    • MCP Integration: github_copilot_with_mcp.py shows configuring Model Context Protocol (MCP) servers (stdio and HTTP).
    • Custom Instructions: github_copilot_with_instruction_directories.py shows configuring custom instruction directories for project-specific guidelines.
    • Multiple Permissions: github_copilot_with_multiple_permissions.py shows combining shell, read, and write access.
    • BYOK (Bring Your Own Key): github_copilot_with_byok.py shows routing requests through your own endpoint instead of the GitHub Copilot backend.
  7. Gemini Integration Features

    main

    The Gemini integration for Microsoft Agent Framework provides several advanced capabilities through familiar chat abstractions:

    • Streaming: Receive model responses incrementally.
    • Tool/Function Calling: Enable agents to interact with external tools.
    • Structured Output: Enforce specific data formats in responses.
    • Grounding: Support for Google Search and Google Maps grounding.
    • Extended Thinking: Configure reasoning capabilities using ThinkingConfig.
    • Code Execution: Utilize built-in code execution capabilities.
  8. Explore provider-specific samples for Agent Framework

    main

    The python/samples/02-agents/providers/ directory contains specialized samples for integrating various LLM providers and services with the Agent Framework. Use these samples to understand how to implement specific clients, agents, and tool-calling patterns for your chosen provider.

    Available provider sample categories include:

    • Anthropic: Claude samples using AnthropicClient and ClaudeAgent (includes tools, MCP, sessions, and Foundry integration).
    • Amazon: AWS Bedrock samples using BedrockChatClient (includes tool-enabled agents).
    • Azure: Azure OpenAI samples using OpenAIChatCompletionClient (includes basic usage, configuration, tools, and sessions).
    • Copilot Studio: Microsoft Copilot Studio agent samples (includes environment/app registration and authentication patterns).
    • Custom: Extensibility samples for building your own BaseAgent and BaseChatClient implementations.
    • Foundry: Microsoft Foundry and Foundry Local samples using FoundryChatClient, FoundryAgent, RawFoundryAgentChatClient, and FoundryLocalClient.
    • Gemini: Google Gemini samples (includes tool calling, streaming, extended thinking, grounding, and code execution).
    • GitHub Copilot: GitHubCopilotAgent samples (includes session handling, permission-scoped access, and MCP integration).
    • Mistral: Mistral AI embedding generation samples.
    • Ollama: Local Ollama samples using OllamaChatClient (includes reasoning and multimodal examples).
    • OpenAI: OpenAI provider samples for Chat and Chat Completion clients (includes tools, structured output, sessions, MCP, web search, and multimodal tasks).
  9. Explore Foundry Provider samples

    main

    The Foundry provider samples are categorized into three main types of implementations:

    FoundryAgent Samples

    Used for creating agents that interface with Microsoft Foundry. Key capabilities demonstrated include:

    • Basic agent setup (foundry_agent_basic.py)
    • Custom client configuration (foundry_agent_custom_client.py)
    • Hosted agent implementations (foundry_agent_hosted.py)
    • Agents with local function tools (foundry_agent_with_function_tools.py)

    FoundryChatClient Samples

    Used for direct chat client interactions. Capabilities include:

    • Project endpoint integration (foundry_chat_client.py)
    • Code interpreter and file handling (foundry_chat_client_code_interpreter_files.py, foundry_chat_client_with_code_interpreter.py)
    • Image analysis (foundry_chat_client_image_analysis.py)
    • File search (foundry_chat_client_with_file_search.py)
    • Function tools and MCP (Model Context Protocol) integration, including hosted and local MCP (foundry_chat_client_with_function_tools.py, foundry_chat_client_with_hosted_mcp.py, foundry_chat_client_with_local_mcp.py)
    • Toolbox connectivity via MCPStreamableHTTPTool or skill discovery via MCPSkillsSource (foundry_chat_client_with_toolbox.py, foundry_chat_client_with_toolbox_skills.py)
    • Session management (foundry_chat_client_with_session.py)

    FoundryLocalClient Samples

    Used for local development and testing with the Foundry Local runtime. The primary sample (foundry_local_agent.py) demonstrates:

    • Streaming and non-streaming responses
    • Function tool calling
  10. Integrate Microsoft Purview for policy enforcement

    main

    The agent-framework-purview package allows you to enforce Microsoft Purview (Microsoft Graph dataSecurityAndGovernance) policies on both the prompt (user input + history) and the model response. This enables Data Loss Prevention (DLP) and governance by blocking or allowing content based on centrally managed policies.

    Key Capabilities:

    • Ingress Protection: Blocks sensitive content before it reaches the LLM.
    • Egress Protection: Blocks disallowed model output before it leaves the system.
    • Middleware Integration: Works with any Agent or orchestration using the standard middleware pipeline.
    • Audit & Governance: Logs AI interactions for Audit, Communication Compliance, and Insider Risk Management.

    Status: Preview

    import asyncio
    from agent_framework import Agent, Message
    from agent_framework.openai import OpenAIChatCompletionClient
    from agent_framework.microsoft import PurviewPolicyMiddleware, PurviewSettings
    from azure.identity import InteractiveBrowserCredential
    
    async def main():
        client = OpenAIChatCompletionClient()
    
        purview_middleware = PurviewPolicyMiddleware(
            credential=InteractiveBrowserCredential(),
            settings=PurviewSettings(app_name="My Sample App")
        )
    
        agent = Agent(
            client=client,
            instructions="You are a helpful assistant.",
            middleware=[purview_middleware]
        )
    
        response = await agent.run(Message("user", ["Summarize zero trust in one sentence."]))
        print(response)
    
    asyncio.run(main())