Skip to content

Commit 1e89d8b

Browse files
authored
Merge pull request #76 from owndev/75-ui-display-for-n8n-ai-agent-tool-usage-in-n8npy-n8p-pipeline
UI display for N8N AI Agent tool usage in n8n.py (N8P Pipeline)
2 parents b45d758 + f58d3da commit 1e89d8b

File tree

6 files changed

+823
-57
lines changed

6 files changed

+823
-57
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,18 +114,29 @@ The functions include a built-in encryption mechanism for sensitive information:
114114
115115
### **2. [N8N Pipeline](./pipelines/n8n/n8n.py)**
116116
117+
> [!TIP]
118+
> **N8N Workflow Automation Integration**
119+
>
120+
> Connect Open WebUI with N8N to leverage powerful workflow automation. Includes configurable AI Agent tool usage display for complete transparency into your agent's actions.
121+
117122
- Integrates **Open WebUI** with **N8N**, an automation and workflow platform.
118-
- Streaming support for real-time data processing.
123+
- **AI Agent Tool Usage Display (v2.2.0)** 🛠️: Shows tool calls from N8N AI Agent workflows with three verbosity levels (minimal, compact, detailed) and customizable length limits (non-streaming mode only).
124+
- Streaming and non-streaming support for real-time and batch data processing.
119125
- Sends messages from Open WebUI to an **N8N webhook**.
120126
- Supports real-time message processing with dynamic field handling.
121127
- Enables automation of AI-generated responses within an **N8N workflow**.
122128
- Supports encryption of sensitive information like API keys.
123129
- Here is an example [N8N workflow](./pipelines/n8n/Open_WebUI_Test_Agent.json) for [N8N Pipeline](./pipelines/n8n/n8n.py)
124130
131+
> [!IMPORTANT]
132+
> **Tool Usage Display Limitation**: The AI Agent tool call display currently only works in **non-streaming mode** due to N8N's current streaming implementation. The code is future-proof and will automatically work when N8N adds `intermediateSteps` to streaming responses.
133+
125134
🔗 [N8N Pipeline in Open WebUI](https://openwebui.com/f/owndev/n8n_pipeline)
126135
127136
🔗 [Learn More About N8N](https://n8n.io/)
128137
138+
📖 [N8N Tool Usage Display Documentation](./docs/n8n-tool-usage-display.md)
139+
129140
### **3. [Infomaniak](./pipelines/infomaniak/infomaniak.py)**
130141
131142
- Integrates **Open WebUI** with **Infomaniak**, a Swiss web hosting and cloud services provider.

docs/n8n-integration.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
This integration allows Open WebUI to communicate with workflows created in **n8n**, a powerful workflow automation tool. Messages are sent and received via webhook endpoints, making it easy to plug Open WebUI into your existing automation pipelines.
44

55
> [!NOTE]
6-
> **Recent Improvements (v2.1.0)**: Enhanced streaming support with consistent response handling, automatic systemPrompt deduplication, simplified configuration, and improved error messaging.
6+
> **Recent Improvements (v2.2.0)**: Added AI Agent tool usage display with collapsible details sections. The pipeline now extracts and displays tool calls from `intermediateSteps` in **non-streaming mode**, showing tool names, inputs, and results in a user-friendly format.
7+
8+
> [!IMPORTANT]
9+
> **Tool Usage Display**: AI Agent tool calls are currently only visible in **non-streaming mode** due to N8N's streaming implementation. The code is future-proof and will automatically work if N8N adds `intermediateSteps` support to streaming responses.
710
811
🔗 [Learn More About N8N](https://n8n.io/)
912

@@ -18,6 +21,19 @@ This integration allows Open WebUI to communicate with workflows created in **n8
1821

1922
## Features
2023

24+
> [!TIP]
25+
> **AI Agent Tool Usage Display (v2.2.0)** 🛠️
26+
>
27+
> Automatically extracts and displays tool calls from N8N AI Agent workflows in **non-streaming mode**.
28+
>
29+
> - 📊 **Three verbosity levels**: `minimal` (names only), `compact` (names + preview), `detailed` (full info)
30+
> - 📏 **Customizable length limits**: Control input/output text length
31+
> - 🎯 **Flexible configuration**: Adapt display to your needs
32+
>
33+
> Shows tool names, inputs, and results from the `intermediateSteps` array to provide transparency into the AI agent's workflow execution.
34+
>
35+
> 📖 [Learn more about Tool Usage Display](./n8n-tool-usage-display.md)
36+
2137
- **Streaming & Non-Streaming Support**
2238
Automatic detection and handling of both streaming and non-streaming responses with consistent output formatting.
2339

docs/n8n-tool-usage-display.md

Lines changed: 297 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,297 @@
1+
# N8N AI Agent Tool Usage Display
2+
3+
## Overview
4+
5+
Starting with version 2.2.0, the N8N pipeline automatically displays AI Agent tool calls in a user-friendly format. When your N8N workflow includes an AI Agent node that uses tools (like Wikipedia, Date/Time, Calculator, etc.), the pipeline will extract and display detailed information about each tool invocation.
6+
7+
Version 2.2.0 includes **configurable verbosity levels** and **length limits** for tool display, allowing you to control how detailed the tool information is shown.
8+
9+
## Important Limitation
10+
11+
> [!IMPORTANT]
12+
> **⚠️ Non-Streaming Mode Only**: Tool usage display is currently only available in **non-streaming mode**. N8N's AI Agent streaming responses do not include the `intermediateSteps` field, which is required to show tool calls. This is a limitation of N8N's streaming implementation, not the pipeline.
13+
>
14+
> **To see tool calls**: Configure your N8N workflow to use **non-streaming responses** (remove or disable streaming in the "Respond to Webhook" node).
15+
16+
## Features
17+
18+
### Automatic Detection
19+
20+
- Works with **non-streaming** N8N responses
21+
- Automatically extracts `intermediateSteps` from the N8N response payload
22+
- Configurable verbosity levels (v2.2.0+)
23+
- Customizable length limits for inputs and outputs (v2.2.0+)
24+
25+
### Verbosity Levels (v2.2.0+)
26+
27+
> [!TIP]
28+
> **Configure via Pipeline Settings**: Set `TOOL_DISPLAY_VERBOSITY` to control the detail level.
29+
30+
#### 1. **Minimal** (`minimal`)
31+
32+
Shows only tool names in a collapsible list:
33+
34+
```txt
35+
🛠️ Tool Calls (4 steps) ▶
36+
1. Date_Time
37+
2. Crypto
38+
3. Wikipedia
39+
4. Calculator
40+
```
41+
42+
**Best for**: Quick overview, minimal UI clutter, collapsible for space-saving
43+
44+
#### 2. **Compact** (`compact`)
45+
46+
Shows tool names with short result previews:
47+
48+
```txt
49+
🛠️ Tool Calls (4 steps) ▶
50+
1. Date_Time → [{"currentDate":"2025-10-10T11:22:38.697+01:00"}]
51+
2. Crypto → [{"Property_Name":"uuid4","uuid4":"c28495ca-1eb8-419f-8941-7a38c753e809"}]
52+
3. Wikipedia → Page: List of tz database time zones...
53+
4. Calculator → 128675.5415958103
54+
```
55+
56+
**Best for**: Balance between overview and detail
57+
58+
#### 3. **Detailed** (`detailed`) - Default
59+
60+
Shows full collapsible sections with all information:
61+
62+
```txt
63+
🛠️ Tool Calls (4 steps) ▶
64+
├─ Step 1: Date_Time ▶
65+
│ 🔧 Tool: Date_Time
66+
│ 🆔 Call ID: call_i7JgGhwh7xV0ghqR9mD4qTJ9
67+
│ 📥 Input: {"Include_Current_Time": true, "Timezone": "Europe/London"}
68+
│ 📤 Result: [{"currentDate":"2025-10-10T11:22:38.697+01:00"}]
69+
│ 📝 Log: Invoking "Date_Time" with...
70+
├─ Step 2: Crypto ▶
71+
└─ ...
72+
```
73+
74+
**Best for**: Debugging, full transparency
75+
76+
### Length Limits (v2.2.0+)
77+
78+
> [!NOTE]
79+
> **Control Output Size**: Set `TOOL_INPUT_MAX_LENGTH` and `TOOL_OUTPUT_MAX_LENGTH` to limit text length.
80+
81+
- **`TOOL_INPUT_MAX_LENGTH`** (default: 500): Maximum characters for tool input display in `detailed` and `compact` modes
82+
- **`TOOL_OUTPUT_MAX_LENGTH`** (default: 500): Maximum characters for tool output/observation display
83+
- Set to **0** for unlimited length (no truncation)
84+
85+
> [!IMPORTANT]
86+
> **Behavior with `0` (unlimited)**:
87+
>
88+
> - **Detailed mode**: Shows complete input and output without any truncation
89+
> - **Compact mode**: For inputs, shows full data. For outputs, still uses a 100-character preview for UI readability
90+
91+
**Example**: For very long Wikipedia results, set `TOOL_OUTPUT_MAX_LENGTH` to 200 to show only the first 200 characters, or set to 0 to show everything.
92+
93+
### Rich Display Format (Detailed Mode)
94+
95+
Each tool call is displayed with:
96+
97+
- 🔧 **Tool Name**: The name of the tool that was invoked
98+
- 🆔 **Call ID**: Unique identifier for debugging (e.g., `call_FB0sIgrwuIGJkOaROor7raU2`)
99+
- 📥 **Input**: The parameters passed to the tool (formatted as JSON, respects `TOOL_INPUT_MAX_LENGTH`)
100+
- 📤 **Result**: The tool's response/observation (respects `TOOL_OUTPUT_MAX_LENGTH`)
101+
- 📝 **Log**: Optional log messages from the tool execution (max 200 chars)
102+
103+
### Collapsible UI
104+
105+
Uses HTML `<details>` tags for a clean, expandable interface:
106+
107+
Click to expand each step and view full details (in detailed mode).
108+
109+
## Example
110+
111+
### N8N Response Format
112+
113+
Your N8N AI Agent workflow should return data in this format:
114+
115+
```json
116+
[
117+
{
118+
"output": "Current time in Europe/London: 2025-10-10 09:46:45 BST (UTC+1)...",
119+
"intermediateSteps": [
120+
{
121+
"action": {
122+
"tool": "Date_Time",
123+
"toolInput": {
124+
"Include_Current_Time": true,
125+
"Timezone": "Europe/London"
126+
},
127+
"toolCallId": "call_FB0sIgrwuIGJkOaROor7raU2",
128+
"log": "Calling Date_Time with input: {...}"
129+
},
130+
"observation": "[{\"currentDate\":\"2025-10-10T09:46:45.754+01:00\"}]"
131+
},
132+
{
133+
"action": {
134+
"tool": "Wikipedia",
135+
"toolInput": {
136+
"input": "Europe/London time zone Wikipedia"
137+
},
138+
"toolCallId": "call_QFUtaSdUI2PtgjhkDTmbRknt",
139+
"log": "Calling Wikipedia with input: {...}"
140+
},
141+
"observation": "Page: Time zone\nSummary: Time zones are regions..."
142+
}
143+
]
144+
}
145+
]
146+
```
147+
148+
### UI Display
149+
150+
The user will see:
151+
152+
1. **Main Response**: The agent's text response from the `output` field
153+
2. **Tool Calls Section**: A collapsible section with all tool invocations
154+
155+
## Implementation Details
156+
157+
### Streaming Mode ⚠️
158+
159+
> **Not Supported**: N8N AI Agent does not include `intermediateSteps` in streaming responses. The streaming mode only sends content chunks, not metadata. This is a limitation of N8N's implementation.
160+
161+
### Non-Streaming Mode ✅
162+
163+
- Tool calls are extracted from the complete response JSON
164+
- Supports both array `[{...}]` and object `{...}` response formats
165+
- Automatically detects and formats all tool calls from `intermediateSteps`
166+
167+
### Data Structure Support
168+
169+
The pipeline handles both response formats from N8N:
170+
171+
**Array Format (typical for streaming):**
172+
173+
```json
174+
[
175+
{
176+
"output": "...",
177+
"intermediateSteps": [...]
178+
}
179+
]
180+
```
181+
182+
**Object Format (typical for non-streaming):**
183+
184+
```json
185+
{
186+
"output": "...",
187+
"intermediateSteps": [...]
188+
}
189+
```
190+
191+
## N8N Workflow Configuration
192+
193+
To enable this feature, your N8N workflow must:
194+
195+
1. **Use AI Agent Node**: Include an AI Agent node with tools
196+
2. **Disable Streaming**: In the "Respond to Webhook" node, ensure streaming is disabled
197+
3. **Return intermediateSteps**: Ensure your workflow returns the `intermediateSteps` array in the response
198+
199+
### Example N8N Workflow Structure
200+
201+
```txt
202+
Webhook Trigger
203+
204+
AI Agent (with tools: Wikipedia, Date/Time, etc.)
205+
206+
Function Node (format response)
207+
208+
Respond to Webhook
209+
```
210+
211+
**Function Node Code Example:**
212+
213+
```javascript
214+
// Get the AI Agent output
215+
const agentOutput = $('AI Agent').item.json;
216+
217+
return {
218+
output: agentOutput.output,
219+
intermediateSteps: agentOutput.intermediateSteps || []
220+
};
221+
```
222+
223+
## Supported Tools
224+
225+
The display works with any N8N tool, including:
226+
227+
- 📅 Date/Time
228+
- 📚 Wikipedia
229+
- 🔍 Search
230+
- 🧮 Calculator
231+
- 🌐 HTTP Request
232+
- 📧 Email
233+
- 💾 Database queries
234+
- And any custom tools you create!
235+
236+
## Configuration
237+
238+
### Pipeline Settings
239+
240+
Configure tool display in the N8N pipeline settings (Admin Panel → Functions → N8N Pipeline):
241+
242+
| Setting | Default | Description |
243+
|---------|---------|-------------|
244+
| `TOOL_DISPLAY_VERBOSITY` | `detailed` | Display mode: `minimal`, `compact`, or `detailed` |
245+
| `TOOL_INPUT_MAX_LENGTH` | `500` | Maximum characters for tool input. Set to `0` for unlimited (no truncation) |
246+
| `TOOL_OUTPUT_MAX_LENGTH` | `500` | Maximum characters for tool output. Set to `0` for unlimited in detailed mode (compact mode uses 100 char preview) |
247+
248+
### Recommendations
249+
250+
> [!TIP]
251+
> **For Production Use**:
252+
>
253+
> - Use `compact` mode for cleaner UI with essential info
254+
> - Set `TOOL_OUTPUT_MAX_LENGTH` to 200-300 for long outputs like Wikipedia
255+
>
256+
> **For Development/Debugging**:
257+
>
258+
> - Use `detailed` mode to see all information
259+
> - Set lengths to 0 (unlimited) to see complete data
260+
>
261+
> **For Minimal UI**:
262+
>
263+
> - Use `minimal` mode to just show tool names
264+
> - Perfect for when you only need to know which tools were called
265+
266+
## Troubleshooting
267+
268+
### Tool Calls Not Showing?
269+
270+
Check that:
271+
272+
1. ✅ Your N8N workflow includes an AI Agent node with tools
273+
2. ✅ The response includes the `intermediateSteps` array
274+
3. ✅ The N8N pipeline version is 2.2.0 or higher
275+
4. ✅ The response structure matches the expected format (see examples above)
276+
5. ✅ You're using non-streaming mode (streaming doesn't support tool display)
277+
278+
### Debugging
279+
280+
Enable debug logging in the pipeline to see:
281+
282+
- Number of intermediate steps found
283+
- Tool call extraction process
284+
- Response parsing details
285+
286+
The pipeline logs helpful messages like:
287+
288+
```txt
289+
Found 3 intermediate steps
290+
Added 3 tool calls to response
291+
```
292+
293+
## Related Documentation
294+
295+
- [N8N Integration Overview](./n8n-integration.md)
296+
- [N8N Template Workflows](../pipelines/n8n/)
297+
- [N8N AI Agent Documentation](https://docs.n8n.io/integrations/builtin/cluster-nodes/root-nodes/n8n-nodes-langchain.agent/)

0 commit comments

Comments
 (0)