{
  "meta": {
    "creator": "Lucas Peyrin",
    "fingerprint": "<redacted-credential>"
  },
  "nodes": [
    {
      "id": "180a023e-a350-4315-a7f2-968d052f634d",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "onError": "continueErrorOutput",
      "position": [
        288,
        -16
      ],
      "parameters": {
        "text": "Only output \"test\".",
        "options": {},
        "promptType": "define"
      },
      "typeVersion": 2
    },
    {
      "id": "32f3f1ad-8e72-427b-9bcf-0686ae3c4c5c",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "Agent Variables",
      "type": "n8n-nodes-base.set",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        -48,
        -16
      ],
      "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",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "Fallback Models",
      "type": "@n8n/n8n-nodes-langchain.code",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        288,
        512
      ],
      "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",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "First Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        304,
        704
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o",
          "cachedResultName": "gpt-4o"
        },
        "options": {}
      },
      "typeVersion": 1.2
    },
    {
      "id": "75ce0d64-dcbd-47bf-a15b-802fa979333a",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "Falback Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        432,
        704
      ],
      "parameters": {
        "options": {},
        "modelName": "models/gemma-3-27b-it"
      },
      "typeVersion": 1
    },
    {
      "id": "10efe391-496f-45db-ae13-52324b41b4ff",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        208,
        208
      ],
      "parameters": {
        "color": 6,
        "width": 420,
        "height": 640,
        "content": "### \u2699\ufe0f CONFIGURE YOUR FALLBACK CHAIN HERE \u2699\ufe0f\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",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        240,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 340,
        "height": 320,
        "content": "#### \ud83d\udcdd 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",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        -176,
        -240
      ],
      "parameters": {
        "color": 7,
        "width": 400,
        "height": 320,
        "content": "#### \ud83d\udd01 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",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "Manual Trigger",
      "type": "n8n-nodes-base.manualTrigger",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        -320,
        -16
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "0c0620d5-64fc-432a-bb22-84d7a4134f4b",
      "cid": "Ikx1Y2FzIFBleXJpbiI",
      "name": "Sticky Note10",
      "type": "n8n-nodes-base.stickyNote",
      "notes": "\u00a9 2025 Lucas Peyrin",
      "creator": "Lucas Peyrin",
      "position": [
        704,
        -240
      ],
      "parameters": {
        "color": 4,
        "width": 540,
        "height": 800,
        "content": "## Was this helpful? Let me know!\n\nI really hope this template helped you understand how Langchain code works here in n8n. Your feedback is incredibly valuable and helps me create better resources for the n8n community.\n\n### **Share Your Thoughts & Ideas**\n\nWhether you have a suggestion, found a typo, or just want to say thanks, I'd love to hear from you!\nHere's a simple n8n form built for this purpose:\n\n#### \u27a1\ufe0f **[Click here to give feedback](https://api.ia2s.app/form/templates/feedback?template=Fallback%20Agent)**\n\n### **Ready to Build Something Great?**\n\nIf you're looking to take your n8n skills or business automation to the next level, I can help.\n\n**\ud83c\udf93 n8n Coaching:** Want to become an n8n pro? I offer one-on-one coaching sessions to help you master workflows, tackle specific problems, and build with confidence.\n#### \u27a1\ufe0f **[Book a Coaching Session](https://api.ia2s.app/form/templates/coaching?template=Fallback%20Agent)**\n\n**\ud83d\udcbc n8n Consulting:** Have a complex project, an integration challenge, or need a custom workflow built for your business? Let's work together to create a powerful automation solution.\n#### \u27a1\ufe0f **[Inquire About Consulting Services](https://api.ia2s.app/form/templates/consulting?template=Fallback%20Agent)**\n\n---\n\nHappy Automating!\nLucas Peyrin"
      },
      "typeVersion": 1
    }
  ],
  "connections": {
    "AI Agent": {
      "main": [
        [],
        [
          {
            "node": "Agent Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "First Model": {
      "ai_languageModel": [
        [
          {
            "node": "Fallback Models",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Falback Model": {
      "ai_languageModel": [
        [
          {
            "node": "Fallback Models",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Manual Trigger": {
      "main": [
        [
          {
            "node": "Agent Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Agent Variables": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fallback Models": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}