I’m building an iterative blog post optimization loop in n8n using AI Agent nodes.
First, an AI Agent creates the initial blog post ($json.blogBeitrag).
Then, the post is evaluated by another AI Agent (persona) and if needed, optimized by a third AI Agent (Blog Optimierer)
After the optimization, I want the persona to evaluate the new version, not the first (original) one.
My problem:
If I connect both the original Set node (with blogBeitrag) and the optimized Set node to the persona AI Agent node, n8n treats them as two separate input items, and the persona doesn’t know which to prioritize.
My questions:
What is the best way to make sure the persona AI Agent always uses only the latest blogBeitrag in each iteration?
How can I ensure that the original blog post is used only once (on the first run) and then always the optimized version afterward?
Should I use an IF or Merge node for this, or is there a simpler “single source of truth” pattern?
I really would appreciate any help from you guys.
Many thx
Tobi
If one of your AI Agents gets two items (both are texts, but one is optimized and another is not optimized), you need to merge them first (with combine), so that they come as a single input item.
Unless I misunderstood your explanation (if so, please try again).
thx for your reply.
But how should i handle it, when the first loop has only one input from the first “Zähler” Node and after the first run of the process, there would be two inputs in the merge-node.
And wouldn’t it only create a mix of both inputs with the combine mode?
I Know there is the option to choose input 1 or input 2 (which i want after the first run), but how could i give this logic in the worklfow?
First time you choose the original (input 1) and after that, you always will choose the input 2.
Actually i choose the “dumb way“, that i recreate this process 3 times
(blog creation (first time)→persona (first time)→ optimization 1 → persona (second time) → optimization 2 → persona (third time) ….)
but I’m pretty sure, there is a better way than doing it this way - the loop is my first time doing something like this. I love it and hate it at the same time because I don’t solve the input problem…
Appreciate your help mate!!
Greetings from Germany
In order not to mess with merging and getting last and not the first iteration results, you should probably further divide the flow into separate workflow per action - one to create, one to create, one to run “persona” (whatever that means), then one to do the optimization, then in the main workflow go over the loop and call required sub workflows.