feat: Add n8n workflow automation integration#19
Conversation
…aisonAI#1396) - Add N8nWorkflowTool class for executing n8n workflows - Add n8n_workflow and n8n_list_workflows decorator functions - Provides access to 400+ integrations (Slack, Gmail, Notion, databases, APIs) - Includes comprehensive unit tests with mocking - Add example usage and documentation - Optional httpx dependency with lazy loading - Bidirectional PraisonAI ↔ n8n integration support
Greptile SummaryThis PR adds a bidirectional n8n workflow automation integration, introducing The two previously flagged blockers (missing Key changes:
Confidence Score: 4/5Safe to merge after the one-line "crashed" status fix; all previously flagged blockers are resolved. Both prior blocking issues (missing export and wrong module path in lazy-loader) are fully fixed. The remaining P1 is a single-line addition to the terminal-status set in _wait_for_execution; it degrades reliability (unnecessary full-timeout wait on crashed workflows) but does not corrupt data or break the happy path. The two P2 style issues are non-blocking. Overall the integration is well-structured with good test coverage. praisonai_tools/n8n/n8n_workflow.py — specifically the _wait_for_execution status check on line 136 and the hardcoded timeout in list_workflows on line 160. Important Files Changed
Sequence DiagramsequenceDiagram
participant Agent as PraisonAI Agent
participant TF as n8n_workflow()
participant Tool as N8nWorkflowTool
participant N8N as n8n REST API
Agent->>TF: n8n_workflow(workflow_id, input_data)
TF->>Tool: N8nWorkflowTool(url, api_key, timeout)
TF->>Tool: tool.run(workflow_id, input_data)
Tool->>N8N: POST /api/v1/workflows/{id}/execute
N8N-->>Tool: {executionId, status: running}
alt wait_for_completion=True
loop Poll every 2s up to timeout
Tool->>N8N: GET /api/v1/executions/{executionId}
N8N-->>Tool: {status: running|success|error|canceled}
Note over Tool,N8N: crashed not handled — keeps polling
end
end
Tool-->>TF: execution result dict
TF-->>Agent: result / error dict
Agent->>TF: n8n_list_workflows()
TF->>Tool: N8nWorkflowTool(url, api_key)
TF->>Tool: tool.list_workflows()
Tool->>N8N: GET /api/v1/workflows
N8N-->>Tool: {data: [...workflows]}
Tool-->>TF: workflows dict
TF-->>Agent: workflows / error dict
Reviews (2): Last reviewed commit: "fix: resolve critical n8n integration is..." | Re-trigger Greptile |
Additional Findings: n8n Management & Node CreationAfter deeper analysis, here are additional integration capabilities: n8n Workflow SDK (
|
| Endpoint | Purpose |
|---|---|
POST /api/v1/workflows |
Create workflow |
PUT /api/v1/workflows/{id} |
Update workflow |
DELETE /api/v1/workflows/{id} |
Delete workflow |
POST /api/v1/workflows/{id}/activate |
Activate |
POST /api/v1/workflows/{id}/deactivate |
Deactivate |
GET /api/v1/executions |
List executions |
POST /api/v1/executions/{id}/retry |
Retry execution |
POST /api/v1/executions/{id}/stop |
Stop execution |
GET /api/v1/credentials |
List credentials |
POST /api/v1/credentials |
Create credential |
Proposed: n8n Management Tools for PraisonAI
from praisonaiagents.tools import tool
@tool
def n8n_create_workflow(name: str, nodes: list, connections: dict) -> dict:
"""Create a new n8n workflow."""
...
@tool
def n8n_list_workflows(active: bool = None) -> list:
"""List all n8n workflows."""
...
@tool
def n8n_activate_workflow(workflow_id: str) -> dict:
"""Activate an n8n workflow."""
...
@tool
def n8n_get_executions(workflow_id: str = None, status: str = None) -> list:
"""Get workflow execution history."""
...This enables agents to fully manage n8n — create, update, activate, and monitor workflows programmatically.
Related Issue
See #1397 for the unique Visual Workflow Editor feature — converting PraisonAI YAML to n8n JSON for visual preview/editing.
not in praisonaiagents, but in praisonai-tools @claude validate
|
Claude finished @MervinPraison's task —— View job n8n Integration Validation Complete ✅I've successfully validated and fixed all critical issues identified in the n8n integration PR. Todo List:
Issues Fixed:✅ P0 Critical Issues:
✅ P1 Issues: Summary:The n8n integration is now ready for merge. All blocking issues have been resolved:
The integration provides access to 400+ n8n integrations through two @tool-decorated functions that follow the established praisonai-tools patterns. Fixes committed: --- | Branch: |
- Export n8n_list_workflows from __init__.py (fixes ImportError) - Fix module path in tools registry to use absolute imports - Update __getattr__ to handle absolute module paths - Fix timeout parameter not being used in _wait_for_execution - Update test mocking to work with lazy imports Addresses P0 and P1 issues identified in code review. Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
| execution = response.json() | ||
| status = execution.get("status") | ||
|
|
||
| if status in ["success", "error", "canceled"]: |
There was a problem hiding this comment.
"crashed" status causes full-timeout wait
The polling loop only exits early for "success", "error", and "canceled". n8n's REST API also returns "crashed" for workflows that fail with an unhandled exception. When a workflow crashes, the poller will keep polling until max_wait seconds are exhausted (default 60 s) before returning a timeout error — instead of exiting immediately.
| if status in ["success", "error", "canceled"]: | |
| if status in ["success", "error", "canceled", "crashed"]: |
Fixes MervinPraison/PraisonAI#1396
Overview
This PR implements bidirectional integration between PraisonAI agents and n8n workflow automation platform, providing access to 400+ integrations (Slack, Gmail, Notion, databases, APIs, etc.).
Key Features
Files Added
Core Implementation:
Configuration:
Tests & Examples:
Generated with Claude Code