Skip to content
BotServBotServ
Node-REDAutomationOllamaLocal AIWorkflows

Node-RED for AI Automation

Connect Node-RED with local AI. Installation, Ollama integration, function calling, RAG flows and practical automation examples.

S

schutzgeist

8 min read
Node-RED for AI Automation

Node-RED for AI Automation

What This Article Covers

  • How to install and configure Node-RED for AI automation.
  • How to connect Node-RED with Ollama and use local models in flows.
  • How to implement function calling, RAG, and agent workflows in Node-RED.
  • Practical examples for email sorting, document summarization, and notifications.
  • Best practices for security, performance, and maintenance.

Introduction: Node-RED for AI Automation Explained

Node-RED is a visual programming tool for automation. Originally developed by IBM to connect IoT devices and APIs, it’s now used for everything from smart homes to enterprise integration. Combined with local AI, Node-RED becomes a powerful platform for building AI workflows visually without writing code.

This article is for people who want to run AI automation with local models and use Node-RED as their platform. You should understand what local AI is and how Ollama works. For programming fundamentals, see IRC-Coding.de.

Why Use Node-RED for AI Automation?

Imagine you want to sort emails automatically, summarize documents, and send notifications, all with local AI. You could write a Python script, but it quickly becomes messy. Node-RED lets you build these workflows visually: one node receives email, another classifies it with AI, and another takes action.

Node-RED is especially useful when you need multi-step workflows that connect different APIs and should be modifiable by non-programmers. The visual interface makes workflows understandable, and the flow editor enables rapid experimentation.

Node-RED for AI Automation: The Essentials

Node-RED is a browser-based flow editor where you connect nodes via drag-and-drop. Each node does one thing: receive email, send an HTTP request, execute JavaScript, or call AI. For AI automation, you connect input nodes (email, webhook, schedule) with AI nodes (Ollama, OpenAI) and output nodes (email, Slack, database).

The core idea: Node-RED is the visual bridge between input, AI, and output.

Who Should Read This?

  • Automation enthusiasts wanting to integrate AI into existing workflows.
  • Self-hosters using local AI for automation and looking for an interface.
  • Developers evaluating visual workflow tools.
  • Teams building workflows that non-programmers can understand.

Familiarity with local AI, Ollama, and basic JavaScript is helpful.

Key Terms

  • Node-RED - Visual flow editor for automation. Useful when: building workflows visually.
  • Ollama - Local model server. Useful when: serving as the AI backend for Node-RED.
  • Node - A single element in a flow. Useful when: performing one task, like making an HTTP request.
  • Flow - Connected nodes forming a workflow. Useful when: creating a complete automation script.
  • Function Calling - AI function returning structured data. Useful when: making AI-driven decisions.
  • RAG - Retrieval-Augmented Generation. Useful when: extending models with custom data.
  • Docker - Container platform. Useful when: running Node-RED in isolation.
  • Inject Node - Starts a flow manually or on a schedule. Useful when: testing and scheduling tasks.

Installing Node-RED

With Docker

docker run -d \
  --name nodered \
  -p 1880:1880 \
  -v nodered-data:/data \
  --restart unless-stopped \
  nodered/node-red

Then open http://localhost:1880 in your browser.

With npm

npm install -g node-red
node-red

With Proxmox LXC

If you use Proxmox VE, you can install Node-RED in an LXC container:

# Inside the LXC container
npm install -g node-red
# Set up as a service
npm install -g pm2
pm2 start node-red
pm2 startup
pm2 save

Connecting Ollama to Node-RED

Preparing Ollama

Make sure Ollama is running and a model is loaded:

ollama pull llama3.1
ollama serve

HTTP Request Node in Node-RED

