MAF - AG-UI Azure Agent Template

December 9, 2025 Β· View on GitHub

A structured and production-ready template for AI agent development. It combines the Microsoft Agent Framework, AG-UI, CopilotKit UI, and Azure services in a clean structure. The design keeps the frontend, agent logic, tools, and observability separate, so you can build agent-driven apps with minimal setup.

Architecture Diagram

🌟 What is this?

This is a starter template for building AI chat applications with:

  • AG-UI Protocol - Standard protocol for AI agent communication (CopilotKit ↔ Agent Framework)
  • Azure-native - Built with Azure Services (OpenAI, Cosmos DB, Container Apps, Application Insights, etc.)
  • Agent Workflow - Multi-agent orchestration with tools and MCP (Model Context Protocol) integration
  • Modern Architecture - Clean separation of concerns with modular folder structure
  • Production Features - Auth, persistence, observability, security middleware, CI/CD included

Demo Use Case

The template demonstrates a simple flight price assistant that:

  1. Queries flight prices between cities
  2. Generates charts/tables for visualization (via MCP Tools)

⚠️ Architecture Note: The example uses two agents (Flight β†’ Chart) to illustrate workflow composition. In real applications, responsibilities can be combined or extended based on system needs.

✨ Features

CategoryFeatures
ProtocolπŸ”Œ AG-UI standard (CopilotKit ↔ Microsoft Agent Framework)
Frontend🎨 CopilotKit Chat UI (Next.js)
Backend⚑ FastAPI + Microsoft Agent Framework
LLM🧠 Azure OpenAI (Managed Identity auth)
DatabaseπŸ’Ύ Azure Cosmos DB (conversation persistence)
SecurityπŸ›‘οΈ Agent middleware (prompt injection detection, input validation)
ObservabilityπŸ“Š OpenTelemetry β†’ Azure Application Insights
InfrastructureπŸ—οΈ Terraform (Infrastructure as Code for one-command deployment)
DevOps🐳 Docker Compose (local) + GitHub Actions β†’ Azure Container Registry (CI/CD)
Deployment☁️ Azure Container Apps + Static Web Apps

πŸ—οΈ Architecture

Click to expand text version
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Frontend (Next.js)                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚              CopilotKit Chat UI                      β”‚    β”‚
β”‚  β”‚         (port 3000)                                  β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚ AG-UI Protocol
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Backend (FastAPI)                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚              /copilotkit endpoint                    β”‚    β”‚
β”‚  β”‚         (port 8000)                                  β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                         β”‚                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚           Microsoft Agent Framework                  β”‚    β”‚
β”‚  β”‚                                                      β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  workflow  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”         β”‚    β”‚
β”‚  β”‚  β”‚ Flight Agentβ”‚ ─────────▢ β”‚ Chart Agent β”‚         β”‚    β”‚
β”‚  β”‚  β”‚  (Tool A)   β”‚            β”‚  (Tool B)   β”‚         β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜         β”‚    β”‚
β”‚  β”‚                                                      β”‚    β”‚
β”‚  β”‚  Note: Two agents used to demo workflow feature.     β”‚    β”‚
β”‚  β”‚  Single agent with both tools works too!             β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                         β”‚                                    β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚              Azure Cosmos DB                         β”‚    β”‚
β”‚  β”‚         (Conversation Persistence)                   β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                          β”‚
                          β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Azure Services                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”   β”‚
β”‚  β”‚ Azure OpenAI β”‚ β”‚  Cosmos DB   β”‚ β”‚ Application Insightsβ”‚   β”‚
β”‚  β”‚   (LLM)      β”‚ β”‚ (NoSQL)      β”‚ β”‚   (Monitoring)      β”‚   β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Project Structure

maf/
β”œβ”€β”€ main.py                     # FastAPI entry point
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ services/               # 🧠 Core business logic
β”‚   β”‚   β”œβ”€β”€ agent.py            #    Agent definitions & CopilotKit integration
β”‚   β”‚   β”œβ”€β”€ tools.py            #    Tool implementations (flight query, chart)
β”‚   β”‚   └── workflow.py         #    Multi-agent workflow orchestration
β”‚   β”œβ”€β”€ db/                     # πŸ’Ύ Database layer
β”‚   β”‚   β”œβ”€β”€ cosmos.py           #    Cosmos DB connection (Azure Identity)
β”‚   β”‚   └── cosmos_chat_store.py#    Chat message persistence for Agent Framework
β”‚   β”œβ”€β”€ schemas/                # πŸ“‹ Data models (Pydantic)
β”‚   β”‚   └── flight.py           #    Flight data schema
β”‚   β”œβ”€β”€ middleware.py           # πŸ›‘οΈ Security middleware (prompt injection detection)
β”‚   └── exceptions.py           # ⚠️ Global exception handling
β”œβ”€β”€ tests/                      # πŸ§ͺ Unit tests (pytest)
β”œβ”€β”€ frontend/                   # 🎨 Next.js + CopilotKit
β”‚   └── src/app/
β”‚       β”œβ”€β”€ layout.tsx          #    App layout with CopilotKit provider
β”‚       β”œβ”€β”€ page.tsx            #    Chat UI component
β”‚       └── api/copilotkit/     #    API route (proxy to backend via AG-UI)
β”œβ”€β”€ terraform/                  # πŸ—οΈ Infrastructure as Code
β”‚   β”œβ”€β”€ main.tf                 #    Azure resource definitions
β”‚   β”œβ”€β”€ variables.tf            #    Configurable variables
β”‚   β”œβ”€β”€ outputs.tf              #    Resource outputs (URLs, keys, etc.)
β”‚   └── README.md               #    Terraform usage guide
β”œβ”€β”€ docker-compose.yml          # 🐳 Local development (one command)
└── Dockerfile                  # πŸ“¦ Backend container

πŸš€ Quick Start

Prerequisites

  • Python 3.13 + uv
  • Docker & Docker Compose
  • Azure CLI (az login)
  • Azure OpenAI resource

1. Clone and Configure

git clone https://github.com/xxyckiki/MAF-AGUI-Azure-Template.git
cd MAF-AGUI-Azure-Template

# Copy environment variables
cp .env.example .env

# Edit .env with your Azure OpenAI settings

2. Start with Docker Compose

docker-compose up --build

This starts:

3. Open the App

Visit http://localhost:3000 and start chatting!

πŸ’» Development

Backend

uv sync                              # Install dependencies
uv run uvicorn main:app --reload     # Run server
uv run pytest -v                     # Run tests

Frontend

cd frontend
npm install --legacy-peer-deps       # Install dependencies
npm run dev                          # Run dev server

☁️ Azure Deployment

Deploy entire infrastructure with Terraform:

cd terraform

# Configure variables
cp terraform.tfvars.example terraform.tfvars
# Edit terraform.tfvars with your subscription ID

# Deploy
terraform init
terraform plan
terraform apply

# Get all configuration values (API keys, endpoints, etc.)
terraform output

See terraform/README.md for detailed instructions.

Option 2: Manual Deployment

This template can also be deployed manually using Azure Portal or CLI.

Azure Resources

ComponentAzure ServiceAuth
BackendContainer AppsManaged Identity
FrontendStatic Web Apps-
Container RegistryAzure Container RegistryAdmin / Managed Identity
LLMAzure OpenAIManaged Identity
DatabaseCosmos DB (NoSQL)Key or Managed Identity
MonitoringOpenTelemetry β†’ Application InsightsConnection String
CI/CDGitHub ActionsFederated Identity

πŸ“š Tech Stack

πŸ“„ License

Apache 2.0