bps-kit 1.2.2 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/.bps-kit.json +4 -4
  2. package/README.md +3 -0
  3. package/implementation_plan.md.resolved +37 -0
  4. package/package.json +2 -2
  5. package/templates/agents-template/ARCHITECTURE.md +21 -9
  6. package/templates/agents-template/agents/automation-specialist.md +157 -0
  7. package/templates/agents-template/rules/GEMINI.md +2 -10
  8. package/templates/agents-template/workflows/automate.md +153 -0
  9. package/templates/skills_normal/n8n-code-javascript/BUILTIN_FUNCTIONS.md +764 -0
  10. package/templates/skills_normal/n8n-code-javascript/COMMON_PATTERNS.md +1110 -0
  11. package/templates/skills_normal/n8n-code-javascript/DATA_ACCESS.md +782 -0
  12. package/templates/skills_normal/n8n-code-javascript/ERROR_PATTERNS.md +763 -0
  13. package/templates/skills_normal/n8n-code-javascript/README.md +350 -0
  14. package/templates/skills_normal/n8n-code-javascript/SKILL.md +699 -0
  15. package/templates/skills_normal/n8n-code-python/COMMON_PATTERNS.md +794 -0
  16. package/templates/skills_normal/n8n-code-python/DATA_ACCESS.md +702 -0
  17. package/templates/skills_normal/n8n-code-python/ERROR_PATTERNS.md +601 -0
  18. package/templates/skills_normal/n8n-code-python/README.md +386 -0
  19. package/templates/skills_normal/n8n-code-python/SKILL.md +748 -0
  20. package/templates/skills_normal/n8n-code-python/STANDARD_LIBRARY.md +974 -0
  21. package/templates/skills_normal/n8n-expression-syntax/COMMON_MISTAKES.md +393 -0
  22. package/templates/skills_normal/n8n-expression-syntax/EXAMPLES.md +483 -0
  23. package/templates/skills_normal/n8n-expression-syntax/README.md +93 -0
  24. package/templates/skills_normal/n8n-expression-syntax/SKILL.md +516 -0
  25. package/templates/skills_normal/n8n-mcp-tools-expert/README.md +99 -0
  26. package/templates/skills_normal/n8n-mcp-tools-expert/SEARCH_GUIDE.md +374 -0
  27. package/templates/skills_normal/n8n-mcp-tools-expert/SKILL.md +642 -0
  28. package/templates/skills_normal/n8n-mcp-tools-expert/VALIDATION_GUIDE.md +442 -0
  29. package/templates/skills_normal/n8n-mcp-tools-expert/WORKFLOW_GUIDE.md +618 -0
  30. package/templates/skills_normal/n8n-node-configuration/DEPENDENCIES.md +789 -0
  31. package/templates/skills_normal/n8n-node-configuration/OPERATION_PATTERNS.md +913 -0
  32. package/templates/skills_normal/n8n-node-configuration/README.md +364 -0
  33. package/templates/skills_normal/n8n-node-configuration/SKILL.md +785 -0
  34. package/templates/skills_normal/n8n-validation-expert/ERROR_CATALOG.md +943 -0
  35. package/templates/skills_normal/n8n-validation-expert/FALSE_POSITIVES.md +720 -0
  36. package/templates/skills_normal/n8n-validation-expert/README.md +290 -0
  37. package/templates/skills_normal/n8n-validation-expert/SKILL.md +689 -0
  38. package/templates/skills_normal/n8n-workflow-patterns/README.md +251 -0
  39. package/templates/skills_normal/n8n-workflow-patterns/SKILL.md +411 -0
  40. package/templates/skills_normal/n8n-workflow-patterns/ai_agent_workflow.md +784 -0
  41. package/templates/skills_normal/n8n-workflow-patterns/database_operations.md +785 -0
  42. package/templates/skills_normal/n8n-workflow-patterns/http_api_integration.md +734 -0
  43. package/templates/skills_normal/n8n-workflow-patterns/scheduled_tasks.md +773 -0
  44. package/templates/skills_normal/n8n-workflow-patterns/webhook_processing.md +545 -0
  45. package/templates/vault/n8n-code-javascript/SKILL.md +10 -10
  46. package/templates/vault/n8n-code-python/SKILL.md +11 -11
  47. package/templates/vault/n8n-expression-syntax/SKILL.md +4 -4
  48. package/templates/vault/n8n-mcp-tools-expert/SKILL.md +9 -9
  49. package/templates/vault/n8n-node-configuration/SKILL.md +2 -2
  50. package/templates/vault/n8n-validation-expert/SKILL.md +3 -3
  51. package/templates/vault/n8n-workflow-patterns/SKILL.md +11 -11
