Key Concepts
- AI Agents: Specialized AI systems designed for specific tasks (email management, calendar management, contact management, content creation).
- n8n: A workflow automation platform used to build and connect the AI agents.
- Telegram Trigger: Initiates the workflow based on incoming messages from Telegram.
- Tool Delegation: The process of the ultimate assistant assigning tasks to the appropriate specialized agent.
from AIFunction: A function used within n8n to allow the AI model to dynamically fill in parameters based on the input query.- Placeholders: Used in API requests (like with Tavily) to dynamically insert search terms or other data.
- Execute Workflow Trigger: Used to trigger a workflow when it's called as a tool by another workflow.
- Response Node: The last node in a sub-workflow (like the email agent) that provides the output back to the calling workflow.
- Error Handling: Using "On Error Continue" to create separate branches for successful and unsuccessful execution paths.
Ultimate Personal Assistant: Overview
The video demonstrates the creation of an "ultimate personal assistant" using n8n, composed of several specialized AI agents: an email agent, a calendar agent, a content creator agent, and a contact agent. The assistant receives input via Telegram, delegates tasks to the appropriate agent, and responds to the user in Telegram. The key is to have specialized agents with simple prompts rather than one complex agent.
Workflow Breakdown
1. Input and Output (Telegram Integration)
- Telegram Trigger: The workflow starts with a Telegram trigger that listens for incoming messages.
- Voice vs. Text: A switch node determines if the message is text or voice. Voice messages are transcribed using a transcription node.
- Unified Input: Both text and transcribed voice messages are mapped to a common "text" field for the AI agent to process.
- Telegram Response: The final output is sent back to the user via Telegram, using the original chat ID.
2. Ultimate Assistant Prompt and Tool Delegation
- Simple Prompt: The ultimate assistant's prompt is concise, focusing on delegating tasks to the correct agent.
- "Your job is to send the user's query to the correct tool. You should never be writing emails or creating event summaries all you need to do is just call the correct tool."
- Tool Definitions: The prompt defines the available tools (email agent, calendar agent, contact agent, content creator, Tavily) and their respective functions.
- Contact Information Rule: A rule specifies that for certain actions (sending emails, creating calendar events with attendees), the contact agent must be used first to retrieve contact information.
- Example Input/Action: An example is provided to guide the AI in delegating tasks.
- Access to Current Date/Time: The agent has access to the current date and time.
3. Implementing Agents as Tools
- Call n8n Workflow Tool: The specialized agents are integrated as tools using the "Call n8n Workflow" tool within the ultimate assistant workflow.
- Naming Convention: The tool names defined in the n8n tool configuration must match the names used in the ultimate assistant's prompt (camel case).
- Workflow Selection: The specific workflow for each agent is selected from the n8n database.
- Response Handling: The ultimate assistant expects a "response" field from the called workflow's last node.
4. Email Agent: Functionality and Logic
- Email Agent Prompt: The email agent's prompt is focused on email management tasks.
- "You're an email management assistant. All emails must be formatted professionally in HTML and signed off as Nate."
- Tool Definitions: The prompt defines the available email tools (send email, create drafts, get emails, get labels, mark unread, reply to emails).
- Dependency Handling: The prompt specifies dependencies between tools (e.g., "use get emails first" before using "mark unread" or "label emails").
- Error Handling: The email agent uses "On Error Continue" to handle errors and return an "unable to perform task" message to the ultimate assistant.
from AIFunction in Action: Thefrom AIfunction is used extensively within the email tools to dynamically fill in parameters like recipient email, subject, and message body based on the input query.- Example: In the "send email" tool,
from AIis used to extract the email address from the query and populate the "to" field.
- Example: In the "send email" tool,
- Example: Labeling Emails: To label an email, the agent first uses the "get emails" tool to retrieve the message ID and then uses the "get labels" tool to retrieve the label ID. These IDs are then used in the "label email" tool.
5. Calendar Agent: Functionality and Logic
- Calendar Agent Prompt: The calendar agent's prompt focuses on calendar management tasks.
- "Your calendar assistant. Your responsibilities include creating, getting, and deleting events."
- Tool Definitions: The prompt defines the available calendar tools (create event with attendee, create event, get events, delete event, update event).
- Dependency Handling: Similar to the email agent, the calendar agent requires getting the event ID before deleting or updating an event.
- Default Duration: If a duration for an event isn't specified, the agent assumes it's 1 hour long.
6. Contact Agent: Functionality and Logic
- Contact Agent Prompt: The contact agent's prompt focuses on contact management tasks.
- "Your contact management assistant. Your responsibilities include looking up contacts, adding new ones, or updating them."
- Tool Definitions: The prompt defines the available contact tools (retrieve contacts, add or update contacts).
- AirTable Integration: The contact agent interacts with an AirTable database to store and retrieve contact information.
7. Content Creator Agent: Functionality and Logic
- Content Creator Agent Prompt: The content creator agent's prompt focuses on writing engaging and informative blog content.
- "You are a skilled AI blog writer specializing in engaging, well-structured, informative content."
- Tool Definitions: The agent uses Tavily for web search.
- HTML Formatting: The agent is instructed to format the blog content as HTML.
- Placeholder Usage: The agent uses placeholders in the Tavily API request to dynamically insert the search term.
- Example: The
search termplaceholder is used to insert the user's requested blog topic into the Tavily search query.
- Example: The
- Claude 3.5 Sonnet: This model is used for content creation due to its ability to structure content well.
8. Tavily Integration
- API Request: The content creator agent sends a POST request to the Tavily API.
- Placeholders: Placeholders are used in the JSON body of the API request to dynamically insert the search term.
- Dynamic Search Term: The search term is extracted from the user's query and inserted into the Tavily search query using the placeholder.
Conclusion
The video demonstrates a powerful approach to building a personal assistant by combining specialized AI agents within an n8n workflow. The key takeaways are the use of simple prompts for each agent, the delegation of tasks by a central "ultimate assistant," the use of the from AI function to dynamically fill in parameters, and the integration of external tools like Tavily using placeholders. This modular design allows for easy expansion and customization of the assistant's capabilities.
AI summaries can miss context or contain errors. Check important details against the original video.