Overview
This lecture explains how to build a basic AI agent using the N8N platform, covering core components, step-by-step setup, and practical workflow for integrating tools like Google Sheets.
Components of an AI Agent
- An AI agent requires a brain (chat model and memory), tools (e.g., Google Sheets), and a system prompt (brain stem).
- The brain processes input, the tools perform actions, and the system prompt connects the two.
- Input can be given by chatting or uploading a file, and output is produced after action.
Setting Up the AI Agent on N8N
- Sign up for N8N (cloud or local version) and start a new workflow.
- Add a chat trigger node to initiate communication with the AI agent.
- Connect the AI agent node to the chat trigger, which receives and processes messages.
Adding the Brain: Chat Model and Memory
- Connect an OpenAI chat model as the brain; set up credentials using an API key from OpenAI.
- Choose a model balancing cost and performance (e.g., "40 mini").
- Add a simple memory node to help the agent remember past interactions (suggested context window: 14 messages).
Integrating Tools: Google Sheets
- Create a new Google Sheet named "subscription tracker" with columns: expense, charge date, cadence, cost, status.
- Connect Google Sheets as a tool in N8N and authenticate your Google account.
- Set the tool to "append row" operation and link all column values dynamically to the AI model.
- Rename the tool for clarity (e.g., "add entry").
Writing and Adjusting the System Prompt
- Use screenshots and JSON of your workflow to generate a precise system prompt via ChatGPT.
- Paste the system prompt into the system message field of the AI agent node.
- Adjust the system prompt for confirmation steps and correct date handling using dynamic variables.
Testing and Troubleshooting
- Test the agent by inputting example subscription data.
- Update the system prompt to always confirm before adding entries and to use dynamic timestamps.
- Validate that entries are correctly added and the agent remembers past information.
Workflow Improvements and Logical Extensions
- To prevent duplicate entries, add tools to check existing rows before appending.
- Change the operation to "update row" for modifying existing subscriptions.
- Update the system prompt to reflect these workflow changes.
Key Terms & Definitions
- AI Agent — A system that processes inputs and performs actions using connected tools and a system prompt.
- System Prompt — Instructions that guide the AI agent's interaction with tools and users.
- Memory Node — Stores previous interactions for context retention.
- Append Row — An operation to add new entries to a spreadsheet.
Action Items / Next Steps
- Practice adding "get row" and "update row" tools in N8N for advanced agent logic.
- Revisit and refine the system prompt as your workflow evolves.
- Explore further tutorials, such as building agents with Google Gemini.