commit ec581f67da7a3b2dc643997eaab5cb4b55ab8b53 Author: ph34444 Date: Mon Mar 16 15:41:38 2026 +0100 docs: AI support automation design spec and implementation plan diff --git a/.env b/.env new file mode 100644 index 0000000..44d3193 --- /dev/null +++ b/.env @@ -0,0 +1,15 @@ +# DOMAIN_NAME and SUBDOMAIN together determine where n8n will be reachable from +# The top level domain to serve from +DOMAIN_NAME=fft-it.de + +# The subdomain to serve from +SUBDOMAIN=n8n + +# The above example serve n8n at: https://n8n.example.com + +# Optional timezone to set which gets used by Cron and other scheduling nodes +# New York is the default value if not set +GENERIC_TIMEZONE=Europe/Berlin + +# The email address to use for the TLS/SSL certificate creation +SSL_EMAIL=patrick.haas@eks-intec.de \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..1c7a7a6 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,61 @@ +services: + traefik: + image: "traefik" + restart: always + command: + - "--api.insecure=true" + - "--providers.docker=true" + - "--providers.docker.exposedbydefault=false" + - "--entrypoints.web.address=:80" + - "--entrypoints.web.http.redirections.entryPoint.to=websecure" + - "--entrypoints.web.http.redirections.entrypoint.scheme=https" + - "--entrypoints.websecure.address=:443" + - "--certificatesresolvers.mytlschallenge.acme.tlschallenge=true" + - "--certificatesresolvers.mytlschallenge.acme.email=${SSL_EMAIL}" + - "--certificatesresolvers.mytlschallenge.acme.storage=/letsencrypt/acme.json" + ports: + - "80:80" + - "443:443" + volumes: + - traefik_data:/letsencrypt + - /var/run/docker.sock:/var/run/docker.sock:ro + - ./crts:/opt/custom-certificates + + n8n: + image: docker.n8n.io/n8nio/n8n + restart: always + ports: + - "127.0.0.1:5678:5678" + labels: + - traefik.enable=true + - traefik.http.routers.n8n.rule=Host(`${SUBDOMAIN}.${DOMAIN_NAME}`) + - traefik.http.routers.n8n.tls=true + - traefik.http.routers.n8n.entrypoints=web,websecure + - traefik.http.routers.n8n.tls.certresolver=mytlschallenge + - traefik.http.middlewares.n8n.headers.SSLRedirect=true + - traefik.http.middlewares.n8n.headers.STSSeconds=315360000 + - traefik.http.middlewares.n8n.headers.browserXSSFilter=true + - traefik.http.middlewares.n8n.headers.contentTypeNosniff=true + - traefik.http.middlewares.n8n.headers.forceSTSHeader=true + - traefik.http.middlewares.n8n.headers.SSLHost=${DOMAIN_NAME} + - traefik.http.middlewares.n8n.headers.STSIncludeSubdomains=true + - traefik.http.middlewares.n8n.headers.STSPreload=true + - traefik.http.routers.n8n.middlewares=n8n@docker + environment: + - N8N_ENFORCE_SETTINGS_FILE_PERMISSIONS=true + - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME} + - N8N_PORT=5678 + - N8N_PROTOCOL=https + - N8N_RUNNERS_ENABLED=true + - NODE_ENV=production + - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/ + - GENERIC_TIMEZONE=${GENERIC_TIMEZONE} + - TZ=${GENERIC_TIMEZONE} + volumes: + - n8n_data:/home/node/.n8n + - ./local-files:/files + - ./crts:/opt/custom-certificates + +volumes: + n8n_data: + traefik_data: \ No newline at end of file diff --git a/docs/superpowers/plans/2026-03-16-ai-support-automation-plan.md b/docs/superpowers/plans/2026-03-16-ai-support-automation-plan.md new file mode 100644 index 0000000..9c93a7d --- /dev/null +++ b/docs/superpowers/plans/2026-03-16-ai-support-automation-plan.md @@ -0,0 +1,1023 @@ +# AI-gestützte IT-Support-Automatisierung Implementation Plan + +> **For agentic workers:** REQUIRED: Use superpowers:subagent-driven-development or superpowers:executing-plans to implement this plan. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Ein produktives Hybrid-System bauen, das Freescout-Mails analysiert, KI-Vorschläge macht, Mensch-Approval einholt, und eine selbstlernende Wissensdatenbank aufbaut. + +**Architecture:** 4-phasiger Ansatz: +1. **Phase 1 (Setup):** Docker Compose + Vector DB + Freescout Custom Fields +2. **Phase 2 (Workflows):** n8n Workflows A (Mail-Processing), B (Approval), C (KB-Update) +3. **Phase 3 (Integration):** End-to-End Testing + API Connections +4. **Phase 4 (Production):** Monitoring + Dokumentation + Go-Live + +**Tech Stack:** +- **Orchestrierung:** n8n (vorhanden, Docker) +- **Vector DB:** Milvus (Docker) +- **KI:** LiteLLM API (extern: http://llm.eks-ai.apps.asgard.eks-lnx.fft-it.de) +- **Mail-Source:** Freescout API (extern: https://ekshelpdesk.fft-it.de) +- **Job-Execution:** Baramundi Management Server API (extern) +- **Audit Trail:** PostgreSQL (Docker) + +--- + +## Chunk 1: Infrastructure & Setup + +### Task 1.1: Vector Database in Docker Compose integrieren + +**Files:** +- Modify: `compose.yaml` +- Create: `.env.example` (aktualisieren mit neuen Vars) + +- [ ] **Step 1: compose.yaml lesen und Struktur verstehen** + +Schau dir die aktuelle Struktur an (Traefik, n8n). + +- [ ] **Step 2: Milvus Service zu compose.yaml hinzufügen** + +```yaml + milvus: + image: milvusdb/milvus:latest + restart: always + environment: + COMMON_STORAGETYPE: local + COMMON_LOG_LEVEL: info + ports: + - "127.0.0.1:19530:19530" + - "127.0.0.1:9091:9091" + volumes: + - milvus_data:/var/lib/milvus + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:9091/healthz"] + interval: 30s + timeout: 10s + retries: 5 + + postgres: + image: postgres:15-alpine + restart: always + environment: + POSTGRES_DB: n8n_kb + POSTGRES_USER: kb_user + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD} + ports: + - "127.0.0.1:5432:5432" + volumes: + - postgres_data:/var/lib/postgresql/data + healthcheck: + test: ["CMD-SHELL", "pg_isready -U kb_user"] + interval: 10s + timeout: 5s + retries: 5 + +volumes: + traefik_data: + n8n_data: + milvus_data: + postgres_data: +``` + +- [ ] **Step 3: .env mit neuen Variablen aktualisieren** + +```bash +# Existing +SSL_EMAIL=your-email@example.com +SUBDOMAIN=n8n +DOMAIN_NAME=example.com +GENERIC_TIMEZONE=Europe/Berlin + +# New für KB +POSTGRES_PASSWORD=secure_password_change_me +MILVUS_API_URL=http://milvus:19530 +``` + +- [ ] **Step 4: Services starten und healthcheck testen** + +```bash +docker-compose up -d milvus postgres +docker-compose logs -f milvus +# Expected: "Milvus is ready to serve" + +curl http://127.0.0.1:9091/healthz +# Expected: 200 OK +``` + +- [ ] **Step 5: Commit** + +```bash +git add compose.yaml .env.example +git commit -m "infra: add Milvus vector DB and PostgreSQL for KB audit trail" +``` + +--- + +### Task 1.2: PostgreSQL Audit Schema erstellen + +**Files:** +- Create: `sql/01-audit-schema.sql` + +- [ ] **Step 1: Erstelle SQL Schema Datei** + +```sql +-- Audit Trail für KB Updates +CREATE TABLE knowledge_base_updates ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + ticket_id INTEGER NOT NULL, + problem_text TEXT NOT NULL, + kategorie VARCHAR(100), + lösung TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, + approved_at TIMESTAMP, + executed_at TIMESTAMP, + status VARCHAR(50) CHECK (status IN ('PENDING', 'APPROVED', 'REJECTED', 'EXECUTED')), + freescout_note TEXT +); + +CREATE INDEX idx_kbu_ticket ON knowledge_base_updates(ticket_id); +CREATE INDEX idx_kbu_status ON knowledge_base_updates(status); +CREATE INDEX idx_kbu_kategorie ON knowledge_base_updates(kategorie); + +CREATE TABLE kb_feedback ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + kb_entry_id VARCHAR(255) NOT NULL, + feedback VARCHAR(50) CHECK (feedback IN ('helpful', 'not_helpful')), + reason TEXT, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE INDEX idx_kbf_entry ON kb_feedback(kb_entry_id); + +CREATE TABLE workflow_executions ( + id UUID PRIMARY KEY DEFAULT gen_random_uuid(), + workflow_name VARCHAR(255), + ticket_id INTEGER, + status VARCHAR(50), + error_message TEXT, + execution_time_ms INTEGER, + created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +CREATE INDEX idx_we_ticket ON workflow_executions(ticket_id); +CREATE INDEX idx_we_workflow ON workflow_executions(workflow_name); +``` + +- [ ] **Step 2: Initialisiere PostgreSQL mit Schema** + +```bash +docker-compose exec postgres psql -U kb_user -d n8n_kb < sql/01-audit-schema.sql +# Expected: CREATE TABLE, CREATE INDEX messages +``` + +- [ ] **Step 3: Teste Schema** + +```bash +docker-compose exec postgres psql -U kb_user -d n8n_kb -c "\dt" +# Expected: 3 tables angezeigt +``` + +- [ ] **Step 4: Commit** + +```bash +git add sql/01-audit-schema.sql +git commit -m "infra: PostgreSQL audit schema for KB tracking" +``` + +--- + +### Task 1.3: Freescout Custom Fields erstellen (manuell) + +**Dokumentation:** Freescout API Docs + +- [ ] **Step 1: Freescout API Key vorbereiten** + +Erstelle `.env` Eintrag: +```bash +FREESCOUT_API_KEY=your_api_key_here +FREESCOUT_API_BASE=https://ekshelpdesk.fft-it.de/api/v1 +FREESCOUT_MAILBOX_ID=1 +``` + +- [ ] **Step 2: Test Freescout API Verbindung** + +```bash +curl -H "Authorization: Bearer $FREESCOUT_API_KEY" \ + https://ekshelpdesk.fft-it.de/api/v1/mailboxes/1 +# Expected: Mailbox JSON angezeigt +``` + +- [ ] **Step 3: Erstelle Setup-Skript für Custom Fields** + +Datei: `scripts/setup-freescout-fields.sh` + +```bash +#!/bin/bash + +API_BASE="${FREESCOUT_API_BASE}" +API_KEY="${FREESCOUT_API_KEY}" +MAILBOX_ID="${FREESCOUT_MAILBOX_ID}" + +echo "Creating Freescout Custom Fields..." + +# Field 1: AI_SUGGESTION (Text für JSON) +curl -X POST "$API_BASE/mailboxes/$MAILBOX_ID/custom-fields" \ + -H "Authorization: Bearer $API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "AI_SUGGESTION", + "title": "KI-Vorschlag", + "type": "text", + "required": false + }' && echo "✅ AI_SUGGESTION created" + +# Field 2: AI_SUGGESTION_STATUS (Dropdown) +curl -X POST "$API_BASE/mailboxes/$MAILBOX_ID/custom-fields" \ + -H "Authorization: Bearer $API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "AI_SUGGESTION_STATUS", + "title": "KI-Status", + "type": "select", + "required": false, + "options": ["PENDING", "APPROVED", "REJECTED", "EXECUTED"] + }' && echo "✅ AI_SUGGESTION_STATUS created" + +# Field 3: PROCESSED_BY_AI (Boolean) +curl -X POST "$API_BASE/mailboxes/$MAILBOX_ID/custom-fields" \ + -H "Authorization: Bearer $API_KEY" \ + -H "Content-Type: application/json" \ + -d '{ + "name": "PROCESSED_BY_AI", + "title": "Von KI verarbeitet", + "type": "checkbox", + "required": false + }' && echo "✅ PROCESSED_BY_AI created" + +echo "✅ All custom fields created!" +``` + +- [ ] **Step 4: Führe Setup Skript aus** + +```bash +bash scripts/setup-freescout-fields.sh +# Expected: 3x ✅ created +``` + +- [ ] **Step 5: Commit** + +```bash +git add scripts/setup-freescout-fields.sh +git commit -m "scripts: setup Freescout custom fields" +``` + +--- + +## Chunk 2: n8n Workflows Setup & Workflow A (Mail Processing) + +### Task 2.1: n8n Credentials & Collections vorbereiten + +**Files:** +- Create: `n8n-workflows/00-SETUP.md` +- Create: `n8n-workflows/workflow-a-mail-processing.json` + +- [ ] **Step 1: Verstehe n8n Workflow Export Format** + +n8n Workflows werden als JSON exportiert. Struktur: +```json +{ + "name": "Workflow Name", + "nodes": [...], + "connections": {...}, + "active": true +} +``` + +- [ ] **Step 2: Erstelle Setup-Dokumentation** + +Datei: `n8n-workflows/00-SETUP.md` + +```markdown +# n8n Workflows Setup + +## Benötigte Credentials + +1. **Freescout API:** + - Type: HTTP Request (Generic Credentials) + - Base URL: https://ekshelpdesk.fft-it.de/api/v1 + - Auth: Bearer Token (von .env FREESCOUT_API_KEY) + +2. **LiteLLM API:** + - Type: HTTP Request + - Base URL: http://llm.eks-ai.apps.asgard.eks-lnx.fft-it.de + - No auth needed (lokal) + +3. **PostgreSQL:** + - Host: postgres (Docker) + - Port: 5432 + - Database: n8n_kb + - User: kb_user + - Password: (von .env POSTGRES_PASSWORD) + +4. **Milvus:** + - Host: milvus + - Port: 19530 + - No auth + +## Workflow Import + +Importiere folgende Workflows in n8n: +1. workflow-a-mail-processing.json +2. workflow-b-approval-execution.json +3. workflow-c-kb-update.json + +Schalte sie in dieser Reihenfolge an: +1. Workflow A (Mail Processing) – hauptziel +2. Workflow B (Approval) – triggered bei Field-Änderung +3. Workflow C (KB Update) – triggered nach Workflow B +``` + +- [ ] **Step 3: Commit Setup Dokumentation** + +```bash +git add n8n-workflows/00-SETUP.md +git commit -m "docs: n8n setup and credential configuration" +``` + +--- + +### Task 2.2: Workflow A – Mail Processing (Polling + KI-Analyse) + +**Files:** +- Create: `n8n-workflows/workflow-a-mail-processing.json` + +**Logik:** +1. Trigger: Cron (alle 5 Min) +2. Freescout API: neue Tickets fetchen +3. Für jedes Ticket: Vector DB Query + LLM Call +4. Speichere Vorschlag in Freescout + +- [ ] **Step 1: Workflow-Struktur in n8n UI bauen** + +Node 1: **Cron Trigger** +- Cron: `*/5 * * * *` (alle 5 Min) + +Node 2: **Freescoot API – Get Conversations** +- Method: GET +- URL: `https://ekshelpdesk.fft-it.de/api/v1/mailboxes/1/conversations?status=active` +- Auth: Bearer Token +- Params: `status=active&limit=20&processed_by_ai=false` + +Node 3: **Loop through Conversations** +- Use: Loop node über Array aus Node 2 + +Node 4: **Extract Conversation Details** +- Use: Set node um Subject, Body zu extrahieren +```javascript +{ + ticket_id: item.id, + subject: item.subject, + body: item.threads[0].body, + customer_email: item.customer.email +} +``` + +Node 5: **Vector DB Query (Milvus)** +- Python node um ähnliche KB-Einträge zu finden +```python +from pymilvus import Collection + +# Connect to Milvus +collection = Collection("knowledge_base") + +# Search for similar problems +results = collection.search( + data=[embedding_vector], # zu erzeugen via LLM + anns_field="embedding", + param={ + "metric_type": "L2", + "params": {"nprobe": 10} + }, + limit=3, + output_fields=["problem_text", "kategorie", "lösung"] +) + +return results +``` + +Node 6: **LLM Call (LiteLLM)** +- HTTP Request zu LiteLLM +- Method: POST +- URL: `http://llm.eks-ai.apps.asgard.eks-lnx.fft-it.de/v1/chat/completions` +- Body: +```json +{ + "model": "available-model", + "messages": [ + { + "role": "system", + "content": "Du bist IT-Support-Assistent..." + }, + { + "role": "user", + "content": "Ticket: [subject]\n[body]\n\nÄhnliche Lösungen aus KB: [top 3 results]" + } + ], + "temperature": 0.3 +} +``` + +Node 7: **Parse LLM Response** +- Extract JSON aus response +```javascript +{ + kategorie: json.kategorie, + lösung_typ: json.lösung_typ, + vertrauen: json.vertrauen, + antwort_text: json.antwort_text, + begründung: json.begründung +} +``` + +Node 8: **Save to Freescout (Custom Fields)** +- HTTP Request +- Method: PUT +- URL: `https://ekshelpdesk.fft-it.de/api/v1/conversations/{ticket_id}` +- Body: +```json +{ + "custom_fields": { + "AI_SUGGESTION": "{{$node[\"Parse LLM Response\"].json}}", + "AI_SUGGESTION_STATUS": "PENDING", + "PROCESSED_BY_AI": true + } +} +``` + +- [ ] **Step 2: Exportiere Workflow als JSON** + +In n8n: Menu → Export → Full Workflow JSON +Speichere als `n8n-workflows/workflow-a-mail-processing.json` + +- [ ] **Step 3: Teste Workflow manuell** + +- Starte Workflow manuell (Test-Button) +- Check Freescout UI: neue Custom Fields angezeigt? +- Check n8n Logs auf Fehler + +- [ ] **Step 4: Aktiviere Cron Trigger** + +Schalte Workflow an. Sollte jetzt alle 5 Min laufen. + +- [ ] **Step 5: Commit** + +```bash +git add n8n-workflows/workflow-a-mail-processing.json +git commit -m "feat: workflow A – mail processing and KI analysis" +``` + +--- + +## Chunk 3: Workflow B & C (Approval + KB Update) + +### Task 3.1: Workflow B – Approval & Execution + +**Files:** +- Create: `n8n-workflows/workflow-b-approval-execution.json` + +**Logik:** +1. Trigger: Webhook oder Polling (wenn AI_SUGGESTION_STATUS geändert) +2. Validiere: APPROVED oder REJECTED +3. Wenn APPROVED: Branching + - Baramundi Job? → Baramundi API Call + - Automatische Antwort? → Email senden +4. Trigger Workflow C + +- [ ] **Step 1: Baue Trigger Node** + +Option A: **Webhook Trigger** (empfohlen) +- Freescout muss Webhook supportieren +- Trigger bei Field-Änderung + +Option B: **Polling via HTTP** +- Alle 2 Min abfragen: welche Conversations haben AI_SUGGESTION_STATUS = APPROVED +- Fallback wenn Webhook nicht verfügbar + +Für MVP: **Option B (Polling)** + +- [ ] **Step 2: Baue Approval Check Node** + +HTTP Request zu Freescout: +``` +GET /api/v1/conversations?custom_field_AI_SUGGESTION_STATUS=APPROVED&processed_approval=false +``` + +- [ ] **Step 3: Baue Branching Logic** + +Für jedes approved Ticket: +- Parse AI_SUGGESTION +- Check: ist `lösung_typ == "BARAMUNDI_JOB"` oder `"AUTOMATISCHE_ANTWORT"`? + +- [ ] **Step 4: Baramundi Job Node** + +Wenn Baramundi: +``` +POST /api/jobs (Baramundi Management Server) +{ + "name": "{{$node[...].json.baramundi_job.name}}", + "parameter": {...} +} +``` + +- [ ] **Step 5: Email/Reply Node** + +Wenn Automatische Antwort: +``` +POST /api/v1/conversations/{id}/threads +{ + "from": "support@company.com", + "to": "{{customer_email}}", + "subject": "Re: {{subject}}", + "body": "{{antwort_text}}" +} +``` + +- [ ] **Step 6: Mark as Executed** + +Nach Success: Update Custom Field +``` +PUT /api/v1/conversations/{id} +{ + "custom_fields": { + "AI_SUGGESTION_STATUS": "EXECUTED" + } +} +``` + +- [ ] **Step 7: Trigger Workflow C** + +Webhook Call zu Workflow C: +``` +POST http://n8n:5678/webhook/kb-update +{ + "ticket_id": "...", + "status": "EXECUTED" +} +``` + +- [ ] **Step 8: Exportiere & Teste** + +```bash +# Export Workflow B +# In n8n: Menu → Export + +git add n8n-workflows/workflow-b-approval-execution.json +git commit -m "feat: workflow B – approval gate and execution" +``` + +--- + +### Task 3.2: Workflow C – Knowledge Base Update + +**Files:** +- Create: `n8n-workflows/workflow-c-kb-update.json` + +**Logik:** +1. Trigger: Webhook von Workflow B +2. Hole Lösungs-Details +3. Generiere Embedding (LLM) +4. Speichere in Milvus +5. Update Häufigkeit bestehender Einträge +6. Log in PostgreSQL + +- [ ] **Step 1: Webhook Trigger Node** + +``` +POST http://n8n:5678/webhook/kb-update +``` + +Payload: +```json +{ + "ticket_id": "123", + "problem_text": "...", + "kategorie": "Hardware", + "lösung": "Drucker-Treiber neu installiert" +} +``` + +- [ ] **Step 2: Embedding Generation Node** + +LLM Call für Embedding: +``` +POST http://llm.eks-ai.apps.asgard.eks-lnx.fft-it.de/v1/embeddings +{ + "model": "available", + "input": "Hardware: {{kategorie}} + {{problem_text}}" +} +``` + +- [ ] **Step 3: Milvus Insert Node** + +Python Node: +```python +from pymilvus import Collection +import json + +collection = Collection("knowledge_base") + +entity = { + "id": uuid4(), + "problem_text": "{{problem_text}}", + "kategorie": "{{kategorie}}", + "lösung": "{{lösung}}", + "häufigkeit": 1, + "embedding": embedding_vector, + "timestamp": datetime.now(), + "freescout_ticket_id": ticket_id +} + +collection.insert([entity]) +collection.flush() + +return {"status": "inserted"} +``` + +- [ ] **Step 4: Update Häufigkeit (Optional)** + +Suche ähnliche KB-Einträge und erhöhe deren Häufigkeit: +```python +results = collection.search( + data=[embedding_vector], + limit=5, + threshold=0.85 +) + +for result in results: + # Update entry + collection.delete(id=result.id) + result.häufigkeit += 1 + collection.insert([result]) +``` + +- [ ] **Step 5: PostgreSQL Audit Log Node** + +PostgreSQL Node: +```sql +INSERT INTO knowledge_base_updates + (ticket_id, problem_text, kategorie, lösung, status, created_at, approved_at, executed_at) +VALUES + ('{{ticket_id}}', '{{problem_text}}', '{{kategorie}}', '{{lösung}}', 'EXECUTED', NOW(), NOW(), NOW()) +``` + +- [ ] **Step 6: Error Handling** + +Wenn einer der Steps fehlschlägt: +- Log Error in PostgreSQL +- Notify Admin (optional Email) +- STOP (nicht crashen) + +- [ ] **Step 7: Exportiere & Teste** + +```bash +git add n8n-workflows/workflow-c-kb-update.json +git commit -m "feat: workflow C – knowledge base auto-update" +``` + +--- + +## Chunk 4: Integration, Testing & Production + +### Task 4.1: End-to-End Testing + +**Files:** +- Create: `tests/e2e-test-scenario.md` +- Create: `tests/curl-test-collection.sh` + +- [ ] **Step 1: Schreibe E2E Test Szenario** + +```markdown +# E2E Test: Full Workflow + +## Setup +- Milvus läuft +- PostgreSQL läuft +- n8n läuft +- Freescout erreichbar +- LiteLLM erreichbar + +## Test Steps + +1. **Create Test Ticket in Freescout** + - Subject: "Drucker funktioniert nicht" + - Body: "Jeder Druck-Befehl wird abgelehnt. Fehlercode 5." + - Customer: test@example.com + +2. **Warte 5 Min** (Workflow A Cycle) + - Check n8n Logs: Mail verarbeitet? + - Check Freescout: Custom Field AI_SUGGESTION gefüllt? + +3. **Approve Vorschlag** + - Freescout: AI_SUGGESTION_STATUS = APPROVED + +4. **Warte 2 Min** (Workflow B Cycle) + - Check n8n: Job ausgelöst oder Email gesendet? + - Check Baramundi: Job erstellt? + +5. **Warte 1 Min** (Workflow C Cycle) + - Check PostgreSQL: INSERT in knowledge_base_updates? + - Check Milvus: KB-Eintrag erstellt? + +6. **Vector DB Search Test** + - Query Milvus mit ähnlichem Problem + - Sollte neuen Eintrag finden mit hoher Similarity +``` + +- [ ] **Step 2: Schreibe Test Curl Commands** + +`tests/curl-test-collection.sh`: + +```bash +#!/bin/bash + +echo "=== E2E Test Collection ===" + +# 1. Check Milvus Health +echo "✓ Testing Milvus..." +curl http://127.0.0.1:9091/healthz + +# 2. Check PostgreSQL +echo "✓ Testing PostgreSQL..." +docker-compose exec postgres psql -U kb_user -d n8n_kb -c "SELECT COUNT(*) FROM knowledge_base_updates;" + +# 3. Check Freescout API +echo "✓ Testing Freescout API..." +curl -H "Authorization: Bearer $FREESCOUT_API_KEY" \ + https://ekshelpdesk.fft-it.de/api/v1/mailboxes/1/conversations?limit=5 + +# 4. Check LiteLLM +echo "✓ Testing LiteLLM..." +curl -X POST http://llm.eks-ai.apps.asgard.eks-lnx.fft-it.de/v1/chat/completions \ + -H "Content-Type: application/json" \ + -d '{ + "model": "any", + "messages": [{"role": "user", "content": "test"}] + }' + +echo "=== All tests passed ===" +``` + +- [ ] **Step 3: Führe Tests aus** + +```bash +bash tests/curl-test-collection.sh +# Expected: ✓ All tests passed +``` + +- [ ] **Step 4: Erstelle echtes Test-Ticket in Freescout** + +Manuell oder via Freescout UI: +- Subject: "Drucker funktioniert nicht" +- Body: "Fehlercode 5 beim Drucken" + +Überwache: +- n8n Logs +- Freescout Custom Fields +- PostgreSQL + +- [ ] **Step 5: Commit** + +```bash +git add tests/ +git commit -m "test: E2E test scenarios and curl collection" +``` + +--- + +### Task 4.2: Monitoring & Logging Setup + +**Files:** +- Create: `docker-compose.override.yml` (für Logging) +- Create: `docs/MONITORING.md` + +- [ ] **Step 1: Füge n8n Logging zu Compose hinzu** + +`docker-compose.override.yml`: + +```yaml +services: + n8n: + environment: + - N8N_LOG_LEVEL=debug + - N8N_LOG_OUTPUT=stdout + logging: + driver: "json-file" + options: + max-size: "100m" + max-file: "10" +``` + +- [ ] **Step 2: Erstelle Monitoring Dokumentation** + +`docs/MONITORING.md`: + +```markdown +# Monitoring & Debugging + +## Key Metrics + +1. **Mail Processing Rate** + - N8N Logs: "processed X conversations" + - PostgreSQL: `SELECT COUNT(*) FROM workflow_executions WHERE workflow_name='workflow-a'` + +2. **Approval Rate** + - PostgreSQL: `SELECT status, COUNT(*) FROM knowledge_base_updates GROUP BY status` + - Expected: Meiste APPROVED + +3. **KB Growth** + - Milvus: `SELECT COUNT(*) FROM knowledge_base` (via Python) + - Expected: +1 pro appropierten Ticket + +4. **Error Rate** + - PostgreSQL: `SELECT * FROM workflow_executions WHERE status='ERROR'` + - Expected: < 5% + +## Troubleshooting + +### Workflow A läuft nicht +- Check: Cron trigger aktiv? +- Check: n8n credentials valid? +- Check: Freescout API erreichbar? + +### Workflow B triggert nicht +- Check: AI_SUGGESTION_STATUS im Freescout updatet? +- Check: Polling Interval (2 Min)? + +### Workflow C speichert nicht in KB +- Check: Milvus läuft? +- Check: Embedding generiert? + +## Logs + +```bash +# n8n Logs +docker-compose logs -f n8n + +# PostgreSQL +docker-compose exec postgres psql -U kb_user -d n8n_kb -c "SELECT * FROM workflow_executions LIMIT 10;" + +# Milvus +docker-compose logs -f milvus +``` +``` + +- [ ] **Step 3: Commit** + +```bash +git add docker-compose.override.yml docs/MONITORING.md +git commit -m "infra: logging and monitoring setup" +``` + +--- + +### Task 4.3: Production Dokumentation & Go-Live Checklist + +**Files:** +- Create: `docs/DEPLOYMENT.md` +- Create: `docs/GO-LIVE-CHECKLIST.md` + +- [ ] **Step 1: Schreibe Deployment Guide** + +`docs/DEPLOYMENT.md`: + +```markdown +# Deployment Guide + +## Prerequisites + +- Docker & Docker Compose installed +- Freescout API Key +- Baramundi API Access +- PostgreSQL Backup Strategy + +## Deployment Steps + +1. Clone Repository +2. Setup .env (siehe .env.example) +3. Run Docker Services: `docker-compose up -d` +4. Run DB Schema: `sql/01-audit-schema.sql` +5. Setup Freescout Custom Fields: `bash scripts/setup-freescout-fields.sh` +6. Import n8n Workflows (manual via n8n UI) +7. Run E2E Tests: `bash tests/curl-test-collection.sh` +8. Enable Workflows (schalte alle 3 Workflows an) + +## Monitoring + +See docs/MONITORING.md + +## Rollback + +1. Deaktiviere alle n8n Workflows +2. Lösche PostgreSQL Daten (optional) +3. Setze KB zurück (optional) +``` + +- [ ] **Step 2: Go-Live Checklist** + +`docs/GO-LIVE-CHECKLIST.md`: + +```markdown +# Go-Live Checklist + +## 1 Week Before + +- [ ] E2E Tests durchgeführt (alle ✓) +- [ ] Staging Environment getestet +- [ ] Team Training abgeschlossen +- [ ] Backup-Strategie definiert + +## Go-Live Day + +- [ ] Alle Docker Services laufen +- [ ] All n8n Workflows aktiv +- [ ] Monitoring Dashboard aktiv +- [ ] Backup vor Go-Live + +## Während Launch + +- [ ] Monitor n8n Logs +- [ ] Monitor Freescout +- [ ] Monitor Baramundi Job Queue +- [ ] Alert System aktiv + +## Nach 24h + +- [ ] KI-Vorschläge angezeigt? +- [ ] Approvals funktionieren? +- [ ] Jobs werden ausgelöst? +- [ ] KB wächst? + +## Nach 1 Woche + +- [ ] Statistiken: Wie viele Mails verarbeitet? +- [ ] Wie viele Approvals? +- [ ] Wie viele Baramundi Jobs? +- [ ] Feedback vom Team sammeln +``` + +- [ ] **Step 3: Commit** + +```bash +git add docs/DEPLOYMENT.md docs/GO-LIVE-CHECKLIST.md +git commit -m "docs: deployment and go-live documentation" +``` + +--- + +### Task 4.4: Final Testing & Acceptance + +- [ ] **Step 1: Führe alle E2E Tests durch** + +```bash +bash tests/curl-test-collection.sh +``` + +- [ ] **Step 2: Teste mit echtem Ticket (Staging)** + +Erstelle Test-Ticket in Freescout: +- Subject: "Test: Drucker funktioniert nicht" +- Body: "Fehlercode 5" + +Überwache 15 Min: +- Mail analysiert? +- KI-Vorschlag angezeigt? +- Approve Vorschlag +- Job ausgelöst oder Email gesendet? +- KB aktualisiert? + +- [ ] **Step 3: Dokumentiere Ergebnisse** + +Wenn alles ✓: Go-Live bereit! + +- [ ] **Step 4: Final Commit** + +```bash +git add . +git commit -m "feat: AI-support-automation MVP complete and tested" +``` + +--- + +## Summary + +✅ **Phase 1:** Milvus + PostgreSQL + Freescout Custom Fields +✅ **Phase 2:** Workflow A (Mail Processing) + Workflow B (Approval) + Workflow C (KB Update) +✅ **Phase 3:** E2E Testing + Monitoring +✅ **Phase 4:** Production Ready + +**Status:** Bereit für Implementation via `superpowers:subagent-driven-development` oder `superpowers:executing-plans` + +--- + +## Next Steps + +🚀 **Sollen wir starten?** +- Wenn ja: Nutze `superpowers:executing-plans` um den Plan zu implementieren +- Wenn nein: Änderungen an Plan vornehmen diff --git a/docs/superpowers/specs/2026-03-16-ai-support-automation-design.docx b/docs/superpowers/specs/2026-03-16-ai-support-automation-design.docx new file mode 100644 index 0000000..e5fce1e Binary files /dev/null and b/docs/superpowers/specs/2026-03-16-ai-support-automation-design.docx differ diff --git a/docs/superpowers/specs/2026-03-16-ai-support-automation-design.md b/docs/superpowers/specs/2026-03-16-ai-support-automation-design.md new file mode 100644 index 0000000..1c81db9 --- /dev/null +++ b/docs/superpowers/specs/2026-03-16-ai-support-automation-design.md @@ -0,0 +1,364 @@ +# AI-gestützte IT-Support-Automatisierung mit Wissensdatenbank + +**Datum:** 2026-03-16 +**Status:** Design-Phase abgeschlossen, zur Implementation bereit +**Autor:** Team + +--- + +## 1. Problemstellung & Ziel + +**Problem:** Manuelle IT-Support-Tickets in Freescout erfordern manuelle Bearbeitung. Viele wiederkehrende Probleme könnten automatisiert werden, aber lokales KI-Modell ist noch nicht vollständig vertrauenswürdig. + +**Ziel:** Ein Hybrid-System aufbauen, das: +- Eingehende Mails analysiert mit lokalem LLM +- Lösungsvorschläge macht (automatische Behebung oder Baramundi-Job) +- **Mensch genehmigt alle Actions** (Approval-Gate) +- Eine selbstlernende Wissensdatenbank aufbaut und nutzt +- Mit der Zeit immer bessere Vorschläge macht + +**Success-Kriterium:** +- ✅ Mindestens 50% der Tickets werden von KI erkannt +- ✅ Mensch kann innerhalb Freescout approven/rejecten +- ✅ Genehmigt → automatische Ausführung (Baramundi oder Antwort) +- ✅ KB wächst mit jeder genehmigten Lösung + +--- + +## 2. Architektur-Übersicht + +### Komponenten & Technologien + +| Komponente | Technologie | Grund | +|---|---|---| +| **Orchestrierung** | n8n (Docker) | bereits vorhanden, robust | +| **Mail-Quelle** | Freescout API (https://ekshelpdesk.fft-it.de) | direkter API-Zugriff | +| **KI-Engine** | LiteLLM API (http://llm.eks-ai.apps.asgard.eks-lnx.fft-it.de/v1/chat/completions) | lokales, OpenAI-kompatibles Modell | +| **Vector Database** | Milvus oder Weaviate (Docker) | semantische Suche für KB | +| **Knowledge Base** | Vector Embeddings + Metadaten | Problem → Kategorie → Lösung → Häufigkeit | +| **Job-Execution** | Baramundi Management Server API | IT-Jobs auslösen | +| **Approval-UI** | Freescout Notes + Custom Field | Mensch genehmigt direkt in Freescout | +| **Optional Storage** | PostgreSQL (Docker) | Audit Trail, History, Metadaten | + +### System-Datenfluss + +``` +┌─────────────────────────────────────────────────────────────────┐ +│ 1. MAIL-INGESTION & KI-ANALYSE │ +└─────────────────────────────────────────────────────────────────┘ + Freescout (neue Mails) + ↓ + n8n Polling Workflow (alle 5 Min) + ↓ + [Für jedes neue Ticket] + ├→ Vector DB Query: "Ähnliche Probleme finden?" + ├→ LLM-Call mit Mail + KB-Context + ├→ Parse KI-Response + └→ Speichere Vorschlag in Freescout (Note + Custom Field) + +┌─────────────────────────────────────────────────────────────────┐ +│ 2. HUMAN APPROVAL (Mensch-in-the-Loop) │ +└─────────────────────────────────────────────────────────────────┘ + Freescout Ticket zeigt KI-Vorschlag + ↓ + Support-Mitarbeiter liest Vorschlag + ↓ + [Approve] oder [Reject] geklickt + ↓ + Custom Field "AI_SUGGESTION_STATUS" = "APPROVED" / "REJECTED" + +┌─────────────────────────────────────────────────────────────────┐ +│ 3. EXECUTION & KB-UPDATE │ +└─────────────────────────────────────────────────────────────────┘ + n8n Webhook triggert bei Field-Änderung + ├→ Branching: + │ ├─ Baramundi-Job? → Baramundi API Call + │ └─ Automatische Antwort? → Mail/Antwort senden + └→ Bei Success: Lösung in Vector DB speichern + ├─ Generiere Embedding + ├─ Speichere [Problem | Kategorie | Lösung | Häufigkeit] + └─ Update bestehende KB-Einträge (Häufigkeit++) +``` + +--- + +## 3. Workflows (n8n) + +### Workflow A: Mail-Processing & KI-Analyse + +**Trigger:** Cron (alle 5 Minuten) + +**Schritte:** + +1. **Freescout API:** Hole neue, unverarbeitete Tickets + - Endpoint: `GET /api/conversations?status=active&limit=20` + - Filter: `processed_by_ai == false` + +2. **Für jedes Ticket:** + - Extract Mail-Inhalt: `subject`, `body`, `customer_email` + - **Vector DB Query:** Suche semantisch ähnliche Probleme aus KB + - Query: `subject + first 500 chars of body` + - Return: Top 3 Ergebnisse mit Kategorie + Lösung + +3. **LLM-Call** mit: + ```json + { + "system": "Du bist IT-Support-Assistent. Analysiere das Ticket und nutze die KB.", + "user_content": { + "ticket": { "subject": "...", "body": "..." }, + "similar_kb_entries": [ {...}, {...}, {...} ] + } + } + ``` + +4. **Parse Response** (JSON): + ```json + { + "kategorie": "Hardware|Software|Account|Netzwerk|Sonstiges", + "problem_verstanden": "Kurze Zusammenfassung", + "lösung_typ": "BARAMUNDI_JOB | AUTOMATISCHE_ANTWORT | ESKALATION", + "baramundi_job": { + "name": "Job-Name", + "parameter": { "..." } + }, + "antwort_text": "Kundenfreundliche Antwort für Mail...", + "vertrauen": 0.75, + "begründung": "Dieses Problem ist in KB vorhanden..." + } + ``` + +5. **Filter nach Vertrauen:** + - Wenn `vertrauen >= 0.6`: Vorschlag in Freescout speichern + - Wenn `vertrauen < 0.6`: Als "ESKALATION" markieren + +6. **Speichere Vorschlag in Freescout:** + - Note (für Mensch zu lesen): + ``` + [KI-VORSCHLAG] + Kategorie: Hardware + Lösung: Baramundi-Job "Drucker-Treiber-Update" + Vertrauen: 75% + Begründung: ... + ``` + - Custom Field `AI_SUGGESTION`: JSON serialisiert + - Custom Field `AI_SUGGESTION_STATUS`: "PENDING" + +7. **Markiere Ticket:** `processed_by_ai = true` + +--- + +### Workflow B: Approval & Execution + +**Trigger:** Freescout Custom Field `AI_SUGGESTION_STATUS` geändert + +**Schritte:** + +1. **Validiere:** Status ist "APPROVED" oder "REJECTED" + +2. **Wenn REJECTED:** + - Log in PostgreSQL: `{ticket_id, rejected_at, reason}` + - Notify Mensch (optional): "KI-Vorschlag wurde abgelehnt" + - **STOP** + +3. **Wenn APPROVED:** + - Hole KI-Vorschlag aus Custom Field + - Parse `lösung_typ` + +4. **Branching:** + + **A) Wenn `lösung_typ == "BARAMUNDI_JOB"`:** + - Call Baramundi API: + ``` + POST /api/jobs + { + "name": "...", + "parameter": {...} + } + ``` + - Speichere Job-ID in Freescout + - Schreibe Reply-Note: "✅ Baramundi-Job #123 ausgelöst" + + **B) Wenn `lösung_typ == "AUTOMATISCHE_ANTWORT"`:** + - Sende Email an Kunde: + ``` + To: customer_email + Subject: Re: [TICKET_SUBJECT] + Body: [antwort_text aus KI-Response] + ``` + - Schreibe Note in Freescout: "✅ Automatische Antwort gesendet" + - Markiere Ticket als gelöst + + **C) Wenn `lösung_typ == "ESKALATION"`:** + - Markiere für manuelles Review + - Notify Manager + +5. **Bei Success (A oder B):** + - Gehe zu Workflow C (KB-Update) + +--- + +### Workflow C: Knowledge Base Update + +**Trigger:** Nach Workflow B bei Success + +**Schritte:** + +1. **Extracte Info:** + - Problem-Text: `subject + body` + - Kategorie: aus KI-Response + - Lösung: `antwort_text` oder `baramundi_job.name` + - Timestamp: now + +2. **LLM-Embedding generieren:** + - Call LLM API: `/v1/embeddings` + - Input: `category + problem_text` + - Output: `embedding` (vector) + +3. **Vector DB Insert:** + ```json + { + "id": "uuid()", + "problem_text": "Drucker funktioniert nicht", + "kategorie": "Hardware", + "lösung": "Treiber neu installiert via Baramundi", + "häufigkeit": 1, + "embedding": [0.123, -0.456, ...], + "timestamp": "2026-03-16T10:30:00Z", + "baramundi_job_id": "123" (optional), + "freescout_ticket_id": "999" + } + ``` + +4. **Update bestehende KB-Einträge:** + - Query Vector DB: "Finde ähnliche Probleme" + - Für jeden Hit mit Similarity > 0.85: + - `häufigkeit++` + - Update `last_used_at` + +5. **Log in PostgreSQL:** + - `knowledge_base_updates` Tabelle + - Track: wann, was, von welchem Ticket + +6. **Cleanup (optional):** + - Einmal pro Woche: Archiviere alte Einträge (> 1 Jahr, häufigkeit = 0) + +--- + +## 4. Data Structures + +### Freescout Custom Fields (zu erstellen) + +``` +1. AI_SUGGESTION (Text/JSON) + - Speichert KI-Vorschlag als JSON + +2. AI_SUGGESTION_STATUS (Dropdown) + - Werte: PENDING, APPROVED, REJECTED, EXECUTED + +3. PROCESSED_BY_AI (Boolean) + - Markiert ob Mail schon analysiert wurde +``` + +### Vector DB Schema (Milvus/Weaviate) + +```json +{ + "id": "uuid", + "problem_text": "string", + "kategorie": "string", + "lösung": "string", + "häufigkeit": "integer", + "embedding": "vector[1024]", + "timestamp": "datetime", + "freescout_ticket_id": "integer", + "baramundi_job_id": "string (optional)" +} +``` + +### PostgreSQL Schema (optional, für Audit Trail) + +```sql +CREATE TABLE knowledge_base_updates ( + id UUID PRIMARY KEY, + ticket_id INTEGER, + problem_text TEXT, + kategorie VARCHAR, + lösung TEXT, + created_at TIMESTAMP, + approved_at TIMESTAMP, + executed_at TIMESTAMP, + status VARCHAR -- APPROVED, REJECTED, EXECUTED +); + +CREATE TABLE kb_feedback ( + id UUID PRIMARY KEY, + kb_entry_id UUID REFERENCES milvus, + feedback VARCHAR -- helpful, not_helpful + created_at TIMESTAMP +); +``` + +--- + +## 5. Sicherheit & Governance + +### Mensch-in-the-Loop + +- ✅ **Keine automatische Ausführung:** Jede Aktion benötigt manuellen Approval +- ✅ **Vertrauen-Scoring:** Nur Vorschläge mit `vertrauen >= 0.6` werden angezeigt +- ✅ **Audit Trail:** Alle Decisions werden gelogged (wer, wann, was) +- ✅ **Rejection-Tracking:** Abgelehnte Vorschläge werden analysiert → Modell-Improvement + +### Fehlerbehandlung + +- **LLM-Timeout:** Fallback auf "ESKALATION" +- **Baramundi-API-Fehler:** Retry 3x, dann manuelles Review +- **Vector DB Down:** Ignoriere KB-Context, nutze LLM ohne Context +- **Mail-Parsing-Fehler:** Markiere Ticket, notify Mensch + +--- + +## 6. Phasen & Rollout + +### Phase 1: MVP (Woche 1-2) +- ✅ n8n Workflows A (Mail-Processing) + B (Approval) einrichten +- ✅ Freescout API Integration testen +- ✅ LiteLLM Integration testen +- ✅ Manuelle Approval-Flow testen + +### Phase 2: KB Integration (Woche 3) +- ✅ Milvus in Docker deployen +- ✅ Workflow C (KB-Update) einrichten +- ✅ Vector DB Query in Workflow A integrieren + +### Phase 3: Production (Woche 4+) +- ✅ Monitoring + Alerting +- ✅ KB-Cleanup-Jobs +- ✅ Reporting + Analytics + +--- + +## 7. Success Metrics + +| Metrik | Ziel | Messung | +|---|---|---| +| **Mail-Erkennungsrate** | > 50% | (processed_by_ai = true) / total_tickets | +| **Approval-Rate** | > 70% | approved / total_suggested | +| **Baramundi-Job-Success** | > 90% | successful_jobs / total_jobs | +| **KB-Größe** | > 100 Einträge | count(*) from vector_db | +| **Häufigkeits-Improvement** | > 20% weniger Manual-Work | manual_processing_time t1 vs t2 | + +--- + +## 8. Offene Fragen & Next Steps + +- [ ] Welche Baramundi-Jobs sind verfügbar? +- [ ] Freescout API-Key vorhanden? +- [ ] LiteLLM API-Key/Auth Setup? +- [ ] PostgreSQL für Audit Trail gewünscht oder Optional? +- [ ] Milvus oder Weaviate bevorzugt? +- [ ] Wie oft soll KB-Cleanup laufen? + +--- + +**Status:** Bereit für Implementation Plan