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.

π 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:
- Queries flight prices between cities
- 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
| Category | Features |
|---|---|
| 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:
- Backend: http://localhost:8000
- Frontend: http://localhost:3000
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
Option 1: Terraform (Recommended - One Command 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
| Component | Azure Service | Auth |
|---|---|---|
| Backend | Container Apps | Managed Identity |
| Frontend | Static Web Apps | - |
| Container Registry | Azure Container Registry | Admin / Managed Identity |
| LLM | Azure OpenAI | Managed Identity |
| Database | Cosmos DB (NoSQL) | Key or Managed Identity |
| Monitoring | OpenTelemetry β Application Insights | Connection String |
| CI/CD | GitHub Actions | Federated Identity |
π Tech Stack
- Microsoft Agent Framework - AI Agent orchestration
- CopilotKit - React chat UI + AG-UI protocol
- FastAPI - Python web framework
- Next.js - React framework
- Azure OpenAI - LLM backend
- Azure Cosmos DB - NoSQL database
- OpenTelemetry - Observability
π License
Apache 2.0