Node-RED has a built-in HTTP Request node you can use with Ollama:

  1. Drag an inject node into your flow.
  2. Drag a function node and set the payload:
    msg.payload = {
      model: "llama3.1",
      messages: [
        { role: "user", content: msg.payload.prompt || "Hello" }
      ],
      stream: false
    };
    msg.headers = { "Content-Type": "application/json" };
    return msg;
  3. Drag an http request node and configure:
    • Method: POST
    • URL: http://localhost:11434/api/chat
    • Return: parsed JSON
  4. Connect the nodes: inject → function → http request → debug.

Click the Inject button, and you’ll see Ollama’s response in the Debug panel.

Community Nodes for Ollama

Several community nodes provide direct Ollama support:

  • node-red-contrib-ollama - Direct Ollama integration with chat and embedding nodes.
  • node-red-contrib-openai - OpenAI-compatible, works with Ollama.

Install via the Palette Manager in Node-RED:

Manage Palette → Install → "node-red-contrib-ollama"

Practical Example 1: Email Sorting with AI

This example sorts incoming emails by category using Ollama to determine the right classification.

Flow Structure

  1. IMAP Node (Incoming emails)
  2. Function Node (Build prompt):
    msg.payload = {
      model: "llama3.1",
      messages: [
        {
          role: "system",
          content: "You are an email classifier. Reply with only one of these categories: support, sales, billing, spam, other."
        },
        {
          role: "user",
          content: `Subject: ${msg.topic}\nContent: ${msg.payload}`
        }
      ],
      stream: false
    };
    msg.headers = { "Content-Type": "application/json" };
    return msg;
  3. HTTP Request Node (Call Ollama)
  4. Switch Node (Branch by category)
  5. Output Nodes (Move email to folder, notify Slack, etc.)

Advantages

  • Emails sort automatically without manual rules.
  • Add new categories by adjusting the system prompt.
  • Local AI means no cloud dependency and no privacy concerns.

Limitations

  • Each email takes inference time (seconds to minutes).
  • Misclassifications are possible, especially with ambiguous messages.
  • The model should be evaluated regularly.

Practical Example 2: Document Summarization

This example summarizes PDF documents that land in a folder.

Flow Setup

  1. File Node (monitor directory for PDFs)
  2. Function Node (extract text using pdf-parse):
    const pdf = require('pdf-parse');
    const buffer = msg.payload;
    pdf(buffer).then(data => {
      msg.payload = {
        model: "llama3.1",
        messages: [
          { role: "system", content: "Summarize this document in 5 sentences." },
          { role: "user", content: data.text.substring(0, 4000) }
        ],
        stream: false
      };
      msg.headers = { "Content-Type": "application/json" };
      node.send(msg);
    });
  3. HTTP Request Node (call Ollama)
  4. File Node (save summary)

Important Notes

  • Large documents need to be chunked, since models have a context window limit.
  • For better summaries, use models with larger context, such as qwen2.5:32k.
  • See context length for details.

Practical Example 3: AI-Filtered Notifications

This example filters system notifications and forwards only important ones.

Flow Setup

  1. Webhook Node (receive notification)
  2. Function Node (build prompt):
    msg.payload = {
      model: "llama3.1",
      messages: [
        {
          role: "system",
          content: "Determine whether this notification is important. Respond with 'important' or 'unimportant'."
        },
        { role: "user", content: msg.payload.message }
      ],
      stream: false
    };
    msg.headers = { "Content-Type": "application/json" };
    return msg;
  3. HTTP Request Node (call Ollama)
  4. Switch Node (forward only if marked ‘important’)
  5. Slack Node (send notification)

Function Calling in Node-RED

Function Calling lets you retrieve structured data from the AI that you can process further in Node-RED.

Example: Structured Email Response

// Function Node
msg.payload = {
  model: "llama3.1",
  messages: [
    {
      role: "system",
      content: "You are an email assistant. Respond in JSON format: {\"category\": \"...\", \"priority\": \"...\", \"response\": \"...\"}"
    },
    { role: "user", content: msg.payload.email }
  ],
  format: "json",
  stream: false
};
msg.headers = { "Content-Type": "application/json" };
return msg;

