Multi-Agent Chatbot for Database Visualization and QuickCharts - n8n Workflow

Use this comprehensive n8n workflow to build a sophisticated AI chatbot. It connects GPT-4o-mini agents to query Postgres/Supabase databases and generate dynamic data charts via QuickChart.io using advanced n8n node logic.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Data Analysts and Scientists needing instant database insights.
Users of PostgreSQL or Supabase requiring automated data visualization.
n8n developers looking for advanced examples of multi-agent orchestration.
Technical users wanting to leverage the power of the LangChain n8n node suite with tools.

Overview

This powerful n8n workflow template is designed for complex data interaction and visualization. It establishes a multi-layered AI system, starting with an n8n trigger that receives a chat message. A 'Primary Agent' acts as the router, directing the user's request (e.g., 'Show me sales data' or 'Chart the average price') to specialized secondary agents. This architecture ensures efficient processing: the 'Secondary Postgres Agent' handles all database operations (connecting seamlessly via a Postgres n8n node to execute queries), while the 'Secondary QuickChart Agent' translates the resulting database records into a visualization. This entire n8n automation process utilizes OpenAI's models (like GPT-4o-mini) combined with robust flow control to deliver accurate textual responses and visual charts based on live data.

How it Works

The operation of this advanced n8n workflow is divided into three key stages:


  1. Initiation and Primary Routing: The flow starts with the 'When chat message received' n8n trigger. The input prompt is passed to the '🤖Primary Agent'. This primary agent is connected to a 'Postgres Chat Memory' n8n node to maintain conversation history. It evaluates the user's request and decides whether to invoke the querydatabasetool or the generatecharttool.


  1. Tool Agent Router: The primary agent calls the workflow using the internal LangChain Workflow Tool n8n node, triggering the 'When Executed by Another Workflow' n8n trigger node. The '🔀Tool Agent Router' Switch n8n node then examines the input route variable. If the route is querydatabasetool, execution is routed to the Postgres agent branch.


  1. Postgres Agent Execution: The '🤖Secondary Postgres Agent' receives the prompt. This agent leverages three specific Postgres n8n node tools ('Execute SQL Query', 'DB Schema and Tables', 'Table Definitions') to accurately formulate and execute the necessary SQL query against the connected database (Postgres or Supabase). The resulting data is then returned to the Primary Agent, or, if a chart was requested, prepared for the next stage.


  1. QuickChart Generation: If the route is generatecharttool, the flow is routed to the '🤖Secondary QuickChart Agent'. This agent takes the user prompt and the database records as input. It uses an OpenAI LLM (gpt-4o-mini-2) and the 'QuickChart Object Schema' n8n node (an Output Parser) to generate a valid Chart.js configuration JSON object. This JSON is converted into a URL via the 'QuickChart GET URL' n8n node, executed via an HTTP Request n8n node, and the final chart URL is returned to complete the operation of the initial n8n workflow.

Installation Guide

To implement this sophisticated n8n workflow, follow these steps:


  1. Import: Copy the provided JSON data and paste it into your n8n instance using the 'New' -> 'Import from JSON' function.

  2. Database Credentials: You must configure a connection for the Postgres n8n node. This workflow requires a Postgres-compatible database (like Supabase or standard PostgreSQL). Set up the credentials named 'Postgres account'.

  3. OpenAI Credentials: Set up your OpenAI credentials for the Language Model n8n node connections. The workflow uses multiple instances of the 'gpt-4o-mini' model. Ensure your API key is configured with the required permissions.

  4. Database Schema: Populate your Postgres database with data and ensure the agent has the necessary permissions to query table schemas and execute SELECT queries.

  5. Activation: Once credentials are set and the database is connected, activate the main n8n trigger, 'When chat message received', and start interacting with your new AI chatbot.

Node Details

When chat message received (n8n trigger): The entry point of this n8n workflow, responsible for capturing user input from a LangChain chat interface.
🤖Primary Agent (LangChain Agent n8n node): Acts as the central intelligence and router. It decides which specialized tool (database query or chart generation) should handle the user's request.
querydatabasetool / generatequickcharttool (LangChain Tool Workflow n8n nodes): These tools allow the primary agent to execute specific sub-functions contained within the same n8n workflow, routing data between agents.
Postgres Chat Memory (LangChain Memory n8n node): Stores chat history in a dedicated PostgreSQL table (named after the workflow ID) to provide context to the agent.
🔀Tool Agent Router (Switch n8n node): The core flow control component. It evaluates the incoming route variable from the primary agent's tool call and directs the flow to the correct secondary agent branch. This is crucial for the modular nature of the n8n workflow.
🤖Secondary Postgres Agent (LangChain Agent n8n node): Focused solely on database interaction. It uses integrated Postgres n8n node tools (for querying, table definitions, and schema extraction) to convert natural language into optimized SQL.
Execute SQL Query (Postgres n8n node): Executes the SQL generated by the secondary Postgres agent.
🤖Secondary QuickChart Agent (LangChain Agent n8n node): Dedicated to visualization. It processes database records and the user's visualization request, generating a valid Chart.js JSON structure.
QuickChart Object Schema (Output Parser n8n node): Ensures the AI's output conforms strictly to the JSON schema required by QuickChart, improving reliability of the n8n workflow.
QuickChart GET URL / Create QuickChart (Set & HTTP Request n8n nodes): Formulate the final QuickChart image URL by embedding the generated chart JSON configuration.

Related n8n Workflows

Free

Nodes: 12 Nodes
Updated: December 26 2025
View all
Created by
Joseph LePage
Joseph LePage

As an AI Automation consultant based in Canada, I partner with forward-thinking organizations to implement AI solutions that streamline operations and drive growth.

Featured*