For the complete documentation index, see llms.txt. This page is also available as Markdown.

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

  1. A registered n8n account

  2. A valid MaiAgent API key

  3. An Agent that has been set up, and its Agent ID

  4. 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

  1. Add a “When chat message received” node to the n8n workflow

  2. 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

  1. Add an “HTTP Request” node and connect it to the “When chat message received” node

  2. Configure the following settings:

    • Method: POST

    • URL:https://api.maiagent.ai/api/v1/chatbots/{id}/completions/

    • id: Agent ID

    • Authentication: Headers

    • Headers: Add an Authorization header with the value Api-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

  1. Add another “HTTP Request” node and connect it to the first HTTP Request node

  2. Configure the following settings:

    • Method: POST

    • URL:https://api.maiagent.ai/api/v1/chatbots/{id}/completions/

    • id: Agent ID

    • Authentication: Headers

    • Headers: Add an Authorization header with the value Api-Key YOUR_API_KEY

    • Request 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:

  1. Have a legal Agent analyze legal issues

  2. Have a technical Agent analyze technical feasibility

  3. Have a business Agent analyze business impact

  4. Finally, have an aggregation Agent provide combined recommendations

Scenario 2: Translation Improvement Process

  1. An initial Agent translates the content

  2. A second Agent checks translation quality

  3. A final Agent polishes and improves the wording

Scenario 3: Content Generation and Review Workflow

  1. A creative Agent generates content

  2. A review Agent checks accuracy and appropriateness

  3. 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

  1. Add an HTTP Request node to start the conversation

  2. Use settings similar to those above, but save the conversation ID:

Step 2: Set Up a Follow-up Conversation Node

  1. Add a new HTTP Request node and configure it to use the saved conversation ID:

Troubleshooting

Common issues and solutions:

  1. API Authentication Errors:Make sure the API key format is correct, including the “Api-Key” prefix

  2. Request Timeouts:For complex queries, increase the timeout of the HTTP Request node

  3. Handling Streaming Mode:Use is_streaming: true to 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?