|
| 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