In this article, we will demonstrate how to build an AI agent chatbot with n8n (for automation and text chat), Elevenlabs (for voice chat), and InfraNodus (for GraphRAG knowledge base "experts" used in the n8n automation flow).
This chatbot can then be made available as a popup chat widget to any website, enabling your visitors to chat with your content using text, voice, or even the InfraNodus knowledge graph.
You can test how it works at https://polysingularity.com/category/books/
In this example, we have a section of a website — Polysingularity — which presents 4 books by the same author. These books can be bought online but the visitors of the website can also interact with them using
- a text chat conversation (via n8n chat)
- a voice chat conversation (via ElevenLabs conversational AI agent)
- via the InfraNodus graph
Every book is made available to the n8n AI agent using an InfraNodus API node endpoint that will be triggered by the agent in case the user's request is relevant to that book.
The responses are then aggregated from all the books to provide the final answer to the user. You can read more about the "experts" workflow we use here at Build a Custom Knowledge Base Graph RAG AI Chatbot with n8n
As a result, the user gets a precise response about the books via a simple web widget that can be integrated to any website.
Tools Required
In order to activate this workflow, you will need:
- an InfraNodus account to create a knowledge graph "expert" for each book
- an n8n account to build the AI agent workflow
- an ElevenLabs account to create a conversation AI chatbot
- use our free https://www.popupchat.dev/ widget to get the embed widget for your website
Step 1: Create a Graph for Each Book in InfraNodus
First, you need to create a graph for every book in InfraNodus. In order to do that, create an account at www.infranodus.com and then upload each book (PDF or any other format) to a new graph.
For instance, in our case, we will have four graphs, each of them will look something like this:
Each of the graphs is now available via the InfraNodus API endpoint using the internal Graph RAG system to use in your n8n workflows as AI agent "tool" for that particular topic.
Note, that you can generate a prompt enhancer in the Project Notes > Generate Augmented RAG Prompt and later use it in your n8n tool description to improve results.
Step 2: Create a Simple Text Chatbot Workflow in n8n
The first step is to create a simple knowledge base workflow in n8n. You can follow the instructions at Build a Custom Knowledge Base Graph RAG AI Chatbot with n8n or use this public n8n template:
The workflow will perform the following steps:
- receive a request from a text chatbot endpoint
- send it to AI agent
- the AI agent uses the OpenAI model to decide which "expert" knowledge graph "tool" to consult
- the AI agent contacts each tool (via the InfraNodus API) that connects to your InfraNodus graph and provides back a response along with a collection of relevant statements
- the final response is synthesized by the agent and delivered back to the user
Note: Go to the "When chat message received" node (#1) and change it to the Embed mode to later be able to embed it to your website.
Step 3: Create a Webhook Chat Workflow for ElevenLabs Voice Chat
We will now create a duplicate workflow for the use with ElevenLabs conversational AI voice agent.
Simply duplicate the workflow above, and once you're done, replace the Chat Trigger node with the Webhook node. Make sure that webhook is set to Respond to Webhook mode and then in the panel 3 add the Respond to webhook node and attach it to the AI agent node. You can find this workflow in our GitHub repo: https://github.com/infranodus/n8n-infranodus-workflow-templates
This scenario will ensure that when you will be able to submit a request to this workflow through a webhook (a URL) and then once the response is produced, it'll be send to the same webhook.
We will then make this template available as a tool to the ElevenLabs conversational AI agent in order to enable this knowledge to be queried by the ElevenLabs voice agent.
Step 4: Set up the ElevenLabs Conversational AI Agent
In order to enable our users to have a voice chat conversation with our content, we will need to use an existing voice chat solution. The easiest one to set up that works decently well is the solution from ElevenLabs. They have the Conversational AI agent which is embeddable on a website and can work similarly to the ChatGPT voice mode, emulating an almost real-life conversational dynamics.
In order to set this up, we will need to:
1. Create an account at https://elevenlabs.io/
2. Go to the Conversational AI section in the menu
3. Go to Agent > Create New Agent > Use Blank Template
4. In the System Prompt of the agent put the following text modified to relate to your content:
You are well-versed on ... through the tools you have access to.
1) When you receive a user's message, first answer something like "I am consulting my knowledge and will respond soon" or "let me think about it and i'll get back to you" or any other similar in meaning phrase
2) Then forward the user's message, without any changes, to the knowledge_base tool.
3) When you receive a response from the knowledge_base use this answer to respond to the user, use exactly the answer you received to respond.
IMPORTANT: make the response more suitable for the conversational format making it more succint and shorter but maintaining all the specifics.
NOTE: keep the reference to the `knowledge_base` tool as above to let the ElevenLabs agent know that it's exactly that tool it needs to be using to access the knowledge. Replace ... with your content.
5. In the Tools section of the Agent's setup, click Create a new tool
6. The name of the tool should be: `knowledge_base` (as you're referring to it in the system prompt)
7. In the tool's description put in: "A knowledge base on ...." (replace ... with your topic)
8. Choose the POST method and in the URL put the Webhook link from the n8n workflow you created in the Step 3 above. E.g. https://infranodus.app.n8n.cloud/webhook/your_hook_url
9. Scroll to the Body Parameters and add the following parameters that will be submitted with the POST request:
a. Identifier: prompt, Value type: LLM prompt, Description: The user's message
You will use this in the AI agent node to feed the user's prompt from `json.body.prompt` to the model
b. Identifier: sessionId, Value type: Dynamic variable, Variable name: system__conversation_id
You will use this in the Chat Memory node to keep the history of the conversation by referring to `json.body.sessionId` variable
10. Save the tool, save the agent
11. Run the test in ElevenLabs
12. Check the n8n workflow logs (from Step 3) to see if the execution went well
You could ask: why not use ElevenLabs' own knowledge base and upload all the books there? Well, if you do that, you wouldn't have such a good separation of source materials as ElevenLabs knowledge would consider it as one pool of information, so it would be hard to separate the responses by separate books. Another big problem is that ElevenLabs uses RAG under the hood, while our setup above uses GraphRAG, which has a holistic understanding of the main topics in the content and also can retrieve complex relations. Finally, when you need to update your workflows, you'd need to upload the new files both to the InfraNodus graphs (as you have other n8n workflows running with them) as well as upload them to ElevenLabs. Whereas with the workflow we propose, all your data is stored in InfraNodus.
Step 5: Finally — Embed the Text / Voice Chat to Your Website
Now that the text and voice chats are ready and they consistently consult your panel of experts, you can embed them to your website.
In order to do this, you can use our free service https://popupchat.dev — it enables you to create an embeddable widget that will have links to the text chat, voice chat, the InfraNodus graph, and a Telegram chat.
This makes you quite flexible in terms of the tools you use and you can always replace one tool with another. For instance, if you decide to use Dify instead of n8n for text chats or if you decide to use just the Telegram bot and the ElevenLabs voice chat for instance.
Paste the following data into the Embed Code Generator:
- Your n8n chatbot Embed endpoint from the Step 2
- Your ElevenLabs Conversational AI chatbot URL (can be obtained at the top right — Copy link)
- Your InfraNodus graph link (you can create a new graph with all the books combined for it)
- A link to your Telegram bot (if applicable)
Comments
0 comments
Please sign in to leave a comment.