This workflow contains community nodes that are only compatible with the self-hosted version of n8n.
This workflow demonstrates how to create a resilient AI Agent that automatically falls back to a different language model if the primary one fails. This is useful for handling API errors, rate limits, or model outages without interrupting your process.
Agent Variables node initializes a fail_count to 0. This counter tracks how many models have been attempted.Fallback Models (a LangChain Code node) acts as a router. It receives a list of all connected AI models and, based on the current fail_count, selects which one to use for this attempt (0 for the first model, 1 for the second, etc.).AI Agent node attempts to run your prompt using the model selected by the router.AI Agent node fails, its "On Error" output is triggered. This path loops back to the Agent Variables node, which increments the fail_count by 1. The process then repeats, causing the Fallback Models router to select the next model in the list.Setup time: ~3-5 minutes
Fallback Models node.AI Agent node and enter the prompt you want to execute.First Model node or configure it with invalid credentials to force an error.

