n8n Integration
Bidirectional workflow automation between PraisonAI and n8n
n8n integration enables bidirectional workflow automation, connecting PraisonAI agents to n8n’s 400+ integrations including Slack, Gmail, Notion, databases, and APIs.
from praisonaiagents import Agent
from praisonai_tools.n8n import n8n_workflow
agent = Agent(
name="automation-agent",
instructions="Execute n8n workflows for automation tasks",
tools=[n8n_workflow],
)
agent.start("Send a Slack message to #general saying Hello!")The user asks the agent to automate a task; the agent invokes n8n workflows and integrations on their behalf.
Quick Start
- Install n8n Tools
bash pip install "praisonai-tools[n8n]" - Set Up n8n Instance
bash # Start n8n locally docker run -it --rm --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n # Set environment variables export N8N_URL="http://localhost:5678" export N8N_API_KEY="<your-n8n-api-key>" # Optional for local - Use in Agent
python from praisonaiagents import Agent from praisonai_tools.n8n import n8n_workflow agent = Agent( name="automation-agent", instructions="Execute n8n workflows for automation tasks", tools=[n8n_workflow] ) agent.start("Send a Slack message to #general saying Hello!")
How It Works
| Component | Purpose | Direction |
|---|---|---|
| PraisonAI โ n8n | Agents execute workflows via tools | Agent calls n8n |
| n8n โ PraisonAI | Workflows invoke agents via API | n8n calls Agent |
| Visual Editor | Preview YAML workflows in n8n UI | Export/Import |
Integration Directions
Agents execute n8n workflows to access 400+ integrations
n8n โ Agent APIn8n workflows invoke PraisonAI agents via HTTP endpoints
Visual Workflow EditorExport PraisonAI YAML workflows to n8n for visual editing
CLI Export ToolsCommand-line tools for n8n workflow export and management
Common Patterns
Notification Workflows
from praisonaiagents import Agent
from praisonai_tools.n8n import n8n_workflow
notification_agent = Agent(
name="notifier",
instructions="Send notifications via various channels",
tools=[n8n_workflow]
)
# Slack notification
notification_agent.start("Send deployment status to #deployments channel")
# Email notification
notification_agent.start("Email the marketing team about campaign results")Data Processing
from praisonaiagents import Agent
from praisonai_tools.n8n import n8n_workflow
data_agent = Agent(
name="data-processor",
instructions="Process data using n8n integrations",
tools=[n8n_workflow]
)
# Google Sheets integration
data_agent.start("Add this sales data to the Q1 spreadsheet")
# Database operations
data_agent.start("Store customer feedback in PostgreSQL")Multi-Step Automation
from praisonaiagents import Agent, Task, PraisonAIAgents
from praisonai_tools.n8n import n8n_workflow
# Multi-agent workflow with n8n
researcher = Agent(
name="researcher",
instructions="Research topics thoroughly",
tools=[n8n_workflow]
)
publisher = Agent(
name="publisher",
instructions="Publish content to multiple channels",
tools=[n8n_workflow]
)
# Create coordinated workflow
team = PraisonAIAgents(
agents=[researcher, publisher],
process="sequential"
)
team.start("Research AI trends and publish to blog and social media")Available Integrations
n8n provides 400+ integrations across multiple categories:
Communication & Messaging
- Chat: Slack, Discord, Microsoft Teams, Telegram, WhatsApp
- Email: Gmail, Outlook, SendGrid, Mailchimp
- Video: Zoom, Google Meet, Microsoft Teams
Productivity & Collaboration
- Documents: Notion, Google Docs, Microsoft Office, Confluence
- Spreadsheets: Google Sheets, Excel, Airtable
- Task Management: Trello, Jira, Linear, Asana, Monday.com
Databases & Storage
- SQL Databases: PostgreSQL, MySQL, SQL Server, Oracle
- NoSQL: MongoDB, Redis, Elasticsearch, DynamoDB
- Cloud Storage: Google Drive, Dropbox, AWS S3, Azure Blob
APIs & Development
- REST APIs: HTTP Request node, GraphQL
- Webhooks: Trigger and receive webhooks
- Git: GitHub, GitLab, Bitbucket integration
Best Practices
Error Handling
Always handle workflow errors gracefully in your agent instructions:
agent = Agent(
name="robust-agent",
instructions="""
When executing n8n workflows:
1. Check the result for errors
2. Retry with different parameters if needed
3. Provide clear feedback to the user
4. Log important details for debugging
""",
tools=[n8n_workflow]
)Environment Configuration
Use environment variables for configuration:
# Production setup
export N8N_URL="https://n8n.yourcompany.com"
export N8N_API_KEY="<your-n8n-api-key>"
# Development setup
export N8N_URL="http://localhost:5678"
# API key optional for local developmentWorkflow Organization
Create focused, single-purpose workflows in n8n:
- Good:
slack-notify,email-send,database-insert - Avoid:
do-everything-workflow
This makes workflows more reliable and easier to debug.
Security
Never expose sensitive data in workflow inputs:
# Good - use environment variables in n8n
result = n8n_workflow(
workflow_id="secure-api-call",
input_data={"endpoint": "https://api.example.com/data"}
)
# Avoid - don't pass API keys directly
# input_data={"api_key": "secret-key"} # DON'T DO THIS