Scalable Multi-Agent Chat Using @mentions
Last edited 151 days ago
Summary
Engage multiple, uniquely configured AI agents (using different models via OpenRouter) in a single conversation. Trigger specific agents with @mentions or let them all respond. Easily scalable by editing simple JSON settings.
Overview
This workflow is for users who want to experiment with or utilize multiple AI agents with distinct personalities, instructions, and underlying models within a single chat interface, without complex setup. It solves the problem of managing and interacting with diverse AI assistants simultaneously for tasks like brainstorming, comparative analysis, or role-playing scenarios.
It enables dynamic conversations with multiple AI assistants simultaneously within a single chat interface. You can:
- Define multiple unique AI agents.
- Configure each agent with its own name, system instructions, and LLM model (via OpenRouter).
- Interact with specific agents using
@AgentNamementions. - Have all agents respond (in random order) if no specific agents are mentioned.
- Maintain conversation history across multiple turns.
It's designed for flexibility and scalability, allowing you to easily add or modify agents without complex workflow restructuring.
Key Features
- Multi-Agent Interaction: Chat with several distinct AI personalities at once.
- Individual Agent Configuration: Customize name, system prompt, and LLM for each agent.
- OpenRouter Integration: Access a wide variety of LLMs compatible with OpenRouter.
- Mention-Based Triggering: Direct messages to specific agents using
@AgentName. - All-Agent Fallback: Engages all defined agents randomly if no mentions are used.
- Scalable Setup: Agent configuration is centralized in a single Code node (as JSON).
- Conversation Memory: Remembers previous interactions within the session.
How to Set Up
- Configure Settings (Code Nodes):
- Open the
Define Global SettingsCode node: Edit the JSON to set user details (name, location, notes) and add any system message instructions that all agents should follow. - Open the
Define Agent SettingsCode node: Edit the JSON to define your agents. Add or remove agent objects as needed. For each agent, specify:"name": The unique name for the agent (used for @mentions)."model": The OpenRouter model identifier (e.g.,"openai/gpt-4o","anthropic/claude-3.7-sonnet")."systemMessage": Specific instructions or persona for this agent.
- Open the
- Add OpenRouter Credentials:
- Locate the
AI Agentnode. - Click the
OpenRouter Chat Modelnode connected below it via theLanguage Modelinput. - In the 'Credential for OpenRouter API' field, select or create your OpenRouter API credentials.
- Locate the
How to Use
- Start a conversation using the Chat Trigger input.
- To address specific agents, include
@AgentNamein your message. Agents will respond sequentially in the order they are mentioned.- Example:
"@Gemma @Claude, please continue the count: 1"will trigger Gemma first, followed by Claude.
- Example:
- If your message contains no
@mentions, all agents defined inDefine Agent Settingswill respond in a randomized order.- Example:
"What are your thoughts on the future of AI?"will trigger Chad, Claude, and Gemma (based on your default settings) in a random sequence.
- Example:
- The workflow will collect responses from all triggered agents and return them as a single, formatted message.
How It Works (Technical Details)
- Settings Nodes:
Define Global SettingsandDefine Agent Settingsload your configurations. - Mention Extraction: The
Extract mentionsCode node parses the user's input (chatInput) from theWhen chat message receivedtrigger. It looks for@AgentNamepatterns matching the names defined inDefine Agent Settings. - Agent Selection:
- If mentions are found, it creates a list of the corresponding agent configurations in the order they were mentioned.
- If no mentions are found, it creates a list of all defined agent configurations and shuffles them randomly.
- Looping: The
Loop Over Itemsnode iterates through the selected agent list. - Dynamic Agent Execution: Inside the loop:
- An
Ifnode (First loop?) checks if it's the first agent responding. If yes (truepath ->Set user message as input), it passes the original user message to the Agent. If no (falsepath ->Set last Assistant message as input), it passes the previous agent's formatted output (lastAssistantMessage) to the next agent, creating a sequential chain. - The
AI Agentnode receives the input message. ItsSystem Messageand theModelin the connectedOpenRouter Chat Modelnode are dynamically populated using expressions referencing the current agent's data from the loop ({{ $('Loop Over Items').item.json.* }}). - The
Simple Memorynode provides conversation history to theAI Agent. - The agent's response is formatted (e.g.,
**AgentName**:\n\nResponse) in theSet lastAssistantMessagenode.
- An
- Response Aggregation: After the loop finishes, the
Combine and format responsesCode node gathers all thelastAssistantMessageoutputs and joins them into a single text block, separated by horizontal rules (---), ready to be sent back to the user.
Benefits
- Scalability & Flexibility: Instead of complex branching logic, adding, removing, or modifying agents only requires editing simple JSON in the
Define Agent Settingsnode, making setup and maintenance significantly easier, especially for those managing multiple assistants. - Model Choice: Use the best model for each agent's specific task or persona via OpenRouter.
- Centralized Configuration: Keeps agent setup tidy and manageable.
Limitations
- Sequential Responses: Agents respond one after another based on mention order (or randomly), not in parallel.
- No Direct Agent-to-Agent Interaction (within a turn): Agents cannot directly call or reply to each other during the processing of a single user message. Agent B sees Agent A's response only because the workflow passes it as input in the next loop iteration.
- Delayed Output: The user receives the combined response only after all triggered agents have completed their generation.
You may also like
New to n8n?
Need help building new n8n workflows? Process automation for you or your company will save you time and money, and it's completely free!





