← All N8N workflows
AI & researchAgentChat TriggerExecute WorkflowExecute Workflow TriggerHTTP Request

talk to your sqlite database with a langchain ai agent

Configured with Agent, Chat Trigger, Execute Workflow, Execute Workflow Trigger, and additional nodes. Review the connections and setup before adapting this template.

Workflow preview
AI & modelsOpenAI Chat ModelOpenAI Chat ModelSubworkflowExecute WorkflowExecute WorkflowTriggerExecute "Generate achart" toolExecute Workflow TriggerWeb / APIOpenAI - Generate Chartdefinition with…HTTP RequestTransformSet responseEdit FieldsTriggerWhen chat messagereceivedChat TriggerTransformSet Text outputEdit FieldsTransformSet Text + Chart outputEdit FieldsAI & modelsAI AgentAgentData storeWindow Buffer MemoryMemory Buffer WindowAI & modelsOpenAI Chat ModelClassifierOpenAI Chat ModelAI & modelsText Classifier - Chartrequired?Text ClassifierTransformUser question + Agentinitial responseEdit FieldsAI & modelsInformation Extractor -User questionInformation Extractor

Node categories in this workflow

  • AI & models
  • Subworkflow
  • Trigger
  • Web / API
  • Transform
  • Data store

Icons describe general node roles, inferred from node types. Inspect the parameters for the configured action.

Drag to pan; use + and − to zoom. Reconstructed from the exported node positions; nothing runs here. Dashed lines represent non-main connections. Full node names and notes appear below.

How it works

The exported workflow contains the following configured nodes. Their connections are shown above; inspect the JSON for the complete logic, expressions, and external actions.

Workflow node names, types, and operations
NodeCategoryTypeOperation
OpenAI Chat ModelAI & modelsOpenAI Chat ModelSee node parameters
Execute WorkflowSubworkflowExecute WorkflowSee node parameters
Execute "Generate a chart" toolTriggerExecute Workflow TriggerSee node parameters
OpenAI - Generate Chart definition with Structured OutputWeb / APIHTTP RequestPOST
Set responseTransformEdit FieldsSee node parameters
When chat message receivedTriggerChat TriggerSee node parameters
Set Text outputTransformEdit FieldsSee node parameters
Set Text + Chart outputTransformEdit FieldsSee node parameters
AI AgentAI & modelsAgentSee node parameters
Window Buffer MemoryData storeMemory Buffer WindowSee node parameters
OpenAI Chat Model ClassifierAI & modelsOpenAI Chat ModelSee node parameters
Text Classifier - Chart required?AI & modelsText ClassifierSee node parameters
User question + Agent initial responseTransformEdit FieldsSee node parameters
Information Extractor - User questionAI & modelsInformation ExtractorSee node parameters

Setup

  1. Download the JSON and import it into an isolated n8n instance. Leave the workflow inactive.
  2. Connect your own credentials through n8n’s credential store. Replace REPLACE_WITH_* values with your resource identifiers.
  3. Inspect API destinations, Code nodes, database queries, file paths, and outbound actions.
  4. Run with synthetic data and harmless destinations. Enable triggers only after checking the actual outputs.

Requirements

An n8n instance with the listed node types and compatible versions. Service-connected workflows may require accounts, credentials, or paid APIs.

Credential types declared in the source

  • openAiApi
  • postgres

Workflow notes

Overview

Overview

  • This workflow aims to provide data visualization capabilities to a native SQL Agent.
  • Together, they can help foster data analysis and data visualization within a team.
  • It uses the native SQL Agent that works well and adds visualization capabilities thanks to OpenAI’s Structured Output and Quickchart.io.

How it works

  1. Information Extraction:
    • The Information Extractor identifies and extracts the user's question.
    • If the question includes a visualization aspect, the SQL Agent alone may not respond accurately.
  2. SQL Querying:
    • It leverages a regular SQL Agent: it connects to a database, queries it, and translates the response into a human-readable format.
  3. Chart Decision:
    • The Text Classifier determines whether the user would benefit from a chart to support the SQL Agent's response.
  4. Chart Generation:
    • If a chart is needed, the sub-workflow dynamically generates a chart and appends it to the SQL Agent’s response.
    • If not, the SQL Agent’s response is output as is.
  5. Calling OpenAI for Chart Definition:
    • The sub-workflow calls OpenAI via the HTTP Request node to retrieve a chart definition.
  6. Building and Returning the Chart:
    • In the "Set Response" node, the chart definition is appended to a Quickchart.io URL, generating the final chart image.
    • The AI Agent returns the response along with the chart.

How to use it

  • Use an existing database or create a new one.
  • For example, I've used this Kaggle dataset and uploaded it to a Supabase DB.
  • Add the PostgreSQL or MySQL credentials.
  • Alternatively, you can use SQLite binary files (check this template).
  • Activate the workflow.
  • Start chatting with the AI SQL Agent.
  • If the Text Classifier determines a chart would be useful, it will generate one in addition to the SQL Agent's response.

Notes

  • The full Quickchart.io specifications have not been fully integrated, so there may be some glitches (e.g., radar graphs may not display properly due to size limitations).
Generate a Quickchart definition

Generate a Quickchart definition

Original template

HTTP Request node

  • Send the chart query to OpenAI, with a defined JSON response format - using HTTP Request node as it has not yet been implemented in the OpenAI nodes
  • The JSON structure is based on ChartJS and Quickchart.io definitions, that let us create nice looking graphs.
  • The output is a JSON containing the chart definition that is passed to the next node.

Set Response node

  • Adds the chart definition at the end of a Quickchart.io URL (see documentation)
  • Note that in the parameters, we specify the width to 250 in order to be properly displayed in the chart interface.
Information Extractor

Information Extractor

  • This Information Extractor is added to extract the user's question
  • In some cases, if the question contains a visualization aspect, the SQL Agent may not responding accurately.

SQL Agent

  • This SQL Agent is connected to a Database.
  • It queries the Database for each user message.
  • In this example, the prompt has been slightly changed to address an issue with querying a Supabase DB. Feel free to change the Prefix Prompt to suit your needs.
  • This example uses the data from this Kaggle dataset
Respond with a text only or also include a chart

Respond with a text only or also include a chart

  • The text classifier determines if the response from the SQL Agent would benefit from a chart
  • If it does, then it executes the subworkflow to dynamically generate a chart, and append the chart to the response from the SQL Agent
  • If it doesn't, then the SQL Agent response is directly outputted.
Demo

Demo

talk to your sqlite database with a langchain ai agent

talk to your sqlite database with a langchain ai agent

Purpose and structure

This folder contains the talk to your sqlite database with a langchain ai agent workflow. Its executable nodes use agent, chatTrigger, executeWorkflow, executeWorkflowTrigger, httpRequest, informationExtractor, lmChatOpenAi, memoryBufferWindow, set, textClassifier. The table and connection map below are derived from the JSON, not an inferred guarantee of behavior.

Setup

Import inactive. Configure your own credentials and replace REPLACE_WITH_* values. Review external destinations and Code nodes before running.

Entry points

Execute "Generate a chart" tool, When chat message received

Verification

Sanitized source candidate; not runtime-tested. This overview is generated from node metadata. Read the folder README for the connection map, credential types, and license.

Attribution

https://github.com/Zie619/n8n-workflows/blob/94007c1445d9258a7da116646b79473e7c7c3282/workflows/Http/0636_HTTP_Stickynote_Create_Webhook.json MIT; preserve source notices.

More in AI & research