N8N Pipeline

function

An optimized streaming-enabled pipeline for interacting with N8N workflows, consistent response handling for both streaming and non-streaming modes, robust error handling, and simplified status management. Supports Server-Sent Events (SSE) streaming and various N8N workflow formats. Now includes configurable AI Agent tool usage display with three verbosity levels (minimal, compact, detailed) and customizable length limits for tool inputs/outputs (non-streaming mode only).

agents o/agents • @owndev
·
a month ago
31K
62
67K
Updated a month ago
Created Jan 31, 2025
n8n_pipeline.py
Python · 1595 lines
"""
title: n8n Pipeline with StreamingResponse Support
author: owndev
author_url: https://github.com/owndev/
project_url: https://github.com/owndev/Open-WebUI-Functions
funding_url: https://github.com/sponsors/owndev
n8n_template: https://github.com/owndev/Open-WebUI-Functions/blob/main/pipelines/n8n/Open_WebUI_Test_Agent_Streaming.json
version: 2.3.1
required_open_webui_version: 0.8.0
license: Apache License 2.0
description: An optimized streaming-enabled pipeline for interacting with N8N workflows, consistent response handling for both streaming and non-streaming modes, robust error handling, and simplified status management. Supports Server-Sent Events (SSE) streaming and various N8N workflow formats. Now includes configurable AI Agent tool usage display with three verbosity levels (minimal, compact, detailed) and customizable length limits for tool inputs/outputs (non-streaming mode only).
features:

N8N Pipeline

An optimized streaming-enabled pipeline for interacting with N8N workflows, consistent response handling for both streaming and non-streaming modes, robust error handling, and simplified status management. Supports Server-Sent Events (SSE) streaming and various N8N workflow formats. Now includes configurable AI Agent tool usage display with three verbosity levels (minimal, compact, detailed) and customizable length limits for tool inputs/outputs (non-streaming mode only).


Features

  • Integrates with N8N for seamless streaming communication.
  • Uses FastAPI StreamingResponse for real-time streaming.
  • Enables real-time interaction with N8N workflows.
  • Provides configurable status emissions and chunk streaming.
  • Cloudflare Access support for secure communication.
  • Encrypted storage of sensitive API keys.
  • Fallback support for non-streaming responses.
  • Compatible with Open WebUI streaming architecture.
  • Displays N8N AI Agent tool usage with configurable verbosity (non-streaming mode only).
  • Three display modes: minimal (tool names only), compact (names + preview), detailed (full collapsible sections).
  • Customizable length limits for tool inputs and outputs.
  • Shows tool calls, inputs, and results from intermediateSteps in non-streaming mode (N8N limitation - streaming responses do not include intermediateSteps).
  • Parses n8n native streaming (NDJSON), Server-Sent Events (data lines, [DONE], comments) and plain-text streams line by line without leaking SSE framing.
  • Forwards token usage from a non-streamed JSON reply of the workflow to Open WebUI, for streaming and non-streaming chats.
  • Sends Open WebUI tasks (title, tags, follow-ups, ...) without chat_id/message_id, so they stay out of the workflow's chat memory.
  • Final status on completion, on error or when the response is stopped.
  • Shows n8n stream error chunks as 'N8N Error: ...' and ends a failed or interrupted stream with an error status.
  • Parses large JSON objects streamed in small chunks in linear time, without blocking Open WebUI.
  • Here is an example N8N workflow for N8N Pipeline

Workflows for N8N Pipeline


GitHub

Open-WebUI-Functions

NOTE

For questions, problems, and feature requests, an issue must be created on GitHub.


License

Apache License 2.0


6