# azure/gpt-rag-orchestrator architecture

> Architecture diagram of the GitHub repository azure/gpt-rag-orchestrator, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/azure/gpt-rag-orchestrator
- Repository: https://github.com/azure/gpt-rag-orchestrator

## Overview

#### Purpose and runtime
GPT-RAG Orchestrator is a Python 3.12 agentic RAG backend for ChatGPT-style, grounded enterprise Q&A. It coordinates Azure AI Foundry/Agent Service, Azure OpenAI, Azure AI Search/Foundry IQ, SQL sources, and Cosmos DB conversation history. The service entry point is `src/main.py`; dependency wiring and startup behavior live in `src/dependencies.py` and `src/startup_warmup.py`.

#### HTTP API and optional dashboard
The backend exposes the orchestration API and conditionally mounts a read-only admin dashboard when App Configuration enables it. Dashboard API, configuration gating, Cosmos-backed metrics/history access, and role enforcement are concentrated in `src/api/dashboard.py`, `src/api/dashboard_config.py`, and `src/api/config_settings.py`. The React/Vite SPA entry is `frontend/src/main.tsx`, with its top-level UI in `frontend/src/App.tsx` and backend client boundary in `frontend/src/lib/api.ts`.

#### Request orchestration and strategy selection
Incoming conversations are normalized, compacted where needed, and delegated to a configured agent strategy. The central control flow is `src/orchestration/orchestrator.py`; history-size management is `src/orchestration/conversation_compaction.py`. `src/strategies/agent_strategy_factory.py` selects implementations behind the common contract in `src/strategies/base_agent_strategy.py`, separating transport/API concerns from RAG execution choices.

#### Agent strategy layer
Strategy implementations represent materially different execution backends: Foundry Agent Service/MAF, direct Azure OpenAI MAF Lite, MCP, multimodal retrieval, NL2SQL, and single-agent RAG. Core provider/routing abstractions are `src/strategies/agent_provider_v2.py`, `src/strategies/agent_strategies.py`, and `src/strategies/single_agent_rag_strategy_v2.py`. Foundry/MAF and direct-model paths are isolated in `src/strategies/maf_agent_service_strategy.py` and `src/strategies/maf_lite_strategy.py`; SQL execution follows `src/strategies/nl2sql_strategy.py`.

#### Grounding, plugins, and data boundaries
Retrieval plugins produce grounded context and citations; SQL plugins translate natural language to validated, least-privilege read-only queries. These boundaries are implemented by `src/plugins/retrieval/plugin.py`, `src/plugins/nl2sql/plugin.py`, and `src/plugins/nl2sql/sql_validation.py`. Context-provider composition and retrieval intent routing live in `src/strategies/composite_context_provider.py`, `src/strategies/retrieval_intent.py`, and `src/strategies/foundry_iq_context_provider.py`. Remote Microsoft 365 Work IQ requires an on-behalf-of user token, unlike managed-identity-backed local retrieval.

#### Azure integration and persistence
Connector modules encapsulate external-service clients: Foundry IQ/Agent Service, Azure OpenAI, AI Search, Cosmos DB, Key Vault, App Configuration, identity, Fabric, and SQL databases. Key boundaries are `src/connectors/foundry_iq.py`, `src/connectors/openai_chat_client.py`, and `src/connectors/cosmosdb.py`. Conversation history is persisted in Cosmos DB and reused for agent context and dashboard reporting; authentication/token handling is centralized in `src/connectors/identity_manager.py` and `src/util/jwt_utils.py`.

#### Deployment and observability
The container build packages the Python service and production dashboard assets through `Dockerfile`. Azure deployment is defined by `azure.yaml`, `infra/main.bicep`, and deployment scripts under `scripts/`. Telemetry is centralized in `src/telemetry/telemetry.py`; prompt assets are versioned separately under `src/prompts/`, allowing strategy behavior to evolve without changing orchestration structure.

Main entry points: [`src/main.py`](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/main.py) (Python service), [`src/strategies/agent_provider_v2.py`](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/agent_provider_v2.py) (Agent routing), [`src/orchestration/orchestrator.py`](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/orchestration/orchestrator.py) (Conversation orchestrator), [`src/connectors/foundry_iq.py`](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/connectors/foundry_iq.py) (Azure AI services)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Backend Runtime"]
  node_service["Python service<br/>FastAPI entrypoint<br/>[main.py]"]
  node_dependencies["Dependency wiring<br/>startup DI<br/>[dependencies.py]"]
  node_warmup["Startup warmup<br/>startup task<br/>[startup_warmup.py]"]
  node_orchestrator["Conversation orchestrator<br/>request control<br/>[orchestrator.py]"]
  node_compaction["History compaction<br/>context management"]
end

subgraph group_strategies["Agent Strategies"]
  node_strategy_factory["Strategy factory<br/>strategy selection"]
  node_strategy_contract["Agent strategy contract<br/>abstraction"]
  node_agent_routing["Agent routing<br/>provider routing"]
  node_foundry_strategy["Foundry Agent / MAF<br/>agent strategy"]
  node_lite_strategy["OpenAI MAF Lite<br/>agent strategy"]
  node_single_rag["Single-agent RAG<br/>agent strategy"]
  node_nl2sql_strategy["NL2SQL strategy<br/>agent strategy<br/>[nl2sql_strategy.py]"]
