Construire des workflows IA résilients avec une chaîne de basculement automatique GPT et Gemini

Intermédiaire

Ceci est unAIworkflow d'automatisation du domainecontenant 9 nœuds.Utilise principalement des nœuds comme Set, ManualTrigger, Code, Agent, LmChatOpenAi, combinant la technologie d'intelligence artificielle pour une automatisation intelligente. Construire des workflows IA résilients avec Auto-GPT et une chaîne de basculement Gemini

Prérequis
  • Clé API OpenAI
  • Clé API Google Gemini
Aperçu du workflow
Visualisation des connexions entre les nœuds, avec support du zoom et du déplacement
Exporter le workflow
Copiez la configuration JSON suivante dans n8n pour importer et utiliser ce workflow
{
  "meta": {
    "instanceId": "e409ea34548a2afe2dffba31130cd1cf2e98ebe2afaeed2a63caf2a0582d1da0"
  },
  "nodes": [
    {
      "id": "180a023e-a350-4315-a7f2-968d052f634d",
      "name": "Agent IA",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "onError": "continueErrorOutput",
      "position": [
        280,
        -20
      ],
      "parameters": {
        "text": "Only output \"test\".",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "32f3f1ad-8e72-427b-9bcf-0686ae3c4c5c",
      "name": "Variables de l'agent",
      "type": "n8n-nodes-base.set",
      "position": [
        -40,
        -20
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "38ce3db6-ce1d-4091-9645-39e674ad1782",
              "name": "models",
              "type": "array",
              "value": "[\"gemini-2.5-flash\"]"
            },
            {
              "id": "151da1bf-a82a-40a9-bca2-a85ab48f1c5b",
              "name": "fail_count",
              "type": "number",
              "value": "={{ $('Agent Variables')?.isExecuted ? $('Agent Variables').last()?.json?.fail_count + 1 : 0 }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "2d7804a4-3744-4866-89b2-705bbec66acc",
      "name": "Modèles de secours",
      "type": "@n8n/n8n-nodes-langchain.code",
      "position": [
        280,
        500
      ],
      "parameters": {
        "code": {
          "supplyData": {
            "code": "let llms = await this.getInputConnectionData('ai_languageModel', 0);\nllms.reverse(); // reverse array, so the order matches the UI elements\n\nconst llm_index = $input.item.json.fail_count;\n\nif (!Number.isInteger(llm_index)) {\n  console.log(\"'llm_index' is udefined or not a valid integer\");\n  throw new Error(\"'llm_index' is udefined or not a valid integer\");\n}\n\nif(typeof llms[llm_index] === 'undefined') {\n  console.log(`No LLM found with index ${llm_index}`);\n  throw new Error(`No LLM found with index ${llm_index}`);\n}\n\nreturn llms[llm_index];"
          }
        },
        "inputs": {
          "input": [
            {
              "type": "ai_languageModel",
              "required": true
            }
          ]
        },
        "outputs": {
          "output": [
            {
              "type": "ai_languageModel"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e3d0d416-2571-4e86-b701-27aee1e5856e",
      "name": "Premier modèle",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        300,
        700
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "75ce0d64-dcbd-47bf-a15b-802fa979333a",
      "name": "Modèle de secours",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        420,
        700
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemma-3-27b-it"
      },
      "typeVersion": 1
    },
    {
      "id": "10efe391-496f-45db-ae13-52324b41b4ff",
      "name": "Note adhésive",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        200,
        200
      ],
      "parameters": {
        "color": 6,
        "width": 420,
        "height": 640,
        "content": "### ⚙️ CONFIGURE YOUR FALLBACK CHAIN HERE ⚙️\n\nThis node selects which AI model to use based on the number of previous failures.\n\n**To set up your models:**\n1.  Add your desired AI model nodes to the canvas (OpenAI, Gemini, Anthropic, etc.).\n2.  Connect them to **THIS** node's `ai_languageModel` input.\n\n\n**IMPORTANT:** The **order** you connect them in is the order they will be tried."
      },
      "typeVersion": 1
    },
    {
      "id": "93797015-159e-4e43-bf72-47f0533e92f1",
      "name": "Note adhésive1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        240,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 340,
        "height": 320,
        "content": "#### 📝 DEFINE YOUR PROMPT HERE\n\nEnter the prompt or task for the AI agent in this node.\n\nIt will dynamically use the models provided one-by-one from the `Fallback Models` node. If it fails, it will automatically retry with the next model in your chain."
      },
      "typeVersion": 1
    },
    {
      "id": "4cedd679-70d3-41a2-9bf5-addf8e146c9a",
      "name": "Note adhésive2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -180,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 320,
        "content": "#### 🔁 Loop Controller\n\nThis node manages the retry loop.\n\nIt initializes and increments a `fail_count` variable each time the `AI Agent` fails, which tells the `Fallback Models` node to try the next model in the list.\n\nNo configuration is needed here."
      },
      "typeVersion": 1
    },
    {
      "id": "4b5e9318-16fd-4e69-add6-0edbca278d91",
      "name": "Déclencheur manuel",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -320,
        -20
      ],
      "parameters": {},
      "typeVersion": 1
    }
  ],
  "pinData": {},
  "connections": {
    "180a023e-a350-4315-a7f2-968d052f634d": {
      "main": [
        [],
        [
          {
            "node": "32f3f1ad-8e72-427b-9bcf-0686ae3c4c5c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "e3d0d416-2571-4e86-b701-27aee1e5856e": {
      "ai_languageModel": [
        [
          {
            "node": "2d7804a4-3744-4866-89b2-705bbec66acc",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "75ce0d64-dcbd-47bf-a15b-802fa979333a": {
      "ai_languageModel": [
        [
          {
            "node": "2d7804a4-3744-4866-89b2-705bbec66acc",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "4b5e9318-16fd-4e69-add6-0edbca278d91": {
      "main": [
        [
          {
            "node": "32f3f1ad-8e72-427b-9bcf-0686ae3c4c5c",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "32f3f1ad-8e72-427b-9bcf-0686ae3c4c5c": {
      "main": [
        [
          {
            "node": "180a023e-a350-4315-a7f2-968d052f634d",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "2d7804a4-3744-4866-89b2-705bbec66acc": {
      "ai_languageModel": [
        [
          {
            "node": "180a023e-a350-4315-a7f2-968d052f634d",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}
Foire aux questions

Comment utiliser ce workflow ?

Copiez le code de configuration JSON ci-dessus, créez un nouveau workflow dans votre instance n8n et sélectionnez "Importer depuis le JSON", collez la configuration et modifiez les paramètres d'authentification selon vos besoins.

Dans quelles scénarios ce workflow est-il adapté ?

Intermédiaire - Intelligence Artificielle

Est-ce payant ?

Ce workflow est entièrement gratuit et peut être utilisé directement. Veuillez noter que les services tiers utilisés dans le workflow (comme l'API OpenAI) peuvent nécessiter un paiement de votre part.

Informations sur le workflow
Niveau de difficulté
Intermédiaire
Nombre de nœuds9
Catégorie1
Types de nœuds7
Description de la difficulté

Adapté aux utilisateurs expérimentés, avec des workflows de complexité moyenne contenant 6-15 nœuds

Auteur
Lucas Peyrin

Lucas Peyrin

@lucaspeyrin

Innovative builder with a passion for crafting automation solutions that solve real-world challenges. From streamlining workflows to driving efficiency, my work empowers teams and individuals to achieve more with less effort. Experienced in developing scalable tools and strategies that deliver results with n8n, supabase and cline.

Liens externes
Voir sur n8n.io

Partager ce workflow

Catégories

Catégories: 34