Is it possible to implement recursive processes?

Hey all :wave: I’m new here, but have quite a bit of programming experience and some low code experience with unreal engine (as a hobby).

I’m trying to translate a piece of code into low code n8n nodes, to better observe the execution flow. This is part of a larger workflow that is getting hard to manage in normal code.

I’d like to share briefly what I’m doing in pseudo code and then rise some questions.

I am extracting user sentiment, pain points and “satisfaction” points from reddit comments and conversation on a given post.

The extraction algorithm in code looks something like this:


Analyze Comments Algorithm
Inputs:

  • the comment to analyze
  • a summary of the post that this comment is a child of
  • a summary of the conversation thread that this comment is a child of. basically if this comment is nested 20 levels deep, I have a short summary of what the 20 ancestor comments were about.

Execution:

  • I take the comment, the summary of the post and the summary of the conversation so far (which is blank initially) and I produce the comment analysis based on the summary of the post, the summary of the conversation if any, and the comment itself.
  • If append the comment to the conversation summary, and if the new summary is larger than 3000 AI tokens I summarize it again.
  • I loop thru all the replies of this comment and call the algorithm again for each reply, with the new conversation summary that was produced.
  • I accumulate all the results from all the replies in a new object that contains the comment insights, and the children execution results

Output:
-I return the object that accumulated the insights for this comment and all the children executions.


What I seem to be missing are

  1. nodes that allow me to define workflow instance variables

Or nodes that give me a way to accumulate values across the execution of the workflow.

For example, I don’t see how I might be able to push different items into an array based on the if branch I am currently on.

  1. the ability to read as input values that are not the immediate outputs of the nodes that were previous in the execution chain.

Is it feasible to implement the algorithm mentioned above in n8n? Would it be easier to follow than typescript code?

If not, would it be feasible to implement a series of custom nodes that might facilitate this functionality? Specifically the workflow instance variables?

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

Welcome to the community @vladnicula !

Tip for sharing information

Pasting your n8n workflow


Ensure to copy your n8n workflow and paste it in the code block, that is in between the pairs of triple backticks, which also could be achieved by clicking </> (preformatted text) in the editor and pasting in your workflow.

```
<your workflow>
```

That implies to any JSON output you would like to share with us.

Make sure that you have removed any sensitive information from your workflow and include dummy or pinned data with it!


Without going into the logic of your workflow, I will try to answer your direct questions.

You can use so-called static data in Code node.

Get familiar with how it is done in n8n, Output of other nodes | n8n Docs.

Hopefully it helps.

Thank you so much for pointing me in the right direction @ihortom .

I’m sharing my progress so far, and will keep updating this topic/post with changes I make along the way. Maybe someone else is trying to achieve a similar thing.

What I noticed so far is that I cannot change the keys used in the loop over. I need to add new keys to the object being changed otherwise the loop over items seems to enter some kind of endless loop.

To simply change the name of the key, you can utilize Rename Keys node. The same could also be achieved with Edit Fields node. The latter is more capable as it also can add/remove the keys.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.