Conversational data collection

Hello friends,

I am trying to replicate a workflow on N8N that I have working fine on a chatbot platform. Relatively new with n8n so please be kind :see_no_evil:

In short, I am trying to create a system that gathers information from users in a conversational manner, verifies that all information has been collected and then outputs a structured output. Think first name, last name, email and zip.

I’ve been able to instruct the agent AI to ask the user and collect the information, but I am stuck at what happens after this point. I would want to check if all fields have been completed. If so, output the json. If not, loop back to the agent and collect the missing information.

What does this workflow look like after the agent node?

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 @flyover137 !

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!


So, where/how do you store the information? Can’t you just query your storage to devise if any data is yet missing?

Hey @ihortom - I have resolved this with help of the all mighty community forums.

The AI Agent is instructed to collect the information from the user (ie. first name, last name, email and zip) and to output a simple json structure when done. In addition to the 4 required key value pairs, it also includes a key called “status” and a value of “completed”.

The IF statement checks if the json contains the value “completed”. If so, if runs the output to an LLM chain and generates structured data in the exact json format I want. If not, I route it to another LLM chain which repeats the last output from the AI Agent - and loops it back for completion.

This works but if I can make this better or more efficient, I’d love to hear it.

Hey @flyover137 , your solution sounds fine to me. Though I was having in mind checking all the outputs produced by Memory manager for the session in question and checking if there is any missing data the user did not provide yet. This approach would not require an additional “status” field.

That would be better. Does that follow the same logic with an IF node and multiple conditions?

Basically yes. Just bear in mind the output of Memory Manager for the session looks like below

  {
    "messages": [
      {
        "human": "...",
        "ai": "..."
      },
      {
        "human": "...",
        "ai": "..."
      }
    ],
    "messagesCount": 2
  }

You will need to ensure all the questions are in the list messages and they are answered (the messagesCount is as expected, etc).

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