Microsoft AI Agents for Beginners

repository·main·Indexed 32 days ago

https://github.com/microsoft/ai-agents-for-beginners

A repository for learning to build production-ready AI agents using the Microsoft Agent Framework (MAF). Covers orchestration patterns (Sequential, Concurrent, Planning), context engineering, tool calling, and multi-agent systems. Includes guidance on using Microsoft Foundry Agent Service, Azure OpenAI, and running models locally via Foundry Local.

Tokens
638.1K
Snippets
1.1K
Records
2.1K
Agent score
91%

What's inside microsoft-ai-agents-for-beginners

  1. Overview of Planning and Design Patterns for AI Agents

    main

    This module covers the design patterns required to move from simple agentic interactions to complex, goal-oriented planning. Key concepts include:

    • Goal Definition and Task Decomposition: Defining a high-level objective and breaking it down into smaller, manageable sub-tasks.
    • Task Decomposition: The process of splitting a complex goal into a sequence or set of discrete actions.
    • Structured Output: Ensuring the agent provides responses in a predictable format (like JSON) to facilitate reliable task execution.
    • ReAct (Reasoning and Acting) Pattern: A pattern where the agent generates reasoning traces and then performs actions based on those thoughts, allowing for iterative improvement.
    • Multi-Agent Planning: Orchestrating multiple specialized agents to work together to achieve a complex goal through a central planning agent.
  2. Overview of AI Agents for Beginners course

    main

    The AI Agents for Beginners course teaches the fundamentals of building AI agents.

    Key Components

    • Code Samples: Found in the code_samples folder. Most examples use Microsoft Agent Framework (MAF) and Microsoft Foundry Agent Service V2.
    • Prerequisites: An Azure Account is required to use Microsoft Foundry.
    • Supported Providers: While primarily focused on Microsoft services, some examples support OpenAI-compatible providers like MiniMax.
    • Learning Materials: Each lesson includes a README, a short video, Python code examples using MAF, and links to additional resources.

    Getting Started

    1. Fork the repository to create your own copy for running code.
    2. Follow the Course Setup guide for detailed instructions on running the code.
    3. If you are new to Generative AI, it is recommended to complete the Generative AI For Beginners course first.

    Community Support

    You can join the Microsoft Foundry Discord to ask questions and connect with other learners: https://aka.ms/ai-agents/discord.

  3. Overview of AI Agents for Beginners Course

    main

    This course provides a comprehensive guide to building AI Agents, covering foundations, design patterns, and practical implementation.

    Key Technologies Used:

    • Microsoft Agent Framework (MAF): The primary framework for agent orchestration.
    • Microsoft Foundry Agent Service V2: Used for hosting and managing agent services (requires an Azure Account).
    • OpenAI-compatible providers: Some code samples support alternative providers like MiniMax for large context models (up to 204K tokens).

    Course Structure:

    Each lesson includes written documentation, a short video, Python code samples (located in the code_samples folder), and additional learning resources. Topics include:

    • Introduction to AI Agents and Use Cases
    • Exploring Agentic Frameworks
    • AI Agentic Design Patterns
    • Tool Use Design
    • Agentic RAG
    • Building Trustworthy AI Agents
    • Planning Design
    • Multi-Agent Design
  4. Overview of Microsoft Agent Framework (MAF) capabilities

    main

    Microsoft Agent Framework (MAF) is designed for building production-ready AI agents across various orchestration patterns:

    Orchestration Patterns

    • Sequential Orchestration: Step-by-step workflows.
    • Concurrent Orchestration: Executing multiple tasks simultaneously.
    • Group Chat Orchestration: Multiple agents collaborating on a single task.
    • Hand-off Orchestration: Agents transferring tasks to one another.
    • Manager Orchestration: A management agent creating and modifying task lists for sub-agents.

    Production Features

    • Observability: Uses OpenTelemetry to track tool calls, orchestration steps, and reasoning traces via Microsoft Foundry dashboards.
    • Security: Hosted via Microsoft Foundry with role-based access control (RBAC), private data handling, and content safety.
    • Durability: Supports long-running processes with the ability to pause, resume, and recover from errors.
    • Control: Supports human-in-the-loop workflows by identifying tasks that require human approval.

    Interoperability

    • Cloud-Agnostic: Runs in containers, on-prem, or across multiple clouds.
    • Provider Agnostic: Supports various SDKs (Azure OpenAI, OpenAI, etc.).
    • Open Standards: Uses Agent-to-Agent (A2A) and Model Context Protocol (MCP).
    • Extensible: Connects to services like Microsoft Fabric, SharePoint, Pinecone, and Qdrant.
  5. Overview of the Planning Design Pattern

    main

    The Planning Design Pattern involves creating a Planner that dynamically selects from available agents to solve complex tasks. The Planner's primary responsibility is to decompose a high-level goal into structured subtasks and assign them to specialized agents.

    Key concepts include:

    • Task Decomposition: Breaking down complex goals into manageable steps.
    • Agent Assignment: Mapping subtasks to agents that possess the necessary tools or functions to execute them.
    • Extensibility: The pattern can be augmented with additional patterns such as reflection, summarizer, and round robin chat for enhanced customization and control.
    • Advanced Orchestration (Magnetic One): For highly complex tasks, the Magnetic One architecture uses an orchestrator that generates task-specific plans, assigns tasks, and utilizes a monitoring mechanism to track progress and trigger re-planning when necessary.
  6. Overview of Local AI Agents with SLMs

    main

    Local AI agents leverage Small Language Models (SLMs) to run on-device (CPU, GPU, or NPU). This approach provides three primary benefits:

    1. Privacy: Data, prompts, and snippets never leave the machine or cross network boundaries.
    2. Cost: Eliminates per-token billing for global inference; costs are limited to local electricity.
    3. Offline Capability: Agents function without an internet connection.

    SLM Capabilities and Limitations

    • Strengths: Structured tasks (classification, extraction, summarization), Tool Calling (deciding which function to call with which arguments), and fast, private iterations on private data.
    • Weaknesses: Complex multi-step reasoning and broad general knowledge (due to smaller parameter counts).

    Best Practice: Use an SLM-led approach where the model orchestrates tools (e.g., read_file, search_docs) rather than relying on the model's internal knowledge of your specific codebase.

  7. Real-world applications of Browser-Use agents

    main

    Browser-based agents (CUAs) can be applied to several real-world workflows:

    • Travel & Commerce: Travel booking, price research, e-commerce price comparison, and availability checks.
    • Data Extraction: Extracting structured data from dynamic websites.
    • Testing: Vision-aware UI testing and verification.
    • Automation: Website monitoring and alerts, and intelligent form filling for complex workflows.
  8. Implement the Tool Use Design Pattern

    main

    The Tool Use Design Pattern enables Large Language Models (LLMs) to interact with external systems (APIs, databases, code interpreters) to achieve specific goals. This pattern relies on model-generated function calls where the LLM selects a tool and provides arguments based on a provided schema.

    Key Building Blocks

    • Function/Tool Schemas: JSON definitions of available tools (name, purpose, parameters, and output format).
    • Function Execution Logic: Logic that decides when and how to call tools (e.g., planners or routers).
    • Message Handling System: Manages the conversation flow between user messages, LLM tool calls, and tool outputs.
    • Tool Integration Framework: The infrastructure connecting the agent to external services.
    • Error Handling & Validation: Manages failures during tool execution and validates parameters.
    • State Management: Tracks conversation context and previous tool uses to ensure consistency across multiple turns.
  9. Understand Microsoft Foundry Agent Service core concepts

    main

    When using the Microsoft Foundry Agent Service, understand these three core concepts:

    • Agent: A 'smart' microservice integrated into Microsoft Foundry. It can answer questions (RAG), perform actions, or automate workflows using tools (like code_interpreter).
    • Thread: Represents a conversation or interaction between an agent and a user. Threads are used to store conversation progress, context, and interaction state.
    • Message: The individual units of communication within a thread. Messages can be text, images, or files. You create messages in a thread and then trigger a run to process them.
  10. Understand AI Agentic Design Principles

    main

    AI Agentic Design Principles provide a human-centric UX framework for building agents that expand human capabilities, fill knowledge gaps, facilitate collaboration, and assist in personal growth. The principles are categorized into three dimensions: Space, Time, and Core.

    Agent (Space)

    Focuses on the environment where the agent operates (physical and digital).

    • Connect, don't contract: Design agents to facilitate connection between people, events, and active knowledge rather than isolating users.
    • Easily available but temporally invisible: Agents should be accessible across tools/platforms and support multimodal inputs (sound, voice, text), but primarily operate in the background, surfacing only when necessary. They should transition smoothly between proactive and reactive modes while maintaining transparency and user control over background processes.

    Agent (Time)

    Focuses on how the agent interacts across different temporal contexts.

    • Past (Reflection of history): Agents should use rich historical context (events, people, states) to provide relevant results and build connections between past events and current situations.
    • Present (Suggesting instead of telling): Agents should have a holistic view of interaction. Instead of static instructions, they should drive progress based on context, social/cultural changes, and user intent, providing information at the appropriate moment through incremental complexity.
    • Future (Adaptive and evolving): Agents should be designed to adapt to new tools, platforms, and models, and evolve based on continuous user interaction and changing needs.
  11. Understand Multi-Agent Design Patterns

    main

    Multi-agent design is a pattern where multiple agents work together to achieve a common goal. This pattern is useful for scaling complex systems and improving reliability compared to a single-agent approach.

    When to use Multi-Agent systems:

    • Large Workloads: Break large tasks into smaller sub-tasks that can be processed in parallel for speed.
    • Complex Tasks: Decompose complex requests into sub-tasks and assign them to agents with specific expertise (e.g., in autonomous vehicles, separate agents handle navigation, obstacle detection, and vehicle communication).
    • Diverse Expertise: Assign different agents to handle specialized domains (e.g., in healthcare, separate agents for engineering, treatment planning, and patient monitoring).

    Benefits over Single-Agent systems:

    • Specialization: Each agent is optimized for a specific task, preventing the 'jack of all trades, master of none' problem.
    • Scalability: It is easier to scale by adding more specialized agents rather than increasing the complexity of a single agent.
    • Fault Tolerance: If one agent fails, others can continue working, increasing the overall system reliability.
  12. Understand the transition from Prototype to Production agents

    main

    When moving from a prototype (running in a notebook or local machine) to a production-ready agent, the focus shifts from the model itself to the operational infrastructure. While the core loop (thinking, tool calling, responding) remains the same, the following aspects must change:

    AspectPrototypeProduction
    HostingLocal notebook/machineHosted service, scalable and rolled out
    IdentityPersonal az login tokenManaged identity with scoped RBAC
    StateIn-memory (lost on restart)Externalized (thread stores, memory services)
    FailureManual traceback inspectionRetries, fallbacks, dead-letter queues, alerts
    CostUnmanaged/ad-hocTracked per request, routed, cached, and budgeted
    QualityManual output inspectionAutomated evaluation before every release
    TrustManual approval of actionsPolicy-based + Human-in-the-loop for high-risk actions