// Classification Node
{
"url": "http://localhost:8005/api/v1/agents/classifier/invoke",
"jsonBody": "{\"message\": \"Classify this content: {{ $json.content }}\"}"
}
// Switch Node Logic
{
"rules": [
{
"operation": "equal",
"value1": "{{ $node.Classifier.json.result.type }}",
"value2": "blog"
},
{
"operation": "equal",
"value1": "{{ $node.Classifier.json.result.type }}",
"value2": "social"
}
]
}
How It Works
Quick Start
1
Start PraisonAI API Server
0.0.0.0 and set an API key:--auth (with CALL_SERVER_TOKEN) is the legacy praisonai/jobs/server.py call-server flag — not the serve agents auth. For praisonai serve agents, use --api-key / PRAISONAI_SERVE_API_KEY instead — see Agents Server → Security.2
Configure n8n HTTP Request Node
3
Test the Integration
API Endpoints
POST /api/v1/agents//invoke
Invoke a specific PraisonAI agent with input data. URL Parameters:
Request Body:
Optional Fields:
Supported agent_config keys
agent_config overrides only the whitelisted attributes below on the request’s isolated clone. Any other key returns a 400.
Behavior changed in v4.6.162. Before then, unknown keys were logged and silently ignored.
The
llm override now takes effect on the request it is sent with. Prior to this release (PR #4400), the wrapper set agent.llm but did not invalidate the cached LLM instance, so the request continued to run on the previously cached model while the response metadata reported the new one. If you rely on per-request model switching (A/B tests, cost tiering by caller), verify against your provider’s billing dashboard that the actual model matches the requested one.400 status:
The non-FastAPI standalone path (
invoke_agent_standalone) returns the same rejection as {"error": "...", "status": "error", "agent_id": "..."} instead of raising an HTTP 400.Session semantics
session_id isolates conversations per id, resumes history within an id, and runs ephemerally when omitted.
Per-request cleanup
/invoke releases the per-request clone deterministically. After every response — success or error — the wrapper calls await agent.aclose() (or agent.close() in a worker thread when the clone only exposes the sync form). Only clones are closed; when the resolved agent is the shared registry template (plain mocks / non-isolatable agents) it is left untouched, so subsequent requests don’t hit a torn-down instance.
This means:
- MCP stdio subprocesses started by a clone’s tools are terminated before the response returns — no
node.exe/uvx …accumulation in long-lived n8n polling loops. - LLM HTTP client pools and tool-executor threads owned by the clone are released.
- Cleanup failures never mask the response — they are caught and logged (
logger.exception("Agent cleanup failed")).
AgentInvokeRequest / AgentInvokeResponse are unchanged. This is a wrapper-internal fix delivered in PR #5083.
Every deployment that serves
praisonai serve agents.yaml (or embeds router from praisonai.api.agent_invoke) gets this cleanup automatically — including every n8n workflow that hits the endpoint. See Agent Lifecycle Cleanup and Agent Invoke Registry.GET /api/v1/agents
List all available agents. Response:GET /api/v1/health
Check API server health status. Response:n8n HTTP Request Configuration
Basic Configuration
- Simple Agent Call
- With Session Management
- With Authentication
Advanced Configuration
Dynamic Agent Selection
Dynamic Agent Selection
Error Handling
Error Handling
Response Processing
Response Processing
Authentication
Token-Based Authentication
Set up authentication for secure API access:- Server Setup
- n8n Configuration
- Environment Variables
API Key Management
Rotation Strategy
Rotation Strategy
Implement token rotation for enhanced security:
Multiple Environments
Multiple Environments
Use different tokens for different environments:
Workflow Examples
Sequential Agent Workflow
- n8n Workflow
- HTTP Node Configuration
- Test Webhook
Create a research → write → publish workflow:
- Webhook Trigger: Receives initial request
- Researcher HTTP Node: Calls
/agents/researcher/invoke - Writer HTTP Node: Calls
/agents/writer/invokewith research data - Publisher HTTP Node: Calls
/agents/publisher/invokewith content - Response Node: Returns final result
Conditional Routing Workflow
Smart Content Router
Smart Content Router
Route content to different agents based on type:
Error Recovery Workflow
Error Recovery Workflow
Implement fallback logic for failed agent calls:
Best Practices
Error Handling
Error Handling
Implement robust error handling in n8n workflows:
Data Validation
Data Validation
Validate data before sending to agents:When your workflow already knows who is talking (a user id, a customer id, a chat id), pass that stable value as
session_id. When it doesn’t, omit the field — the endpoint’s ephemeral mode is the correct default. Do not synthesise ids per-run.Performance Optimization
Performance Optimization
Optimize API calls for better performance:
- Batch Requests: Group multiple agent calls when possible
- Parallel Execution: Use fan-out patterns for independent calls
- Caching: Store frequently used results in Set nodes
- Connection Pooling: Configure HTTP node connection limits
- Timeouts: Set appropriate timeouts based on agent complexity
Security
Security
Secure your API integration:
- Authentication: Always use CALL_SERVER_TOKEN in production
- HTTPS: Use encrypted connections for remote APIs
- Input Sanitization: Validate and sanitize user inputs
- Rate Limiting: Implement rate limiting on the PraisonAI server
- Logging: Enable request logging for audit trails
Troubleshooting
Common Issues
- Connection Errors
- Authentication Errors
- Agent Not Found
- Conversations Mixing
- agent_config rejected
- llm override ignored
- Rising memory / threads / MCP subprocesses
Debugging Steps
- Check Server Status: Verify PraisonAI API is running
- Test Endpoints: Use curl to test API endpoints directly
- Validate Credentials: Confirm authentication tokens are correct
- Review Logs: Check both n8n and PraisonAI logs for errors
- Network Connectivity: Ensure n8n can reach PraisonAI server
Related
n8n Integration Overview
Complete guide to n8n integration architecture and setup
n8n Tools Reference
PraisonAI tools for executing n8n workflows from agents
Visual Workflow Editor
Export and edit PraisonAI workflows in n8n’s visual interface
CLI n8n Commands
Command-line tools for n8n workflow management
Agent Lifecycle Cleanup
How per-request clones release LLM clients and MCP subprocesses
Agent Invoke Registry
Templates vs. per-request clones and their teardown

