# ADR-015: AI Integration Architecture for Intelligent Infrastructure Provisioning\n\n## Status\n\n**Accepted** - 2025-01-08\n\n## Context\n\nThe provisioning platform has evolved to include complex workflows for infrastructure configuration, deployment, and management.\nCurrent interaction patterns require deep technical knowledge of Nickel schemas, cloud provider APIs, networking concepts, and security best practices.\nThis creates barriers to entry and slows down infrastructure provisioning for operators who are not infrastructure experts.\n\n### The Infrastructure Complexity Problem\n\n**Current state challenges**:\n\n1. **Knowledge Barrier**: Deep Nickel, cloud, and networking expertise required\n - Understanding Nickel type system and contracts\n - Knowing cloud provider resource relationships\n - Configuring security policies correctly\n - Debugging deployment failures\n\n2. **Manual Configuration**: All configs hand-written\n - Repetitive boilerplate for common patterns\n - Easy to make mistakes (typos, missing fields)\n - No intelligent suggestions or autocomplete\n - Trial-and-error debugging\n\n3. **Limited Assistance**: No contextual help\n - Documentation is separate from workflow\n - No explanation of validation errors\n - No suggestions for fixing issues\n - No learning from past deployments\n\n4. **Troubleshooting Difficulty**: Manual log analysis\n - Deployment failures require expert analysis\n - No automated root cause detection\n - No suggested fixes based on similar issues\n - Long time-to-resolution\n\n### AI Integration Opportunities\n\n1. **Natural Language to Configuration**:\n - User: "Create a production PostgreSQL cluster with encryption and daily backups"\n - AI: Generates validated Nickel configuration\n\n2. **AI-Assisted Form Filling**:\n - User starts typing in typdialog web form\n - AI suggests values based on context\n - AI explains validation errors in plain language\n\n3. **Intelligent Troubleshooting**:\n - Deployment fails\n - AI analyzes logs and suggests fixes\n - AI generates corrected configuration\n\n4. **Configuration Optimization**:\n - AI analyzes workload patterns\n - AI suggests performance improvements\n - AI detects security misconfigurations\n\n5. **Learning from Operations**:\n - AI indexes past deployments\n - AI suggests configurations based on similar workloads\n - AI predicts potential issues\n\n### AI Components Overview\n\nThe system integrates multiple AI components:\n\n1. **typdialog-ai**: AI-assisted form interactions\n2. **typdialog-ag**: AI agents for autonomous operations\n3. **typdialog-prov-gen**: AI-powered configuration generation\n4. **platform/crates/ai-service**: Core AI service backend\n5. **platform/crates/mcp-server**: Model Context Protocol server\n6. **platform/crates/rag**: Retrieval-Augmented Generation system\n\n### Requirements for AI Integration\n\n- ✅ **Natural Language Understanding**: Parse user intent from free-form text\n- ✅ **Schema-Aware Generation**: Generate valid Nickel configurations\n- ✅ **Context Retrieval**: Access documentation, schemas, past deployments\n- ✅ **Security Enforcement**: Cedar policies control AI access\n- ✅ **Human-in-the-Loop**: All AI actions require human approval\n- ✅ **Audit Trail**: Complete logging of AI operations\n- ✅ **Multi-Provider Support**: OpenAI, Anthropic, local models\n- ✅ **Cost Control**: Rate limiting and budget management\n- ✅ **Observability**: Trace AI decisions and reasoning\n\n## Decision\n\nIntegrate a **comprehensive AI system** consisting of:\n\n1. **AI-Assisted Interfaces** (typdialog-ai)\n2. **Autonomous AI Agents** (typdialog-ag)\n3. **AI Configuration Generator** (typdialog-prov-gen)\n4. **Core AI Infrastructure** (ai-service, mcp-server, rag)\n\nAll AI components are **schema-aware**, **security-enforced**, and **human-supervised**.\n\n### Architecture Diagram\n\n```\n┌────────────────────────────────────────────