{
  "name": "Chimera: AI Pipeline",
  "nodes": [
    {
      "parameters": {
        "context": "={{ $json.message }}",
        "systemInstruction": "You are an intent classification and entity extraction system for a WhatsApp business bot.\n\nTASK: Analyze the user's message and return a structured JSON object.\n\nINTENT CATEGORIES:\n- greeting, order_status, product_inquiry, booking_request, support_request, payment_question, human_handoff, feedback, unsubscribe, unknown\n\nOUTPUT FORMAT:\n{\n  \"intent\": \"string\",\n  \"confidence\": 0.95,\n  \"entities\": {\n    \"order_id\": \"string|null\",\n    \"product_name\": \"string|null\"\n  },\n  \"sentiment\": \"positive|neutral|negative\",\n  \"urgency\": \"low|normal|high\"\n}",
        "options": {
          "responseMimeType": "application/json"
        }
      },
      "id": "gemini-flash-node",
      "name": "Gemini 2.0 Flash: Extraction",
      "type": "n8n-nodes-base.googleGeminiChat",
      "typeVersion": 1,
      "position": [
        400,
        200
      ]
    },
    {
      "parameters": {
        "url": "https://api.x.ai/v1/chat/completions",
        "method": "POST",
        "authentication": "headerAuth",
        "bodyParameters": {
          "parameters": [
            {
              "name": "model",
              "value": "grok-beta"
            },
            {
              "name": "messages",
              "value": "=[{\"role\": \"system\", \"content\": \"{{ $parameter.systemPrompt }}\"}, {\"role\": \"user\", \"content\": \"{{ $parameter.prompt }}\"}]"
            }
          ]
        }
      },
      "id": "grok-node",
      "name": "Grok: Reasoning & Response",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4,
      "position": [
        650,
        400
      ]
    },
    {
      "parameters": {
        "operation": "insert",
        "table": "intent_log",
        "columns": "message_id, primary_intent, confidence, entities, grok_response, gemini_response",
        "values": "={{ $node[\"Execute AI Pipeline\"].json.messageId }}, {{ $node[\"Gemini 2.0 Flash: Extraction\"].json.intent }}, {{ $node[\"Gemini 2.0 Flash: Extraction\"].json.confidence }}, {{ JSON.stringify($node[\"Gemini 2.0 Flash: Extraction\"].json.entities) }}, {{ JSON.stringify($node[\"Grok: Reasoning & Response\"].json) }}, {{ JSON.stringify($node[\"Gemini 2.0 Flash: Extraction\"].json) }}"
      },
      "id": "db-log-node",
      "name": "Postgres: Log Intent",
      "type": "n8n-nodes-base.postgres",
      "typeVersion": 1,
      "position": [
        900,
        300
      ]
    }
  ],
  "connections": {
    "Gemini 2.0 Flash: Extraction": {
      "main": [
        [
          {
            "node": "Grok: Reasoning & Response",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Grok: Reasoning & Response": {
      "main": [
        [
          {
            "node": "Postgres: Log Intent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}