n8n Integration
Integrate n8n with MaiAgent to call multiple Agents using workflow automation. Includes workflow examples, advanced multi-turn conversations, troubleshooting, and complete JSON.
This document provides detailed instructions for connecting multiple MaiAgent Agents using the n8n workflow automation tool. With n8n, you can easily build workflows that chain multiple Agents together.
Prerequisites
A registered n8n account
A valid MaiAgent API key
An Agent that has been set up, and its Agent ID
A basic understanding of APIs and workflows
Basic Concepts
The MaiAgent API lets you converse with Agents. We will use n8n to automate these interactions and chain multiple Agents together.
Workflow Examples
Example 1: Create a Simple Workflow That Chains Agents
This workflow receives a user’s chat message and processes it through two different Agents in sequence, creating a processing chain.
Step 1: Set Up the Chat Trigger Node
Add a “When chat message received” node to the n8n workflow
This is the starting point of the workflow and is triggered when a user sends a message
Step 2: Set Up the First HTTP Request Node
Add an “HTTP Request” node and connect it to the “When chat message received” node
Configure the following settings:
Method: POST
URL:
https://api.maiagent.ai/api/v1/chatbots/{id}/completions/id: Agent ID
Authentication: Headers
Headers: Add an
Authorizationheader with the valueApi-Key YOUR_API_KEY(replace it with your actual API key)Request body type: JSON
Request body:
Step 3: Set Up the Second HTTP Request Node
Add another “HTTP Request” node and connect it to the first HTTP Request node
Configure the following settings:
Method: POST
URL:
https://api.maiagent.ai/api/v1/chatbots/{id}/completions/id: Agent ID
Authentication: Headers
Headers: Add an
Authorizationheader with the valueApi-Key YOUR_API_KEYRequest body type: JSON
Request body:
This configuration passes the first Agent’s response as input to the second Agent, creating a processing chain.
Use Cases for Chaining Agents
Scenario 1: Aggregate Multiple Expert Opinions
Have Agents with different specialties provide their perspectives, then combine them into a comprehensive response:
Have a legal Agent analyze legal issues
Have a technical Agent analyze technical feasibility
Have a business Agent analyze business impact
Finally, have an aggregation Agent provide combined recommendations
Scenario 2: Translation Improvement Process
An initial Agent translates the content
A second Agent checks translation quality
A final Agent polishes and improves the wording
Scenario 3: Content Generation and Review Workflow
A creative Agent generates content
A review Agent checks accuracy and appropriateness
An editing Agent polishes the content and improves formatting
Advanced Usage: Create a Multi-turn Conversation Workflow
Example 2: Use a Conversation ID to Maintain a Multi-turn Conversation
Step 1: Create a Conversation Initialization Node
Add an HTTP Request node to start the conversation
Use settings similar to those above, but save the conversation ID:
Step 2: Set Up a Follow-up Conversation Node
Add a new HTTP Request node and configure it to use the saved conversation ID:
Troubleshooting
Common issues and solutions:
API Authentication Errors:Make sure the API key format is correct, including the “Api-Key” prefix
Request Timeouts:For complex queries, increase the timeout of the HTTP Request node
Handling Streaming Mode:Use
is_streaming: trueto switch responses to streaming mode
Conclusion
With n8n, you can easily integrate and automate multiple MaiAgent Agents to create powerful AI workflows in which Agents with different specialties collaborate on complex tasks. From simple conversations to complex processing chains involving multiple Agents, n8n provides flexible and powerful automation capabilities.
Appendix: Complete Workflow JSON
Below is the complete workflow JSON configuration for Example 1, which you can import directly into n8n:
Import Result

If you have any questions, refer to the official MaiAgent API documentation or the official n8n documentation.
Last updated
Was this helpful?