# ADR-037: Unified Prompt Management UX/UI **Status:** Draft **Date:** 2026-06-14 **Decision Makers:** Development Team, System Architect **Supersedes:** ADR-029: Dynamic Prompt Management (extends prompt_type scope) **Related Documents:** - [ADR-027: AI Admin Console and Dynamic Control](./ADR-027-ai-admin-console-and-dynamic-control.md) - [ADR-030: Context-Aware Prompt Templates](./ADR-030-context-aware-prompt-templates.md) - [ADR-036: Unified AI Model Architecture](./ADR-036-unified-ocr-architecture.md) - [ADR-035: AI Pipeline Flow Architecture](./ADR-035-ai-pipeline-flow-architecture.md) --- ## บริบทและปัญหา (Context and Problem Statement) ADR-029 กำหนด architecture สำหรับ prompt management (ai_prompts table, versioning, activation) แต่จำกัด scope ไว้ที่ prompt_type='ocr_extraction' เดียว และไม่ได้ระบุ UX/UI อย่างละเอียด ทำให้เกิดปัญหาดังนี้: 1. **Version History สับสน:** ไม่แยกระหว่าง prompt types (OCR vs AI) ทำให้ admin ไม่รู้ว่า version ไหนใช้สำหรับ workflow ไหน 2. **Sandbox Workflow ไม่ตรง Production:** ปัจจุบันใช้ 2-step flow (OCR → AI Extract) แต่ production ใช้ 3-step flow (OCR → Extract → RAG Prep) ทำให้ sandbox ทดสอบไม่ครบ 3. **Context Config UI ขาดไป:** ADR-030 กำหนด context_config แต่ไม่มี UI สำหรับ View/Edit/Save/Apply ทำให้ไม่สามารถจัดการ context ได้ 4. **Config Types ไม่เคลียร์:** Admin สับสนระหว่าง 3 config types: - Runtime Parameters (temperature, topP, ฯลฯ) - คุม AI model behavior - Context Config (projectId, contractId, ฯลฯ) - คุม data context - System Prompt (AI role/instruction) - คุม AI บทบาท --- ## ปัจัยขับเคลื่อนการตัดสินใจ (Decision Drivers) - **Multi-Type Support:** ระบบต้องรองรับหลาย prompt types (ocr_extraction, rag_query_prompt, rag_prep_prompt, classification_prompt) ตาม ADR-035 flows - **Sandbox-Production Parity:** Sandbox ต้องทดสอบทั้ง pipeline ที่ใช้ใน production (OCR → Extract → RAG Prep) เพื่อให้ผลลัพธ์ตรงความจริง - **Context Config Management:** Admin ต้องสามารถ View/Edit/Save/Apply context_config ได้ผ่าน UI - **Clear Separation:** 3 config types (Runtime Parameters, Context Config, System Prompt) ต้องแยก UI ชัดเจนเพื่อลดความสับสน - **Single Page Layout:** ตาม ADR-027, AI Admin Console ควรเป็น single page layout --- ## ทางเลือกที่ถูกพิจารณา (Considered Options) ### Option 1: แยกหน้าตาม Prompt Type - **ข้อดี:** UI เรียบง่าย แต่ละ prompt type มีหน้าของตัวเอง - **ข้อเสีย:** ไม่ consistent กับ ADR-027 (single page), ยากต่อการเปรียบเทียบระหว่าง types ### Option 2: Single Page พร้อม Prompt Type Dropdown (ตัวเลือกที่ได้รับเลือก) - **ข้อดี:** Consistent กับ ADR-027, ง่ายต่อการเปรียบเทียบ, ลดจำนวน components - **ข้อเสีย:** UI ซับซ้อนขึ้นเล็กน้อย (ต้องจัดการ state หลาย prompt types) --- ## ผลการตัดสินใจ (Decision Outcome) **ทางเลือกที่ได้รับเลือก:** Option 2 — Single Page พร้อม Prompt Type Dropdown --- ## ข้อตกลงหลัก (Core Decisions — Grilling Session 2026-06-14) | # | ประเด็น | การตัดสินใจ | |---|---------|-------------| | 1 | Prompt Type Scope | รองรับ 4 types: ocr_extraction, rag_query_prompt, rag_prep_prompt, classification_prompt | | 2 | Sandbox Workflow | Hybrid flow: OCR → Extract → Optional Review → RAG Prep | | 3 | UX/UI Layout | Single Page พร้อม Prompt Type Dropdown | | 4 | Context Config UI | View/Edit/Save/Apply ครบถ้วน | | 5 | Runtime Parameters UI | แยกจาก Context Config UI ชัดเจน | | 6 | Version History | แยกตาม prompt_type, แสดง active badge, test result | | 7 | Sandbox to Production | สามารถส่งต่อผลลัพธ์ sandbox ไป activate version ได้ | | 8 | Supersede ADR-029 | ใช่ - ขยาย prompt_type scope จากเดียวเป็นหลาย types | --- ## รายละเอียดเชิงสถาปัตยกรรม (Implementation Details) ### 1. Database Schema Changes (ADR-009) **Table: ai_prompts** (มีอยู่แล้วจาก ADR-029, ไม่ต้องเปลี่ยน) - `prompt_type` VARCHAR(50) - รองรับหลาย types - `context_config` JSON NULL - เพิ่มจาก ADR-030 (มีอยู่แล้ว) **Seed Data:** ```sql -- OCR Extraction Prompt (มีอยู่แล้วจาก ADR-029) INSERT INTO ai_prompts (prompt_type, version_number, template, context_config, is_active, created_by) VALUES ('ocr_extraction', 1, '