end

subgraph group_grounding["Grounding &amp; Data"]
  node_context_provider["Context composition<br/>retrieval routing"]
  node_retrieval_plugin["Retrieval plugin<br/>grounding plugin<br/>[plugin.py]"]
  node_nl2sql_plugin["NL2SQL plugin<br/>SQL boundary<br/>[plugin.py]"]
  node_sql_validation["SQL validation<br/>query guardrail<br/>[sql_validation.py]"]
  node_cosmos[("Cosmos DB history<br/>persistence<br/>[cosmosdb.py]")]
end

subgraph group_dashboard["Admin Dashboard"]
  node_dashboard_api["Dashboard API<br/>optional admin API<br/>[dashboard.py]"]
  node_dashboard_spa["React dashboard<br/>Vite SPA<br/>[App.tsx]"]
end

subgraph group_platform["Azure &amp; Delivery"]
  node_azure_services{{"Azure AI services<br/>external AI<br/>[foundry_iq.py]"}}
  node_identity["Identity &amp; user tokens<br/>authentication"]
  node_telemetry["Telemetry<br/>observability<br/>[telemetry.py]"]
  node_deployment["Container deployment<br/>Azure delivery"]
end

node_service -->|"initializes"| node_dependencies
node_service -->|"runs"| node_warmup
node_service -->|"conversation requests"| node_orchestrator
node_service -.->|"conditionally mounts"| node_dashboard_api
node_orchestrator -->|"manages context size"| node_compaction
node_orchestrator -->|"loads and saves history"| node_cosmos
node_orchestrator -->|"selects execution"| node_strategy_factory
node_strategy_factory -->|"returns"| node_strategy_contract
node_strategy_contract -->|"implemented through"| node_agent_routing
node_agent_routing -->|"Foundry path"| node_foundry_strategy
node_agent_routing -->|"direct model path"| node_lite_strategy
node_agent_routing -->|"RAG path"| node_single_rag
node_agent_routing -->|"SQL path"| node_nl2sql_strategy
node_foundry_strategy -->|"agent service"| node_azure_services
node_lite_strategy -->|"Azure OpenAI"| node_azure_services
node_single_rag -->|"grounds responses"| node_context_provider
node_context_provider -->|"retrieval context"| node_retrieval_plugin
node_retrieval_plugin -->|"Foundry IQ / Search"| node_azure_services
node_nl2sql_strategy -->|"translates questions"| node_nl2sql_plugin
node_nl2sql_plugin -->|"validates queries"| node_sql_validation
node_azure_services -->|"authenticates with"| node_identity
node_dashboard_api -->|"reads history and metrics"| node_cosmos
node_dashboard_spa -->|"read-only API client"| node_dashboard_api
node_service -.->|"emits telemetry"| node_telemetry
node_deployment -->|"packages"| node_service
node_deployment -->|"builds assets"| node_dashboard_spa