After the HTTP Request Node, you can process the JSON response directly, for example, branching with a Switch Node based on category.

See Function Calling for details.

RAG in Node-RED

RAG requires a vector database and embeddings. Node-RED can handle both:

  1. Embeddings from Ollama:

    msg.payload = {
      model: "nomic-embed-text",
      prompt: msg.payload.text
    };
    msg.headers = { "Content-Type": "application/json" };
    return msg;

    URL: http://localhost:11434/api/embeddings

  2. Vector database: Use node-red-contrib-chroma for ChromaDB or build HTTP requests to Pinecone, Qdrant, or Weaviate.

  3. RAG flow: Query, Embedding, Vector Search, build context, Ollama chat with context.

See Local RAG for details.

Security Considerations

  • Secure Node-RED: Set a password by editing settings.js. By default, Node-RED runs without authentication.
  • No secrets in flows: Use environment variables instead of hardcoded API keys.
  • Keep Ollama local: Do not expose Ollama to the internet without authentication. See API Keys.
  • Sandbox for Function Nodes: Function Nodes can execute arbitrary JavaScript. Restrict access to the flow editor.
  • Audit Logging: Enable logging for Node-RED to track actions. See Audit Logging.

Performance Tips

  • Small model for classification: Use a smaller model like llama3.1:8b for simple classification tasks, a larger one for complex work.
  • Caching: Cache recurring requests to save inference time.
  • Batching: Collect multiple requests and send them together when possible.
  • Streaming: Use streaming for long responses to reduce latency.
  • Asynchronous processing: Use queues to handle traffic spikes.

Common Pitfalls

  • No authentication: Node-RED has no password by default, a security risk.
  • Models too large: A 70B model for simple classification is overkill and slow.
  • Missing error handling: If Ollama is unreachable, the flow should catch errors instead of crashing.
  • Ignoring context length: Large documents must be chunked or inference will fail.
  • No testing: Workflows should be tested before going to production.

Further Resources on Node-RED

Key Takeaways:

  • Node-RED is a visual flow editor for automation.
  • With Ollama as backend, you can use local AI in workflows.
  • Practical examples: email sorting, document summarization, notification filtering.
  • Function Calling and RAG are implementable in Node-RED.
  • Security: secure Node-RED, keep secrets out of flows, run Ollama locally only.

FAQ: Node-RED for AI Automation - Common Questions

What is Node-RED?

Node-RED is a browser-based flow editor for automation. You connect nodes visually to build workflows that integrate APIs, devices, and services.

How do I connect Node-RED to Ollama?

Use the HTTP Request Node and send POST requests to the Ollama API (http://localhost:11434/api/chat). Alternatively, community nodes like node-red-contrib-ollama provide direct Ollama integration.

Can I use Function Calling in Node-RED?

Yes. Send the parameter format: json to Ollama and receive structured JSON responses that you can process further in Node-RED.

Can I implement RAG in Node-RED?

Yes. Use Ollama for embeddings, a vector database like ChromaDB for storage, and build a RAG flow: query, embedding, vector search, build context, chat with context.

How do I secure Node-RED?

Set a password in settings.js, use environment variables for secrets, restrict access to the flow editor, and do not expose Ollama to the internet without authentication.

Can I run Node-RED in Docker?

Yes. An official Docker image is available. Start Node-RED with docker run and mount a volume for data persistence.

Which model should I use?

For simple classification, a small model like llama3.1:8b is sufficient. For complex tasks like summarization or code generation, use a larger model like qwen2.5:32b.

How can I improve performance?

Use small models for simple tasks, cache recurring requests, use streaming for long responses, and process asynchronously with queues.

Is Node-RED free?

Yes. Node-RED is open source and free. You only need hardware for Ollama if you use local AI.

Are there alternatives to Node-RED?

Yes. n8n is a popular alternative with a similar concept. Both can integrate with Ollama. See Automation Basics for an overview.

Sources and Further Reading

Back to Blog
Share:

Related Posts