# Install with n8n supportpip install "praisonai-tools[n8n]"# Or install httpx manuallypip install praisonai-tools httpx
2
Basic Usage
from praisonaiagents import Agentfrom praisonai_tools.n8n import n8n_workflowagent = Agent( name="automation-agent", instructions="Execute n8n workflows for automation tasks", tools=[n8n_workflow])agent.start("Execute the slack-notify workflow to send a welcome message")
3
With Configuration
from praisonai_tools.n8n import n8n_workflow, n8n_list_workflows# Direct tool usageresult = n8n_workflow( workflow_id="slack-notify", input_data={ "channel": "#general", "message": "Hello from PraisonAI!" }, n8n_url="http://localhost:5678", api_key="your-api-key")
from praisonaiagents import Agentfrom praisonai_tools.n8n import n8n_workflow, n8n_list_workflowsagent = Agent( name="automation-agent", instructions=""" You help users automate tasks using n8n workflows. Available actions: - List workflows to see what's available - Execute workflows with appropriate input data - Explain what each workflow does based on its name Always ask for clarification if workflow parameters are unclear. """, tools=[n8n_workflow, n8n_list_workflows], llm="gpt-4o-mini")# Example usageagent.start("Send a Slack message to #deployments saying 'Build completed'")
from praisonaiagents import Agentfrom praisonai_tools.n8n import n8n_workflowdata_agent = Agent( name="data-processor", instructions=""" You process and transform data using n8n workflows. Capabilities: - Google Sheets integration - Database operations (PostgreSQL, MongoDB) - CSV processing - API data fetching - File transformations Format data appropriately for each workflow's requirements. """, tools=[n8n_workflow], llm="gpt-4o")# Example usagedata_agent.start("Add this customer data to the CRM spreadsheet: John Doe, john@example.com, Premium Plan")
from praisonaiagents import Agentfrom praisonai_tools.n8n import n8n_workflownotifier = Agent( name="notification-agent", instructions=""" You send notifications across multiple platforms using n8n workflows. Available channels: - Slack (channels and DMs) - Email (Gmail, Outlook) - Discord - Telegram - WhatsApp - Microsoft Teams Choose the appropriate channel based on urgency and content type. """, tools=[n8n_workflow], llm="gpt-4o-mini")# Example usagenotifier.start("Notify the team about the server maintenance scheduled for tonight")
from praisonai_tools.n8n import n8n_workflowresult = n8n_workflow( workflow_id="slack-notify", input_data={"message": "Test message"})if "error" in result: print(f"Workflow failed: {result['error']}")else: print(f"Workflow succeeded: {result.get('status')}")
from praisonaiagents import Agentfrom praisonai_tools.n8n import n8n_workflowagent = Agent( name="robust-agent", instructions=""" When executing n8n workflows: 1. Always check the result for errors 2. If a workflow fails, try to understand why: - Invalid workflow ID? - Missing required input data? - n8n server unreachable? 3. Provide helpful feedback to the user 4. Suggest corrections when possible """, tools=[n8n_workflow])
import timefrom praisonai_tools.n8n import n8n_workflowdef execute_with_retry(workflow_id, input_data, max_retries=3): for attempt in range(max_retries): result = n8n_workflow( workflow_id=workflow_id, input_data=input_data, timeout=30.0 ) if "error" not in result: return result if "timeout" in result["error"].lower() and attempt < max_retries - 1: time.sleep(2 ** attempt) # Exponential backoff continue else: return result return {"error": f"Failed after {max_retries} attempts"}
Error Handling: Include error nodes to handle failures gracefully
Input Data Validation
Validate input data before passing to workflows:
def validate_slack_input(data): required = ["channel", "message"] missing = [key for key in required if key not in data] if missing: return {"error": f"Missing required fields: {missing}"} if not data["channel"].startswith("#"): data["channel"] = f"#{data['channel']}" return data# Use in agent instructionsagent = Agent( name="slack-agent", instructions="Always validate Slack input data before executing workflows", tools=[n8n_workflow])
Security Considerations
Keep sensitive data secure:
Store API keys and secrets in n8n credential storage, not workflow inputs