{
  "name": "Corrigé 6 - Agent IA & Diagnostic AgroTech",
  "nodes": [
    {
      "parameters": {},
      "id": "4551ff6f-42d5-4cbd-8f78-61b924180cb9",
      "name": "When clicking 'Test workflow'",
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        0,
        112
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "out_source",
              "name": "out_source",
              "value": "Station Météo Web",
              "type": "string"
            },
            {
              "id": "out_subject",
              "name": "out_subject",
              "value": "Risque de Gel",
              "type": "string"
            },
            {
              "id": "out_message",
              "name": "out_message",
              "value": "Chute de température sous -2°C détectée à 05:00",
              "type": "string"
            },
            {
              "id": "out_device_email",
              "name": "out_device_email",
              "value": "emailmaria@hubspot.com",
              "type": "string"
            },
            {
              "id": "out_priority",
              "name": "out_priority",
              "value": "high",
              "type": "string"
            },
            {
              "id": "out_created_at",
              "name": "out_created_at",
              "value": "2026-03-15T06:00:00Z",
              "type": "string"
            },
            {
              "id": "out_farm_owner",
              "name": "out_farm_owner",
              "value": "Maria Johnson",
              "type": "string"
            },
            {
              "id": "out_farm_name",
              "name": "out_farm_name",
              "value": "Domaine des Vignes",
              "type": "string"
            },
            {
              "id": "out_farm_crop_type",
              "name": "out_farm_crop_type",
              "value": "Viticulture Premium",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "id": "98fcfdba-d4a8-442b-a36e-649f46ebe216",
      "name": "Simuler relevé enrichi",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        224,
        112
      ]
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "=Voici les données du relevé agricole entrant à analyser :\n\n- Exploitant : {{ $json.out_farm_owner || 'Client' }}\n- Nom de l'exploitation : {{ $json.out_farm_name || 'Non renseignée' }}\n- Type de culture : {{ $json.out_farm_crop_type || 'Non renseigné' }}\n- Sujet de l'alerte : {{ $json.out_subject }}\n- Message du capteur : {{ $json.out_message }}\n- Priorité détectée : {{ $json.out_priority }}\n\nAnalyse cet incident et fournis la catégorie, le niveau d'escalade et le projet de réponse.",
        "hasOutputParser": true,
        "options": {
          "systemMessage": "=RÈGLES D'ESCALADE (escalation_level) :\n- \"L3\" : Si le message mentionne du gel, une chute de température sous 0°C, une panne générale, OU si la priorité est \"high\".\n- \"L2\" : Si le message concerne un problème technique sur un capteur (ex: batterie faible, problème réseau).\n- \"L1\" : Pour toute question d'information ou problème mineur.\n\nRÈGLES DE CATÉGORIE (category) :\nTu dois choisir EXACTEMENT une valeur parmi : [\"panne_materiel\", \"question_technique\", \"alerte_climatique\", \"facturation\"]."
        }
      },
      "id": "f5dec0b3-fe29-4a31-b7c2-4116f9055d5b",
      "name": "Agent IA Agrotech",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        448,
        112
      ],
      "onError": "continueErrorOutput"
    },
    {
      "parameters": {
        "options": {}
      },
      "id": "0685deac-4bbc-40ca-9d25-0cca81905b68",
      "name": "Mistral Cloud Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatMistralCloud",
      "typeVersion": 1,
      "position": [
        400,
        336
      ],
      "credentials": {
        "mistralCloudApi": {
          "id": "SwViUEKeNJBT3gge",
          "name": "Mistral Cloud account"
        }
      }
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "out_category",
              "name": "out_category",
              "type": "string",
              "value": "={{ $json.output.out_category || 'unknown' }}"
            },
            {
              "id": "out_escalation_level",
              "name": "out_escalation_level",
              "type": "string",
              "value": "={{ $json.output.out_escalation_level || 'L1' }}"
            },
            {
              "id": "out_draft_reply",
              "name": "out_draft_reply",
              "type": "string",
              "value": "={{ $json.output.out_draft_reply || null }}"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "818c97f7-f698-4061-8f46-bdb637a2fc89",
      "name": "Formatage Réponse IA",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        976,
        32
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "out_category",
              "name": "out_category",
              "value": "unknown",
              "type": "string"
            },
            {
              "id": "out_escalation_level",
              "name": "out_escalation_level",
              "value": "L1",
              "type": "string"
            },
            {
              "id": "out_draft_reply",
              "name": "out_draft_reply",
              "value": "={{ null }}",
              "type": "string"
            }
          ]
        },
        "includeOtherFields": true,
        "options": {}
      },
      "id": "aed1b30e-8f01-448c-bd20-d4934e9b8dca",
      "name": "Fallback IA Invalide",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1008,
        288
      ]
    },
    {
      "parameters": {
        "content": "### Corrigé 6 - Qualification & Draft via Agent IA\n\n**Objectif**\nQualifier automatiquement l'alerte agricole et générer un projet de réponse.\n\n**Logique**\n1. Analyse du message et profil de l'exploitation par un LLM.\n2. Structuration forcée via Structured Output Parser (category, escalation_level, draft_reply).\n3. En cas de timeout ou défaillance du LLM, bascule automatique sur 'unknown' / L1 / null.",
        "height": 702,
        "width": 1268,
        "color": 5
      },
      "id": "e676957c-d35e-4577-aa6f-7fcb97942610",
      "name": "Sticky Note a6cd4047",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -48,
        -208
      ]
    },
    {
      "parameters": {
        "jsonSchemaExample": "{\n  \"out_category\": \"alerte_climatique\",\n  \"out_escalation_level\": \"L3\",\n  \"out_draft_reply\": \"Bonjour Maria, nous avons bien pris en compte votre alerte concernant le risque de gel sur le Domaine des Vignes. Une alerte d'arrosage anti-gel a été transmise en urgence à nos équipes.\"\n}"
      },
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "typeVersion": 1.3,
      "position": [
        640,
        336
      ],
      "id": "385d1a2b-3ad6-46b8-941f-255faf9b36b8",
      "name": "Structured Output Parser"
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking 'Test workflow'": {
      "main": [
        [
          {
            "node": "Simuler relevé enrichi",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Simuler relevé enrichi": {
      "main": [
        [
          {
            "node": "Agent IA Agrotech",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent IA Agrotech": {
      "main": [
        [
          {
            "node": "Formatage Réponse IA",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Fallback IA Invalide",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Mistral Cloud Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Agent IA Agrotech",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Agent IA Agrotech",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1",
    "binaryMode": "separate",
    "availableInMCP": true
  },
  "versionId": "5b386555-7781-4ca2-a82e-2583823c3ff5",
  "meta": {
    "aiBuilderAssisted": true,
    "builderVariant": "mcp",
    "instanceId": "ee4605bad6c4b5003dc41d3ea7bedaa9c80198c8426442908a1e821a57858a1d"
  },
  "nodeGroups": [],
  "id": "UwseH41e7wftN2tb",
  "tags": []
}