How to Add External JavaScript Libraries to Flowise for Custom Chatbot Tools
Flowise is a powerful open-source, low-code platform designed for quickly building LLM-enabled chatbots. A significant advantage of Flowise is its support for creating custom JavaScript-based tools, which an LLM can dynamically instruct to execute. However, extending these tools with external Node packages—often essential for meaningful functionality—can quickly become challenging due to Flowise’s *ahem* limited documentation. If you’ve found yourself struggling with integrating these external packages, let me be your light of Galadriel to lead you out the Shelob’s lair that is Flowise’s documentation.
I’m Bobby Gill, Chief Architect at BlueLabel, where we build intelligent experiences using generative AI. At BlueLabel, we frequently rely on Flowise for building LLM-enabled workflows (I am trying really hard not to use the word ‘agentic’ here). Here’s a short walkthrough on exactly how to integrate these packages into Flowise, so you don’t have to go through the pain I have had to experience..
The Scenario
Let’s say you’ve built a custom tool in Flowise that fetches customer data via a CSV file downloaded from an S3 bucket, like the function below:
const fetch = require('node-fetch'); const { parse } = require('csv-parse/sync'); const S3_BUCKET_PREFIX = "https://XXXX.s3.us-east-1.amazonaws.com"; const FILENAME = "customers.csv"; async function fetchAndParseCSV(customer_id) { try { const response = await fetch(`${S3_BUCKET_PREFIX}/${customer_id}.csv`); const csvContent = await response.text(); const records = parse(csvContent, { columns: true, skip_empty_lines: true }); return records; } catch (err) { throw new Error(`Error fetching or parsing CSV: ${err.message}`); } }
When you try running this, Flowise hits you with a stack trace that looks something like this (which in this case was logged to LangSmith):
Cannot find module 'csv-parser' VMError: Cannot find module 'csv-parser' at LegacyResolver.resolveFull (/usr/local/lib/node_modules/flowise/node_modules/@flowiseai/nodevm/lib/resolver.js:126:9)
The astute reader would quickly surmise that we need to install a Node package, but, how would one achieve that? Certainly not by looking at the Flowise documentation!
How to Add External Node Packages to Flowise
Here’s how to install new Node packages into Flowise so you can use them in your custom tool declarations.
Prerequisites:
- You are running the open-source version of Flowise using the
pnpm start
command. - You will need to have at least Node 18.5.0 installed on your machine.
- Install the ‘pnpm’ package management tool.
npm i -g pnpm
Steps:
- Create a fork of the Flowise Github repository, or if you want to just follow along at home, you can use the BlueLabel fork of the Flowise repository here:
git clone https://github.com/BlueLabelLabs/BlueLabel-Flowise
- Open up folder in your terminal, navigate to the
packages/components
folder and execute the following command:
pnpm add <package-name>
- If you are running Flowise directly using the
pnpm start
command, then you should have .env file here, within that file add the name of your <package> to theTOOL_FUNCTION_EXTERNAL_DEP
environment variable. - Now navigate back up to the root of the repository and execute the following commands:
pnpm install pnpm build
That’s it—your custom tool should now run without exploding into an arcane stack trace. Thanks for attending my TED talk, remember to spay and neuter your chatbots, because Bob Parker would have wanted you to.
Bobby Gill