@@ -0,0 +1,784 @@
1
+ # AI Agent Workflow Pattern
2
+
3
+ **Use Case**: Build AI agents with tool access, memory, and reasoning capabilities.
4
+
5
+ ---
6
+
7
+ ## Pattern Structure
8
+
9
+ ```
10
+ Trigger → AI Agent (Model + Tools + Memory) → [Process Response] → Output
11
+ ```
12
+
13
+ **Key Characteristic**: AI-powered decision making with tool use
14
+
15
+ ---
16
+
17
+ ## Core AI Connection Types
18
+
19
+ n8n supports **8 AI connection types** for building agent workflows:
20
+
21
+ 1. **ai_languageModel** - The LLM (OpenAI, Anthropic, etc.)
22
+ 2. **ai_tool** - Functions the agent can call
23
+ 3. **ai_memory** - Conversation context
24
+ 4. **ai_outputParser** - Parse structured outputs
25
+ 5. **ai_embedding** - Vector embeddings
26
+ 6. **ai_vectorStore** - Vector database
27
+ 7. **ai_document** - Document loaders
28
+ 8. **ai_textSplitter** - Text chunking
29
+
30
+ ---
31
+
32
+ ## Core Components
33
+
34
+ ### 1. Trigger
35
+ **Options**:
36
+ - **Webhook** - Chat interfaces, API calls (most common)
37
+ - **Manual** - Testing and development
38
+ - **Schedule** - Periodic AI tasks
39
+
40
+ ### 2. AI Agent Node
41
+ **Purpose**: Orchestrate LLM with tools and memory
42
+
43
+ **Configuration**:
44
+ ```javascript
45
+ {
46
+ agent: "conversationalAgent", // or "openAIFunctionsAgent"
47
+ promptType: "define",
48
+ text: "You are a helpful assistant that can search docs, query databases, and send emails."
49
+ }
50
+ ```
51
+
52
+ **Connections**:
53
+ - **ai_languageModel input** - Connected to LLM node
54
+ - **ai_tool inputs** - Connected to tool nodes
55
+ - **ai_memory input** - Connected to memory node (optional)
56
+
57
+ ### 3. Language Model
58
+ **Available providers**:
59
+ - OpenAI (GPT-4, GPT-3.5)
60
+ - Anthropic (Claude)
61
+ - Google (Gemini)
62
+ - Local models (Ollama, LM Studio)
63
+
64
+ **Example** (OpenAI Chat Model):
65
+ ```javascript
66
+ {
67
+ model: "gpt-4",
68
+ temperature: 0.7,
69
+ maxTokens: 1000
70
+ }
71
+ ```
72
+
73
+ ### 4. Tools (ANY Node Can Be a Tool!)
74
+ **Critical insight**: Connect ANY n8n node to agent via `ai_tool` port
75
+
76
+ **Common tool types**:
77
+ - HTTP Request - Call APIs
78
+ - Database nodes - Query data
79
+ - Code - Custom functions
80
+ - Search nodes - Web/document search
81
+ - Pre-built tool nodes (Calculator, Wikipedia, etc.)
82
+
83
+ ### 5. Memory (Optional but Recommended)
84
+ **Purpose**: Maintain conversation context
85
+
86
+ **Types**:
87
+ - **Buffer Memory** - Store recent messages
88
+ - **Window Buffer Memory** - Store last N messages
89
+ - **Summary Memory** - Summarize conversation
90
+
91
+ ### 6. Output Processing
92
+ **Purpose**: Format AI response for delivery
93
+
94
+ **Common patterns**:
95
+ - Return directly (chat response)
96
+ - Store in database (conversation history)
97
+ - Send to communication channel (Slack, email)
98
+
99
+ ---
100
+
101
+ ## Common Use Cases
102
+
103
+ ### 1. Conversational Chatbot
104
+ **Flow**: Webhook (chat message) → AI Agent → Webhook Response
105
+
106
+ **Example** (Customer support bot):
107
+ ```
108
+ 1. Webhook (path: "chat", POST)
109
+ - Receives: {user_id, message, session_id}
110
+
111
+ 2. Window Buffer Memory (load context by session_id)
112
+
113
+ 3. AI Agent
114
+ ├─ OpenAI Chat Model (gpt-4)
115
+ ├─ HTTP Request Tool (search knowledge base)
116
+ ├─ Database Tool (query customer orders)
117
+ └─ Window Buffer Memory (conversation context)
118
+
119
+ 4. Code (format response)
120
+
121
+ 5. Webhook Response (send reply)
122
+ ```
123
+
124
+ **AI Agent prompt**:
125
+ ```
126
+ You are a customer support assistant.
127
+ You can:
128
+ 1. Search the knowledge base for answers
129
+ 2. Look up customer orders
130
+ 3. Provide shipping information
131
+
132
+ Be helpful and professional.
133
+ ```
134
+
135
+ ### 2. Document Q&A
136
+ **Flow**: Upload docs → Embed → Store → Query with AI
137
+
138
+ **Example** (Internal documentation assistant):
139
+ ```
140
+ Setup Phase (run once):
141
+ 1. Read Files (load documentation)
142
+ 2. Text Splitter (chunk into paragraphs)
143
+ 3. Embeddings (OpenAI Embeddings)
144
+ 4. Vector Store (Pinecone/Qdrant) (store vectors)
145
+
146
+ Query Phase (recurring):
147
+ 1. Webhook (receive question)
148
+ 2. AI Agent
149
+ ├─ OpenAI Chat Model (gpt-4)
150
+ ├─ Vector Store Tool (search similar docs)
151
+ └─ Buffer Memory (context)
152
+ 3. Webhook Response (answer with citations)
153
+ ```
154
+
155
+ ### 3. Data Analysis Assistant
156
+ **Flow**: Request → AI Agent (with data tools) → Analysis → Visualization
157
+
158
+ **Example** (SQL analyst agent):
159
+ ```
160
+ 1. Webhook (data question: "What were sales last month?")
161
+
162
+ 2. AI Agent
163
+ ├─ OpenAI Chat Model (gpt-4)
164
+ ├─ Postgres Tool (execute queries)
165
+ └─ Code Tool (data analysis)
166
+
167
+ 3. Code (generate visualization data)
168
+
169
+ 4. Webhook Response (answer + chart data)
170
+ ```
171
+
172
+ **Postgres Tool Configuration**:
173
+ ```javascript
174
+ {
175
+ name: "query_database",
176
+ description: "Execute SQL queries to analyze sales data. Use SELECT queries only.",
177
+ // Node executes AI-generated SQL
178
+ }
179
+ ```
180
+
181
+ ### 4. Workflow Automation Agent
182
+ **Flow**: Command → AI Agent → Execute actions → Report
183
+
184
+ **Example** (DevOps assistant):
185
+ ```
186
+ 1. Slack (slash command: /deploy production)
187
+
188
+ 2. AI Agent
189
+ ├─ OpenAI Chat Model (gpt-4)
190
+ ├─ HTTP Request Tool (GitHub API)
191
+ ├─ HTTP Request Tool (Deploy API)
192
+ └─ Postgres Tool (deployment logs)
193
+
194
+ 3. Agent actions:
195
+ - Check if tests passed
196
+ - Create deployment
197
+ - Log deployment
198
+ - Notify team
199
+
200
+ 4. Slack (deployment status)
201
+ ```
202
+
203
+ ### 5. Email Processing Agent
204
+ **Flow**: Email received → AI Agent → Categorize → Route → Respond
205
+
206
+ **Example** (Support ticket router):
207
+ ```
208
+ 1. Email Trigger (new support email)
209
+
210
+ 2. AI Agent
211
+ ├─ OpenAI Chat Model (gpt-4)
212
+ ├─ Vector Store Tool (search similar tickets)
213
+ └─ HTTP Request Tool (create Jira ticket)
214
+
215
+ 3. Agent actions:
216
+ - Categorize urgency (low/medium/high)
217
+ - Find similar past tickets
218
+ - Create ticket in appropriate project
219
+ - Draft response
220
+
221
+ 4. Email (send auto-response)
222
+ 5. Slack (notify assigned team)
223
+ ```
224
+
225
+ ---
226
+
227
+ ## Tool Configuration
228
+
229
+ ### Making ANY Node an AI Tool
230
+
231
+ **Critical concept**: Any n8n node can become an AI tool!
232
+
233
+ **Requirements**:
234
+ 1. Connect node to AI Agent via `ai_tool` port (NOT main port)
235
+ 2. Configure tool name and description
236
+ 3. Define input schema (optional)
237
+
238
+ **Example** (HTTP Request as tool):
239
+ ```javascript
240
+ {
241
+ // Tool metadata (for AI)
242
+ name: "search_github_issues",
243
+ description: "Search GitHub issues by keyword. Returns issue titles and URLs.",
244
+
245
+ // HTTP Request configuration
246
+ method: "GET",
247
+ url: "https://api.github.com/search/issues",
248
+ sendQuery: true,
249
+ queryParameters: {
250
+ "q": "={{$json.query}} repo:{{$json.repo}}",
251
+ "per_page": "5"
252
+ }
253
+ }
254
+ ```
255
+
256
+ **How it works**:
257
+ 1. AI Agent sees tool: `search_github_issues(query, repo)`
258
+ 2. AI decides to use it: `search_github_issues("bug", "n8n-io/n8n")`
259
+ 3. n8n executes HTTP Request with parameters
260
+ 4. Result returned to AI Agent
261
+ 5. AI Agent processes result and responds
262
+
263
+ ### Pre-built Tool Nodes
264
+
265
+ **Available in @n8n/n8n-nodes-langchain**:
266
+
267
+ - **Calculator Tool** - Math operations
268
+ - **Wikipedia Tool** - Wikipedia search
269
+ - **Serper Tool** - Google search
270
+ - **Wolfram Alpha Tool** - Computational knowledge
271
+ - **Custom Tool** - Define with Code node
272
+
273
+ **Example** (Calculator Tool):
274
+ ```
275
+ AI Agent
276
+ ├─ OpenAI Chat Model
277
+ └─ Calculator Tool (ai_tool connection)
278
+
279
+ User: "What's 15% of 2,847?"
280
+ AI: *uses calculator tool* → "426.05"
281
+ ```
282
+
283
+ ### Database as Tool
284
+
285
+ **Pattern**: Postgres/MySQL node connected as ai_tool
286
+
287
+ **Configuration**:
288
+ ```javascript
289
+ {
290
+ // Tool metadata
291
+ name: "query_customers",
292
+ description: "Query customer database. Use SELECT queries to find customer information by email, name, or ID.",
293
+
294
+ // Postgres config
295
+ operation: "executeQuery",
296
+ query: "={{$json.sql}}", // AI provides SQL
297
+ // Security: Use read-only database user!
298
+ }
299
+ ```
300
+
301
+ **Safety**: Create read-only DB user for AI tools!
302
+
303
+ ```sql
304
+ CREATE USER ai_readonly WITH PASSWORD 'secure_password';
305
+ GRANT SELECT ON customers, orders TO ai_readonly;
306
+ -- NO INSERT, UPDATE, DELETE access
307
+ ```
308
+
309
+ ### Code Node as Tool
310
+
311
+ **Pattern**: Custom Python/JavaScript function
312
+
313
+ **Example** (Data processor):
314
+ ```javascript
315
+ // Tool metadata
316
+ {
317
+ name: "process_csv",
318
+ description: "Process CSV data and return statistics. Input: csv_string"
319
+ }
320
+
321
+ // Code node
322
+ const csv = $input.first().json.csv_string;
323
+ const lines = csv.split('\n');
324
+ const data = lines.slice(1).map(line => line.split(','));
325
+
326
+ return [{
327
+ json: {
328
+ row_count: data.length,
329
+ columns: lines[0].split(','),
330
+ summary: {
331
+ // Calculate statistics
332
+ }
333
+ }
334
+ }];
335
+ ```
336
+
337
+ ---
338
+
339
+ ## Memory Configuration
340
+
341
+ ### Buffer Memory
342
+ **Stores all messages** (until cleared)
343
+
344
+ ```javascript
345
+ {
346
+ memoryType: "bufferMemory",
347
+ sessionKey: "={{$json.body.user_id}}" // Per-user memory
348
+ }
349
+ ```
350
+
351
+ ### Window Buffer Memory
352
+ **Stores last N messages** (recommended)
353
+
354
+ ```javascript
355
+ {
356
+ memoryType: "windowBufferMemory",
357
+ sessionKey: "={{$json.body.session_id}}",
358
+ contextWindowLength: 10 // Last 10 messages
359
+ }
360
+ ```
361
+
362
+ ### Summary Memory
363
+ **Summarizes old messages** (for long conversations)
364
+
365
+ ```javascript
366
+ {
367
+ memoryType: "summaryMemory",
368
+ sessionKey: "={{$json.body.session_id}}",
369
+ maxTokenLimit: 2000
370
+ }
371
+ ```
372
+
373
+ **How it works**:
374
+ 1. Conversation grows beyond limit
375
+ 2. AI summarizes old messages
376
+ 3. Summary stored, old messages discarded
377
+ 4. Saves tokens while maintaining context
378
+
379
+ ---
380
+
381
+ ## Agent Types
382
+
383
+ ### 1. Conversational Agent
384
+ **Best for**: General chat, customer support
385
+
386
+ **Features**:
387
+ - Natural conversation flow
388
+ - Memory integration
389
+ - Tool use with reasoning
390
+
391
+ **When to use**: Most common use case
392
+
393
+ ### 2. OpenAI Functions Agent
394
+ **Best for**: Tool-heavy workflows, structured outputs
395
+
396
+ **Features**:
397
+ - Optimized for function calling
398
+ - Better tool selection
399
+ - Structured responses
400
+
401
+ **When to use**: Multiple tools, need reliable tool calling
402
+
403
+ ### 3. ReAct Agent
404
+ **Best for**: Step-by-step reasoning
405
+
406
+ **Features**:
407
+ - Think → Act → Observe loop
408
+ - Visible reasoning process
409
+ - Good for debugging
410
+
411
+ **When to use**: Complex multi-step tasks
412
+
413
+ ---
414
+
415
+ ## Prompt Engineering for Agents
416
+
417
+ ### System Prompt Structure
418
+ ```
419
+ You are a [ROLE].
420
+
421
+ You can:
422
+ - [CAPABILITY 1]
423
+ - [CAPABILITY 2]
424
+ - [CAPABILITY 3]
425
+
426
+ Guidelines:
427
+ - [GUIDELINE 1]
428
+ - [GUIDELINE 2]
429
+
430
+ Format:
431
+ - [OUTPUT FORMAT]
432
+ ```
433
+
434
+ ### Example (Customer Support)
435
+ ```
436
+ You are a customer support assistant for Acme Corp.
437
+
438
+ You can:
439
+ - Search the knowledge base for answers
440
+ - Look up customer orders and shipping status
441
+ - Create support tickets for complex issues
442
+
443
+ Guidelines:
444
+ - Be friendly and professional
445
+ - If you don't know something, say so and offer to create a ticket
446
+ - Always verify customer identity before sharing order details
447
+
448
+ Format:
449
+ - Keep responses concise
450
+ - Use bullet points for multiple items
451
+ - Include relevant links when available
452
+ ```
453
+
454
+ ### Example (Data Analyst)
455
+ ```
456
+ You are a data analyst assistant with access to the company database.
457
+
458
+ You can:
459
+ - Query sales, customer, and product data
460
+ - Perform data analysis and calculations
461
+ - Generate summary statistics
462
+
463
+ Guidelines:
464
+ - Write efficient SQL queries (always use LIMIT)
465
+ - Explain your analysis methodology
466
+ - Highlight important trends or anomalies
467
+ - Use read-only queries (SELECT only)
468
+
469
+ Format:
470
+ - Provide numerical answers with context
471
+ - Include query used (for transparency)
472
+ - Suggest follow-up analyses when relevant
473
+ ```
474
+
475
+ ---
476
+
477
+ ## Error Handling
478
+
479
+ ### Pattern 1: Tool Execution Errors
480
+ ```
481
+ AI Agent (continueOnFail on tool nodes)
482
+ → IF (tool error occurred)
483
+ └─ Code (log error)
484
+ └─ Webhook Response (user-friendly error)
485
+ ```
486
+
487
+ ### Pattern 2: LLM API Errors
488
+ ```
489
+ Main Workflow:
490
+ AI Agent → Process Response
491
+
492
+ Error Workflow:
493
+ Error Trigger
494
+ → IF (rate limit error)
495
+ └─ Wait → Retry
496
+ → ELSE
497
+ └─ Notify Admin
498
+ ```
499
+
500
+ ### Pattern 3: Invalid Tool Outputs
501
+ ```javascript
502
+ // Code node - validate tool output
503
+ const result = $input.first().json;
504
+
505
+ if (!result || !result.data) {
506
+ throw new Error('Tool returned invalid data');
507
+ }
508
+
509
+ return [{ json: result }];
510
+ ```
511
+
512
+ ---
513
+
514
+ ## Performance Optimization
515
+
516
+ ### 1. Choose Right Model
517
+ ```
518
+ Fast & cheap: GPT-3.5-turbo, Claude 3 Haiku
519
+ Balanced: GPT-4, Claude 3 Sonnet
520
+ Powerful: GPT-4-turbo, Claude 3 Opus
521
+ ```
522
+
523
+ ### 2. Limit Context Window
524
+ ```javascript
525
+ {
526
+ memoryType: "windowBufferMemory",
527
+ contextWindowLength: 5 // Only last 5 messages
528
+ }
529
+ ```
530
+
531
+ ### 3. Optimize Tool Descriptions
532
+ ```javascript
533
+ // ❌ Vague
534
+ description: "Search for things"
535
+
536
+ // ✅ Clear and concise
537
+ description: "Search GitHub issues by keyword and repository. Returns top 5 matching issues with titles and URLs."
538
+ ```
539
+
540
+ ### 4. Cache Embeddings
541
+ For document Q&A, embed documents once:
542
+
543
+ ```
544
+ Setup (run once):
545
+ Documents → Embed → Store in Vector DB
546
+
547
+ Query (fast):
548
+ Question → Search Vector DB → AI Agent
549
+ ```
550
+
551
+ ### 5. Async Tools for Slow Operations
552
+ ```
553
+ AI Agent → [Queue slow tool request]
554
+ → Return immediate response
555
+ → [Background: Execute tool + notify when done]
556
+ ```
557
+
558
+ ---
559
+
560
+ ## Security Considerations
561
+
562
+ ### 1. Read-Only Database Tools
563
+ ```sql
564
+ -- Create limited user for AI tools
565
+ CREATE USER ai_agent_ro WITH PASSWORD 'secure';
566
+ GRANT SELECT ON public.* TO ai_agent_ro;
567
+ -- NO write access!
568
+ ```
569
+
570
+ ### 2. Validate Tool Inputs
571
+ ```javascript
572
+ // Code node - validate before execution
573
+ const query = $json.query;
574
+
575
+ if (query.toLowerCase().includes('drop ') ||
576
+ query.toLowerCase().includes('delete ') ||
577
+ query.toLowerCase().includes('update ')) {
578
+ throw new Error('Invalid query - write operations not allowed');
579
+ }
580
+ ```
581
+
582
+ ### 3. Rate Limiting
583
+ ```
584
+ Webhook → IF (check user rate limit)
585
+ ├─ [Within limit] → AI Agent
586
+ └─ [Exceeded] → Error (429 Too Many Requests)
587
+ ```
588
+
589
+ ### 4. Sanitize User Input
590
+ ```javascript
591
+ // Code node
592
+ const userInput = $json.body.message
593
+ .trim()
594
+ .substring(0, 1000); // Max 1000 chars
595
+
596
+ return [{ json: { sanitized: userInput } }];
597
+ ```
598
+
599
+ ### 5. Monitor Tool Usage
600
+ ```
601
+ AI Agent → Log Tool Calls
602
+ → IF (suspicious pattern)
603
+ └─ Alert Admin + Pause Agent
604
+ ```
605
+
606
+ ---
607
+
608
+ ## Testing AI Agents
609
+
610
+ ### 1. Start with Manual Trigger
611
+ Replace webhook with manual trigger:
612
+ ```
613
+ Manual Trigger
614
+ → Set (mock user input)
615
+ → AI Agent
616
+ → Code (log output)
617
+ ```
618
+
619
+ ### 2. Test Tools Independently
620
+ Before connecting to agent:
621
+ ```
622
+ Manual Trigger → Tool Node → Verify output format
623
+ ```
624
+
625
+ ### 3. Test with Standard Questions
626
+ Create test suite:
627
+ ```
628
+ 1. "Hello" - Test basic response
629
+ 2. "Search for bug reports" - Test tool calling
630
+ 3. "What did I ask before?" - Test memory
631
+ 4. Invalid input - Test error handling
632
+ ```
633
+
634
+ ### 4. Monitor Token Usage
635
+ ```javascript
636
+ // Code node - log token usage
637
+ console.log('Input tokens:', $node['AI Agent'].json.usage.input_tokens);
638
+ console.log('Output tokens:', $node['AI Agent'].json.usage.output_tokens);
639
+ ```
640
+
641
+ ### 5. Test Edge Cases
642
+ - Empty input
643
+ - Very long input
644
+ - Tool returns no results
645
+ - Tool returns error
646
+ - Multiple tool calls in sequence
647
+
648
+ ---
649
+
650
+ ## Common Gotchas
651
+
652
+ ### 1. ❌ Wrong: Connecting tools to main port
653
+ ```
654
+ HTTP Request → AI Agent // Won't work as tool!
655
+ ```
656
+
657
+ ### ✅ Correct: Use ai_tool connection type
658
+ ```
659
+ HTTP Request --[ai_tool]--> AI Agent
660
+ ```
661
+
662
+ ### 2. ❌ Wrong: Vague tool descriptions
663
+ ```
664
+ description: "Get data" // AI won't know when to use this
665
+ ```
666
+
667
+ ### ✅ Correct: Specific descriptions
668
+ ```
669
+ description: "Query customer orders by email address. Returns order ID, status, and shipping info."
670
+ ```
671
+
672
+ ### 3. ❌ Wrong: No memory for conversations
673
+ ```
674
+ Every message is standalone - no context!
675
+ ```
676
+
677
+ ### ✅ Correct: Add memory
678
+ ```
679
+ Window Buffer Memory --[ai_memory]--> AI Agent
680
+ ```
681
+
682
+ ### 4. ❌ Wrong: Giving AI write access
683
+ ```
684
+ Postgres (full access) as tool // AI could DELETE data!
685
+ ```
686
+
687
+ ### ✅ Correct: Read-only access
688
+ ```
689
+ Postgres (read-only user) as tool // Safe
690
+ ```
691
+
692
+ ### 5. ❌ Wrong: Unbounded tool responses
693
+ ```
694
+ Tool returns 10MB of data → exceeds token limit
695
+ ```
696
+
697
+ ### ✅ Correct: Limit tool output
698
+ ```javascript
699
+ {
700
+ query: "SELECT * FROM table LIMIT 10" // Only 10 rows
701
+ }
702
+ ```
703
+
704
+ ---
705
+
706
+ ## Real Template Examples
707
+
708
+ From n8n template library (234 AI templates):
709
+
710
+ **Simple Chatbot**:
711
+ ```
712
+ Webhook → AI Agent (GPT-4 + Memory) → Webhook Response
713
+ ```
714
+
715
+ **Document Q&A**:
716
+ ```
717
+ Setup: Files → Embed → Vector Store
718
+ Query: Webhook → AI Agent (GPT-4 + Vector Store Tool) → Response
719
+ ```
720
+
721
+ **SQL Analyst**:
722
+ ```
723
+ Webhook → AI Agent (GPT-4 + Postgres Tool) → Format → Response
724
+ ```
725
+
726
+ Use `search_templates({query: "ai agent"})` to find more!
727
+
728
+ ---
729
+
730
+ ## Checklist for AI Agent Workflows
731
+
732
+ ### Planning
733
+ - [ ] Define agent purpose and capabilities
734
+ - [ ] List required tools (APIs, databases, etc.)
735
+ - [ ] Design conversation flow
736
+ - [ ] Plan memory strategy (per-user, per-session)
737
+ - [ ] Consider token costs
738
+
739
+ ### Implementation
740
+ - [ ] Choose appropriate LLM model
741
+ - [ ] Write clear system prompt
742
+ - [ ] Connect tools via ai_tool ports (NOT main)
743
+ - [ ] Add tool descriptions
744
+ - [ ] Configure memory (Window Buffer recommended)
745
+ - [ ] Test each tool independently
746
+
747
+ ### Security
748
+ - [ ] Use read-only database access for tools
749
+ - [ ] Validate tool inputs
750
+ - [ ] Sanitize user inputs
751
+ - [ ] Add rate limiting
752
+ - [ ] Monitor for abuse
753
+
754
+ ### Testing
755
+ - [ ] Test with diverse inputs
756
+ - [ ] Verify tool calling works
757
+ - [ ] Check memory persistence
758
+ - [ ] Test error scenarios
759
+ - [ ] Monitor token usage and costs
760
+
761
+ ### Deployment
762
+ - [ ] Add error handling
763
+ - [ ] Set up logging
764
+ - [ ] Monitor performance
765
+ - [ ] Set cost alerts
766
+ - [ ] Document agent capabilities
767
+
768
+ ---
769
+
770
+ ## Summary
771
+
772
+ **Key Points**:
773
+ 1. **8 AI connection types** - Use ai_tool for tools, ai_memory for context
774
+ 2. **ANY node can be a tool** - Connect to ai_tool port
775
+ 3. **Memory is essential** for conversations (Window Buffer recommended)
776
+ 4. **Tool descriptions matter** - AI uses them to decide when to call tools
777
+ 5. **Security first** - Read-only database access, validate inputs
778
+
779
+ **Pattern**: Trigger → AI Agent (Model + Tools + Memory) → Output
780
+
781
+ **Related**:
782
+ - [webhook_processing.md](webhook_processing.md) - Receiving chat messages
783
+ - [http_api_integration.md](http_api_integration.md) - Tools that call APIs
784
+ - [database_operations.md](database_operations.md) - Database tools for agents