Skip to content

Sharono123/agent-framework-ubtech

 
 

Repository files navigation

📧 Microsoft Agent Framework — Learning Examples

A comprehensive collection of learning resources for building AI-powered systems using the Microsoft Agent Framework. This repository includes both an interactive Jupyter notebook tutorial and standalone Python examples demonstrating advanced orchestration patterns.

🎯 What's Included

This repository contains two main learning resources:

1. Support Email Copilot (Jupyter Notebook)

An interactive tutorial that progressively teaches framework capabilities:

  • Classifies incoming emails (Spam / Not Spam / Uncertain)
  • Looks up customer SLA and ticket status via function tools
  • Drafts professional responses with customizable tone
  • Requires approval before sending sensitive replies
  • Remembers user preferences (language, tone, name)
  • Processes in parallel for long emails (response + summary)
  • Uses multiple reviewers for quality control (security, tone, accuracy)
  • Logs every operation for observability

2. Startup Idea Analyzer (Standalone Python Script)

A Magentic orchestration demo featuring collaborative AI agents:

  • 🔍 Market Researcher - Pessimistic analyst focused on risks
  • 💰 Financial Analyst - Optimistic view on revenue potential
  • ⚙️ Tech Advisor - Skeptical technical feasibility assessor
  • 🎯 Magentic Manager - Coordinates the team and balances perspectives
  • 📄 Live Logging - Real-time Markdown discussion logs
  • Streaming Output - See agent discussions as they happen
  • 🔄 Human-in-the-Loop - Optional plan review and approval

🚀 Quick Start

Prerequisites

  1. Azure subscription with access to Azure OpenAI
  2. Azure OpenAI resource with a deployed model (e.g., gpt-4o-mini)
  3. Azure CLI installed and authenticated (az login)
  4. Python 3.10+
  5. Azure AI Foundry project (Section 7 — MCP Integration only)
    • Project endpoint — found in your project's Overview page
    • Model deployment name — found in your project's Models + endpoints page

Setup

# 1. Clone the repository
git clone https://github.com/moti-malka/agent-framework.git
cd agent-framework

# 2. Create virtual environment
python3.10 -m venv .venv
source .venv/bin/activate  # macOS/Linux
# or .venv\Scripts\activate  # Windows

# 3. Install dependencies
pip install -r requirements.txt

# 4. Configure environment
# Create a .env file with your Azure OpenAI configuration:
AZURE_OPENAI_ENDPOINT=https://your-apim-gateway.azure-api.net  # APIM gateway URL
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=gpt-4o-mini
AZURE_OPENAI_API_KEY=your-apim-subscription-key  # APIM subscription key
API_VERSION=2025-01-01-preview  # Optional, defaults to this value

# 5. Login to Azure (for CLI-based authentication)
az login

Running the Examples

Option 1: Jupyter Notebook Tutorial

# Open the notebook
jupyter notebook agent_framework.ipynb
# Or open in VS Code with Jupyter extension

Option 2: Standalone Magentic Demo

# Run the startup analyzer
python magentic_example.py

# Follow the interactive prompts to:
# - Choose streaming or human-in-the-loop mode
# - Select a pre-defined startup idea or enter your own
# - Watch agents collaborate in real-time
# - Review the generated discussion log in discussions/ folder

🏗️ Framework Features Demonstrated

Jupyter Notebook (agent_framework.ipynb)

Feature Section Description
ChatAgent 1-3 Core agent with instructions, streaming, threads
Function Tools 4 @tool decorator for custom capabilities
Approval Mode 5 approval_mode="always_require" for HITL
Middleware 6 Agent and function invocation hooks
ContextProvider 7 Memory with invoking/invoked lifecycle
WorkflowBuilder 8-10 Sequential, branching, fan-out patterns
AgentExecutor 8-10 Wrap agents for workflow orchestration
Switch-Case 9 Multi-way routing with Case/Default
Multi-Selection 10 Dynamic fan-out to parallel paths
Fan-In 10 Aggregate results from parallel execution
ConcurrentBuilder 11 Parallel multi-agent processing
MagenticBuilder 11 Manager-orchestrated agent teams

Python Script (magentic_example.py)

Feature Description
MagenticBuilder Dynamic team coordination with manager agent
Specialized Agents Role-based agents with distinct personalities
Streaming Events Real-time agent updates via AgentRunUpdateEvent
Progress Tracking MagenticProgressLedger for workflow state
Plan Review Human-in-the-loop approval with MagenticPlanReviewRequest
Discussion Logging Custom middleware for Markdown conversation logs
Agent Middleware Custom logging hooks for observability
Azure Authentication Both API key and Azure CLI auth support

📁 Project Structure

agent-framework/
├── agent_framework.ipynb      # Interactive tutorial notebook (12 sections)
├── magentic_example.py        # Standalone Magentic orchestration demo
├── requirements.txt           # Python dependencies
├── .env                       # Azure OpenAI configuration (create this)
├── .venv/                     # Python virtual environment
├── images/                    # Architecture and workflow diagrams
│   ├── agent-components.png
│   ├── concurrent-workflow.png
│   ├── group-chat.png
│   ├── magentic-workflow.png
│   ├── sequential-workflow.png
│   ├── threads-and-memory.png
│   └── workflow-example.png
├── discussions/               # Created by magentic_example.py at runtime (Markdown logs)
└── README.md                  # This file

📝 Environment Variables

Create a .env file in the project root with the following variables:

# Required: Azure OpenAI Configuration (Sections 1–16)
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=gpt-4o-mini

# Optional: API Key (if not using Azure CLI authentication)
AZURE_OPENAI_API_KEY=your-api-key

# Optional: API Version (defaults to 2025-01-01-preview)
API_VERSION=2025-01-01-preview

# Required for Section 7 only (MCP Integration)
# AZURE_AI_PROJECT_ENDPOINT: Azure AI Foundry → your project → Overview → Project endpoint
AZURE_AI_PROJECT_ENDPOINT=https://<resource>.services.ai.azure.com/api/projects/<project>
# AZURE_AI_MODEL_DEPLOYMENT_NAME: Azure AI Foundry → your project → Models + endpoints → Deployment name
AZURE_AI_MODEL_DEPLOYMENT_NAME=gpt-4o-mini

Authentication Options:

  1. Azure CLI (recommended): Run az login before starting
  2. API Key: Set AZURE_OPENAI_API_KEY in .env

📚 Jupyter Notebook Contents

The agent_framework.ipynb tutorial is organized into 12 progressive sections:

# Section What You'll Learn
0 Shared Setup Environment, models, sample data
1 Basic Agent Create and run your first agent
2 Streaming Real-time token streaming
3 Multi-Turn Conversations Thread-based memory
4 Function Tools Add custom capabilities
5 Human-in-the-Loop Approval workflows
6 Middleware Logging & observability
7 Memory Persistent user context
8 Sequential Workflows Classify → Draft → Review
9 Branching Logic Spam vs. NotSpam vs. Uncertain
10 Fan-Out/Fan-In Parallel processing
11 Multi-Agent Group Chat Team collaboration
12 Capstone Demo End-to-end system

📖 Learn More

License

MIT

About

Microsoft Agent Framework demo with Azure OpenAI

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Jupyter Notebook 86.4%
  • Python 13.6%