From c50fbab6e15b50361e5ff79ba3c4725f4e954a32 Mon Sep 17 00:00:00 2001 From: Saizul Amin <155534356+saizul@users.noreply.github.com> Date: Sun, 8 Nov 2026 20:35:59 +0600 Subject: [PATCH] ci: validate workflows and document the Multi AI Agent workflow Add a workflow JSON validator with a GitHub Actions job, and replace the placeholder README with a description derived from the workflow JSON: routing rules, agents and models, nodes used, required credentials and setup steps. --- .github/workflows/validate.yml | 20 ++++ README.md | 63 +++++++++++- scripts/validate-workflows.js | 176 +++++++++++++++++++++++++++++++++ 3 files changed, 258 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/validate.yml create mode 100644 scripts/validate-workflows.js diff --git a/.github/workflows/validate.yml b/.github/workflows/validate.yml new file mode 100644 index 0000000..8b4b957 --- /dev/null +++ b/.github/workflows/validate.yml @@ -0,0 +1,20 @@ +name: Validate workflows + +on: + push: + branches: [main] + pull_request: + +permissions: + contents: read + +jobs: + validate: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: actions/setup-node@v4 + with: + node-version: 20 + - name: Validate n8n workflow JSON + run: node scripts/validate-workflows.js diff --git a/README.md b/README.md index 63bbe69..9bfb1c6 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,63 @@ # ai-workflows -AI integrations, prompt systems, automation workflows, and intelligent process designs. + +Importable [n8n](https://n8n.io) workflows for AI agents and prompt systems, with the description and a diagram of each one. + +[![Validate workflows](https://github.com/saizul/ai-workflows/actions/workflows/validate.yml/badge.svg)](https://github.com/saizul/ai-workflows/actions/workflows/validate.yml) + +| Workflow | File | What it does | +|----------|------|--------------| +| Multi AI Agent (Telegram AI Bot) | [`Multi Ai Agent.json`](Multi%20Ai%20Agent.json) | One Telegram bot that routes each message by keyword to a different AI persona and model, or to all three at once for a combined answer | + +## Multi AI Agent (Telegram AI Bot) + +![Multi AI Agent workflow](Multi%20Ai%20Agent%20Workflow.png) + +**What it does.** A Telegram Trigger receives every message. A Switch node lowercases the text and checks, in order, whether it contains `force`, `nexus`, `victor` or `team`. The first match picks the route; anything else goes to the fallback output (named `Sizu`), which is handled by the default agent. + +| Route | Trigger word | Agent(s) | Model | +|-------|--------------|----------|-------| +| Force | `force` | Ai Force: creative, bold, direct | Google Gemini node, `models/gemma-4-26b-a4b-it` | +| Nexus | `nexus` | Ai Nexus: analytical, structured | OpenRouter, `inclusionai/ring-2.6-1t:free` | +| Victor | `victor` | Ai Victor: fast and concise | Groq, `llama-3.3-70b-versatile` | +| Team | `team` | Team Force, Team Nexus and Ai Victor1 run in parallel as a three-member "council" (2-4 line answers, each prefixed with its name); a Merge node (3 inputs) and a Code node combine them into one message | Gemini `models/gemini-2.5-flash-lite`, OpenRouter `inclusionai/ring-2.6-1t:free`, Groq `llama-3.3-70b-versatile` | +| Fallback (`Sizu`) | anything else | Ai Default (persona "Sizu"), which can search and read Gmail through a tool | Groq, `llama-3.3-70b-versatile` | + +All agents replying to the same Telegram chat share one `Simple Memory` node (window of 15 messages, keyed by the Telegram chat id). Every route ends in a single `Send a text message` Telegram node that replies to the chat the message came from. The agents answer in the language of the user (Bengali, English or mixed). + +**Gmail tool.** `Get many messages in Gmail` is attached to Ai Default as a tool. The agent fills in `limit` and a Gmail search query itself (for example `is:unread` or `newer_than:1d`), so "check my email" or "summarise my last 5 emails" works from Telegram. + +**Nodes used.** Telegram Trigger, Switch, AI Agent (x7), Google Gemini Chat Model (x2), OpenRouter Chat Model (x2), Groq Chat Model (x3), Simple Memory, Gmail Tool, Merge, Code, Telegram. + +**Credentials needed** (create them in n8n, then select them on each node after import): + +| Credential type | Used by | +|-----------------|---------| +| Telegram API (bot token from [@BotFather](https://t.me/BotFather)) | Telegram Trigger, Send a text message | +| Google Gemini (PaLM) API key | Both Google Gemini Chat Model nodes | +| OpenRouter API key | Both OpenRouter Chat Model nodes | +| Groq API key | All three Groq Chat Model nodes | +| Gmail OAuth2 | Get many messages in Gmail | + +The credential names stored in the file (for example "Groq account") belong to the original instance; n8n asks you to pick your own when you open each node. No keys or tokens are stored in the JSON. + +**Setup.** + +1. In n8n choose **Workflows -> Import from file** and select `Multi Ai Agent.json`. +2. Create the five credentials above and attach them to the nodes that show a warning. +3. Check the model names. The free OpenRouter and Gemini/Gemma model ids in the file can be retired by the providers, so swap them for any model you have access to. +4. Edit the trigger words in the **Switch** node if you want different routes. +5. Activate the workflow and message your bot, for example `force give me three headline ideas`, `team what should I post this week`, or any plain message for the default agent. + +Longer notes on the design are in [`Multi Ai Agent Descriptions`](Multi%20Ai%20Agent%20Descriptions) and [`Multi Ai Agent Feature`](Multi%20Ai%20Agent%20Feature). + +## Validation + +`scripts/validate-workflows.js` checks every workflow JSON in this repo (valid JSON, well-formed nodes, connections to existing nodes, no orphaned nodes, no embedded secrets). It runs in GitHub Actions on every push and pull request and locally with: + +```bash +node scripts/validate-workflows.js +``` + +## Author + +[Saizul Amin](https://saizul.com): web developer, SEO and automation specialist. diff --git a/scripts/validate-workflows.js b/scripts/validate-workflows.js new file mode 100644 index 0000000..6ce0b82 --- /dev/null +++ b/scripts/validate-workflows.js @@ -0,0 +1,176 @@ +#!/usr/bin/env node +/* + * Validates exported n8n workflow JSON files. + * + * Checks, for every *.json file in the repository (excluding node_modules/.git): + * 1. The file parses as JSON. + * 2. It has a non-empty "nodes" array, and each node has name, type, + * position ([x, y]) and a unique name. + * 3. Every entry in "connections" refers to existing node names + * (both the source and every target). + * 4. Every non-trigger node takes part in at least one connection + * (AI sub-nodes such as chat models connect outward, so either direction counts). + * 5. No credential-looking secrets are embedded (API keys, bearer tokens, + * private keys, long hard-coded passwords). Credential *references* + * (the "credentials" block with id/name) are fine. + * + * Usage: node scripts/validate-workflows.js [directory] + * Exit code is 1 if any error is found. No dependencies. + */ +'use strict'; +const fs = require('fs'); +const path = require('path'); + +const root = path.resolve(process.argv[2] || '.'); +const SKIP_DIRS = new Set(['.git', 'node_modules', '.github']); +const SKIP_FILES = new Set(['package.json', 'package-lock.json', 'composer.json', 'tsconfig.json']); + +const SECRET_PATTERNS = [ + [/sk-[A-Za-z0-9_-]{20,}/, 'OpenAI-style API key'], + [/AIza[0-9A-Za-z_-]{35}/, 'Google API key'], + [/\bEAA[A-Za-z0-9]{40,}/, 'Facebook/Meta access token'], + [/\bgh[pousr]_[A-Za-z0-9]{30,}/, 'GitHub token'], + [/\bxox[abprs]-[A-Za-z0-9-]{10,}/, 'Slack token'], + [/\bAKIA[0-9A-Z]{16}\b/, 'AWS access key id'], + [/Bearer\s+[A-Za-z0-9._-]{20,}/, 'Bearer token'], + [/-----BEGIN [A-Z ]*PRIVATE KEY-----/, 'private key'], + [/\beyJ[A-Za-z0-9_-]{15,}\.[A-Za-z0-9_-]{15,}\.[A-Za-z0-9_-]{10,}/, 'JWT'], +]; +const SECRET_KEY_RE = /^(api[_-]?key|apikey|secret|client[_-]?secret|password|passwd|access[_-]?token|auth[_-]?token|token)$/i; + +function walk(dir, out) { + for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { + if (entry.isDirectory()) { + if (!SKIP_DIRS.has(entry.name)) walk(path.join(dir, entry.name), out); + } else if (entry.isFile() && entry.name.toLowerCase().endsWith('.json') && !SKIP_FILES.has(entry.name)) { + out.push(path.join(dir, entry.name)); + } + } + return out; +} + +// Values that are clearly placeholders or n8n expressions, not real secrets. +function isPlaceholder(v) { + return ( + v === '' || + /^=?\s*\{\{.*\}\}\s*$/s.test(v) || + /^=/.test(v) || + /YOUR[_ -]|<.*>|REPLACE|PLACEHOLDER|CHANGE[_ -]?ME|EXAMPLE|xxx/i.test(v) + ); +} + +function scanSecrets(value, trail, report) { + if (Array.isArray(value)) { + value.forEach((v, i) => scanSecrets(v, `${trail}[${i}]`, report)); + } else if (value && typeof value === 'object') { + for (const [k, v] of Object.entries(value)) { + if (typeof v === 'string' && SECRET_KEY_RE.test(k) && v.length >= 12 && !isPlaceholder(v)) { + report(`${trail}.${k}: hard-coded value for secret-like field`); + } + scanSecrets(v, `${trail}.${k}`, report); + } + } else if (typeof value === 'string' && !isPlaceholder(value)) { + for (const [re, label] of SECRET_PATTERNS) { + if (re.test(value)) report(`${trail}: looks like a ${label}`); + } + } +} + +function validate(file) { + const errors = []; + let wf; + try { + wf = JSON.parse(fs.readFileSync(file, 'utf8')); + } catch (e) { + return { errors: [`invalid JSON: ${e.message}`], skipped: false }; + } + if (!wf || typeof wf !== 'object' || !Array.isArray(wf.nodes)) { + return { errors: [], skipped: true }; + } + if (wf.nodes.length === 0) errors.push('"nodes" array is empty'); + + const names = new Set(); + wf.nodes.forEach((n, i) => { + const label = `nodes[${i}]${n && n.name ? ` (${n.name})` : ''}`; + if (!n || typeof n !== 'object') return errors.push(`${label}: not an object`); + if (typeof n.name !== 'string' || !n.name) errors.push(`${label}: missing "name"`); + if (typeof n.type !== 'string' || !n.type) errors.push(`${label}: missing "type"`); + if (!Array.isArray(n.position) || n.position.length !== 2 || !n.position.every(Number.isFinite)) { + errors.push(`${label}: "position" must be [x, y]`); + } + if (n.parameters !== undefined && (typeof n.parameters !== 'object' || n.parameters === null)) { + errors.push(`${label}: "parameters" must be an object`); + } + if (typeof n.name === 'string') { + if (names.has(n.name)) errors.push(`${label}: duplicate node name "${n.name}"`); + names.add(n.name); + } + }); + + const conns = wf.connections; + if (conns !== undefined && (typeof conns !== 'object' || conns === null || Array.isArray(conns))) { + errors.push('"connections" must be an object'); + } else if (conns) { + for (const [source, types] of Object.entries(conns)) { + if (!names.has(source)) errors.push(`connections: source node "${source}" does not exist`); + for (const [connType, outputs] of Object.entries(types || {})) { + if (!Array.isArray(outputs)) { + errors.push(`connections.${source}.${connType}: expected an array`); + continue; + } + outputs.forEach((targets, idx) => { + (targets || []).forEach((t) => { + if (!t || !names.has(t.node)) { + errors.push(`connections.${source}.${connType}[${idx}]: target node "${t && t.node}" does not exist`); + } + }); + }); + } + } + } + + // Orphan check: any node that is not a trigger/note must be a connection source or target. + const incoming = new Set(Object.keys(conns || {})); + for (const types of Object.values(conns || {})) { + for (const outputs of Object.values(types || {})) { + (Array.isArray(outputs) ? outputs : []).forEach((targets) => + (targets || []).forEach((t) => t && incoming.add(t.node))); + } + } + wf.nodes.forEach((n) => { + if (!n || typeof n.type !== 'string' || typeof n.name !== 'string') return; + const isEntry = /(trigger|webhook|stickyNote|manualTrigger|cron|start|errorTrigger|formTrigger)$/i.test(n.type); + if (!isEntry && !incoming.has(n.name)) { + errors.push(`node "${n.name}" (${n.type}) is not connected to anything (orphaned)`); + } + }); + + scanSecrets(wf, '$', (m) => errors.push(`possible secret: ${m}`)); + return { errors, skipped: false, nodeCount: wf.nodes.length }; +} + +const files = walk(root, []).sort(); +let failed = 0; +let checked = 0; +for (const file of files) { + const rel = path.relative(root, file); + const { errors, skipped, nodeCount } = validate(file); + if (skipped) { + console.log(`SKIP ${rel} (not an n8n workflow)`); + continue; + } + checked++; + if (errors.length) { + failed++; + console.log(`FAIL ${rel}`); + errors.forEach((e) => console.log(` - ${e}`)); + } else { + console.log(`OK ${rel} (${nodeCount} nodes)`); + } +} +if (checked === 0) { + console.log('No n8n workflow files found.'); + process.exit(1); +} +console.log(`\n${checked - failed}/${checked} workflow file(s) valid.`); +process.exit(failed ? 1 : 0);