How azure/gpt-rag-orchestrator works
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: main.py Python service · agent_provider_v2.py Agent routing · orchestrator.py Conversation orchestrator · foundry_iq.py Azure AI services
Components 23
Backend Runtime
- Python service
src/main.py - Dependency wiring · Builds shared clients and services.
src/dependencies.py - Startup warmup
src/startup_warmup.py - Conversation orchestrator · Normalizes requests and delegates agent execution.
src/orchestration/orchestrator.py - History compaction
src/orchestration/conversation_compaction.py
Agent Strategies
- Strategy factory
src/strategies/agent_strategy_factory.py - Agent strategy contract
src/strategies/base_agent_strategy.py - Agent routing · Selects configured agent providers and implementations.
src/strategies/agent_provider_v2.py - Foundry Agent / MAF
src/strategies/maf_agent_service_strategy.py - OpenAI MAF Lite
src/strategies/maf_lite_strategy.py - Single-agent RAG
src/strategies/single_agent_rag_strategy_v2.py - NL2SQL strategy
src/strategies/nl2sql_strategy.py
Grounding & Data
- Context composition · Composes context providers by retrieval intent.
src/strategies/composite_context_provider.py - Retrieval plugin · Produces grounded context and citations.
src/plugins/retrieval/plugin.py - NL2SQL plugin · Generates validated read-only queries.
src/plugins/nl2sql/plugin.py - SQL validation
src/plugins/nl2sql/sql_validation.py - Cosmos DB history · Stores conversation history and dashboard reporting data.
src/connectors/cosmosdb.py
Admin Dashboard
- Dashboard API · Configuration-gated, role-enforced read-only administration.
src/api/dashboard.py - React dashboard
frontend/src/App.tsx
Azure & Delivery
- Azure AI services · Foundry Agent Service, Foundry IQ, Azure OpenAI, and AI Search.
src/connectors/foundry_iq.py - Identity & user tokens · Provides managed identity and on-behalf-of tokens.
src/connectors/identity_manager.py - Telemetry
src/telemetry/telemetry.py - Container deployment · Packages service and production dashboard assets.
Dockerfile
Connections 26
- 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