click node_service "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/main.py"
click node_dependencies "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/dependencies.py"
click node_warmup "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/startup_warmup.py"
click node_orchestrator "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/orchestration/orchestrator.py"
click node_compaction "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/orchestration/conversation_compaction.py"
click node_strategy_factory "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/agent_strategy_factory.py"
click node_strategy_contract "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/base_agent_strategy.py"
click node_agent_routing "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/agent_provider_v2.py"
click node_foundry_strategy "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/maf_agent_service_strategy.py"
click node_lite_strategy "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/maf_lite_strategy.py"
click node_single_rag "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/single_agent_rag_strategy_v2.py"
click node_nl2sql_strategy "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/nl2sql_strategy.py"
click node_context_provider "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/composite_context_provider.py"
click node_retrieval_plugin "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/plugins/retrieval/plugin.py"
click node_nl2sql_plugin "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/plugins/nl2sql/plugin.py"
click node_sql_validation "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/plugins/nl2sql/sql_validation.py"
click node_azure_services "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/connectors/foundry_iq.py"
click node_cosmos "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/connectors/cosmosdb.py"
click node_identity "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/connectors/identity_manager.py"
click node_dashboard_api "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/api/dashboard.py"
click node_dashboard_spa "https://github.com/azure/gpt-rag-orchestrator/blob/main/frontend/src/App.tsx"
click node_telemetry "https://github.com/azure/gpt-rag-orchestrator/blob/main/src/telemetry/telemetry.py"
click node_deployment "https://github.com/azure/gpt-rag-orchestrator/tree/main/Dockerfile"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_service,node_dependencies,node_warmup,node_orchestrator,node_compaction toneBlue
class node_strategy_factory,node_strategy_contract,node_agent_routing,node_foundry_strategy,node_lite_strategy,node_single_rag,node_nl2sql_strategy toneAmber
class node_context_provider,node_retrieval_plugin,node_nl2sql_plugin,node_sql_validation,node_cosmos toneMint
class node_dashboard_api,node_dashboard_spa toneRose
class node_azure_services,node_identity,node_telemetry,node_deployment toneIndigo
```

## Components

### Backend Runtime

- [Python service](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/main.py): FastAPI entrypoint · `src/main.py`
- [Dependency wiring](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/dependencies.py): startup DI · Builds shared clients and services. · `src/dependencies.py`
- [Startup warmup](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/startup_warmup.py): startup task · `src/startup_warmup.py`
- [Conversation orchestrator](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/orchestration/orchestrator.py): request control · Normalizes requests and delegates agent execution. · `src/orchestration/orchestrator.py`
- [History compaction](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/orchestration/conversation_compaction.py): context management · `src/orchestration/conversation_compaction.py`

### Agent Strategies

- [Strategy factory](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/agent_strategy_factory.py): strategy selection · `src/strategies/agent_strategy_factory.py`
- [Agent strategy contract](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/base_agent_strategy.py): abstraction · `src/strategies/base_agent_strategy.py`
- [Agent routing](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/agent_provider_v2.py): provider routing · Selects configured agent providers and implementations. · `src/strategies/agent_provider_v2.py`
- [Foundry Agent / MAF](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/maf_agent_service_strategy.py): agent strategy · `src/strategies/maf_agent_service_strategy.py`
- [OpenAI MAF Lite](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/maf_lite_strategy.py): agent strategy · `src/strategies/maf_lite_strategy.py`
- [Single-agent RAG](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/single_agent_rag_strategy_v2.py): agent strategy · `src/strategies/single_agent_rag_strategy_v2.py`
- [NL2SQL strategy](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/nl2sql_strategy.py): agent strategy · `src/strategies/nl2sql_strategy.py`

### Grounding & Data

- [Context composition](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/strategies/composite_context_provider.py): retrieval routing · Composes context providers by retrieval intent. · `src/strategies/composite_context_provider.py`
- [Retrieval plugin](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/plugins/retrieval/plugin.py): grounding plugin · Produces grounded context and citations. · `src/plugins/retrieval/plugin.py`
- [NL2SQL plugin](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/plugins/nl2sql/plugin.py): SQL boundary · Generates validated read-only queries. · `src/plugins/nl2sql/plugin.py`
- [SQL validation](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/plugins/nl2sql/sql_validation.py): query guardrail · `src/plugins/nl2sql/sql_validation.py`
- [Cosmos DB history](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/connectors/cosmosdb.py): persistence · Stores conversation history and dashboard reporting data. · `src/connectors/cosmosdb.py`

### Admin Dashboard

- [Dashboard API](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/api/dashboard.py): optional admin API · Configuration-gated, role-enforced read-only administration. · `src/api/dashboard.py`
- [React dashboard](https://github.com/azure/gpt-rag-orchestrator/blob/main/frontend/src/App.tsx): Vite SPA · `frontend/src/App.tsx`

### Azure & Delivery

- [Azure AI services](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/connectors/foundry_iq.py): external AI · Foundry Agent Service, Foundry IQ, Azure OpenAI, and AI Search. · `src/connectors/foundry_iq.py`
- [Identity & user tokens](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/connectors/identity_manager.py): authentication · Provides managed identity and on-behalf-of tokens. · `src/connectors/identity_manager.py`
- [Telemetry](https://github.com/azure/gpt-rag-orchestrator/blob/main/src/telemetry/telemetry.py): observability · `src/telemetry/telemetry.py`
- [Container deployment](https://github.com/azure/gpt-rag-orchestrator/tree/main/Dockerfile): Azure delivery · Packages service and production dashboard assets. · `Dockerfile`

## Connections

- Python service → Dependency wiring: initializes
- Python service → Startup warmup: runs
- Python service → Conversation orchestrator: conversation requests
- Python service → Dashboard API: conditionally mounts
- Conversation orchestrator → History compaction: manages context size
- Conversation orchestrator → Cosmos DB history: loads and saves history
- Conversation orchestrator → Strategy factory: selects execution
- Strategy factory → Agent strategy contract: returns
- Agent strategy contract → Agent routing: implemented through
- Agent routing → Foundry Agent / MAF: Foundry path
- Agent routing → OpenAI MAF Lite: direct model path
- Agent routing → Single-agent RAG: RAG path
- Agent routing → NL2SQL strategy: SQL path
- Foundry Agent / MAF → Azure AI services: agent service
- OpenAI MAF Lite → Azure AI services: Azure OpenAI
- Single-agent RAG → Context composition: grounds responses
- Context composition → Retrieval plugin: retrieval context
- Retrieval plugin → Azure AI services: Foundry IQ / Search
- NL2SQL strategy → NL2SQL plugin: translates questions
- NL2SQL plugin → SQL validation: validates queries
- Azure AI services → Identity & user tokens: authenticates with
- Dashboard API → Cosmos DB history: reads history and metrics
- React dashboard → Dashboard API: read-only API client
- Python service → Telemetry: emits telemetry
- Container deployment → Python service: packages
- Container deployment → React dashboard: builds assets
