How to Build a Multi-Agent Assistant in n8n

78.1K views
•
November 6, 2024
by
Nate Herk | AI Automation
YouTube video player
How to Build a Multi-Agent Assistant in n8n

TL;DR

Build a more scalable n8n personal assistant by letting one main agent route requests to specialized email, calendar, research, and project agents. Each specialized agent chooses and executes its own tools, while the $fromAI function extracts parameters such as event times, attendees, and titles directly from the user's query.

Transcript

so I said can you schedule a meeting for tomorrow with Michael Scott at noon and then can you email him to confirm if that works so we're going to fire that off we'll see it take place real quick it just got Michael Scott's email information from the contact database now it's going to go back to the agent and then the agent is going to figure out w... Read More

Key Insights

  • The upgraded architecture gives the main personal assistant access to four specialized agents instead of six individual tools. The four specialists handle email, calendar, research, and project requests, allowing the main agent to focus on interpreting each incoming message and routing it to the appropriate agent.
  • The main agent works as a request router that receives messages through a Telegram trigger. When a request involves email or scheduling, it gathers required contact information and delegates the task to the relevant specialized agent, which understands how to choose and operate its own tools.
  • The calendar agent has three available actions: getting events, creating events, and creating events with attendees. It receives a query from another workflow, determines the required action, executes it, and returns either a success message or an error that tells the main agent to try again.
  • The contact database supplies email addresses needed for tasks involving named people. In the dinner demonstration, the system finds Michael Scott's stored address before calling the calendar agent, enabling the selected calendar tool to create the event and send an invitation to the correct attendee.
  • The $fromAI function fills node parameters by interpreting the incoming natural-language query. A workflow builder provides a key, such as start time, and can add a description explaining the value, giving the AI enough context to extract the corresponding information from the request.
  • Parameter descriptions provide additional context when a key alone may not be sufficient. The calendar workflow defines attendees as the person or people with whom the user wants to schedule the event, while the event name is described as the name displayed for the calendar entry.
  • The demonstrated assistant can coordinate multiple specialized agents for one compound request. When asked to schedule a noon meeting with Michael Scott and email him for confirmation, it retrieves his contact information, calls both the calendar and email agents, creates the meeting, and sends the confirmation message.
  • The multi-agent framework is presented as easier to expand because additional specialist agents can be added gradually. Instead of enlarging one agent's toolset and prompt, each specialist contains the instructions and tools for its own domain, while the main agent retains the narrower routing responsibility.

Install to Summarize YouTube Videos and Get Transcripts

Explore YouTube Video Summarizer or Get YouTube Transcript Extractor

Questions & Answers

Q: How do you structure a multi-agent assistant in n8n?

Structure the assistant around one main agent and several specialized agents. The main agent receives a user's message through a Telegram trigger, interprets the requested outcome, and routes the task to an email, calendar, research, or project agent. Each specialist has its own actions and decides which one to execute, then returns a success message or an error to the main agent.

Q: Why use specialized agents instead of giving one agent every tool?

Specialized agents reduce the amount of tool selection and information handling required from the main agent. The earlier assistant directly accessed six tools across database, email, and calendar functions. The upgraded version delegates whole categories of work to four agents, so the main agent primarily decides whether a request belongs to email, calendar, research, or projects.

Q: How does the n8n calendar agent create an event with an attendee?

The calendar agent receives the scheduling query from the main workflow and identifies that it needs the create-event-with-attendee action. The system first retrieves the named person's email address from the contact database. The calendar tool then fills the event's start time, end time, attendee, and summary, creates the event, sends the invitation, and returns a confirmation.

Q: What does the $fromAI function do in an n8n workflow?

The $fromAI function tells AI how to fill a node parameter from the incoming query. The workflow builder supplies a key representing the required value and can include an optional description for additional context. In the demonstrated calendar nodes, it extracts the start time, end time, attendee email, and event name without requiring a separate model-processing node.

Q: How should keys and descriptions be written for $fromAI?

Use a key that directly names the required parameter, such as start time, end time, attendees, or name. Add a description when the AI may need more context. For example, start time is described as the time the user asks the event to begin, while attendees are the people the user wants the event scheduled with.

Q: How can the assistant complete calendar and email tasks from one request?

The main agent can divide a compound instruction across multiple specialists. For a request to schedule a meeting with Michael Scott at noon and email him for confirmation, it retrieves his contact details, sends the scheduling work to the calendar agent, and sends the confirmation task to the email agent. It then reports that both actions were completed successfully.

Q: What tools are available to the calendar agent?

The calendar agent can get existing events, create an event, or create an event with an attendee. It evaluates the incoming scheduling query to choose among those three tools. After executing the selected action, it responds to the main agent with a success message, or reports an error and instructs the main agent to try the task again.

Q: How was the upgraded personal assistant tested?

The assistant was tested by sending commands through Telegram while the main workflow listened for messages. One test requested dinner with Michael Scott for tomorrow at 6 p.m., and another requested a team meeting for today at 4 p.m. The resulting calendar entries were inspected, including the attendee invitation for the Michael Scott event.

Summary & Key Takeaways

  • The upgraded personal assistant replaces six tools attached directly to one agent with four specialized agents for email, calendar, research, and projects. The main agent receives Telegram messages, determines which specialist should handle each request, and passes the relevant information to that agent for execution and a success or error response.

  • A calendar demonstration schedules dinner with Michael Scott for tomorrow at 6 p.m. The system retrieves Michael Scott's email address from the contact database, calls the calendar agent, selects the tool for creating an event with an attendee, creates the event, sends the invitation, and reports the successful result.

  • The $fromAI function lets an agent derive node parameters directly from a natural-language query. Keys and optional descriptions tell the AI to identify values such as start time, end time, attendees, and event name. This removes the previously described need for a separate OpenAI node to extract and map those values.


Read in Other Languages (beta)

Share This Summary 📚

Explore More Summaries from Nate Herk | AI Automation 📚