If you can use ChatGPT, you can build an AI agent. This comprehensive guide will walk you through creating your first AI agent from scratch using the n8n platform.
By the end, you'll understand how to give your agent a brain, connect it to tools like Google Sheets, and teach it exactly when and how to use those tools.
Think of an AI agent as having three essential components that mirror human anatomy.
Just as the human brainstem relays information from the brain to the rest of the body, the system prompt performs a similar function by helping the agent brain control the tools correctly.
The agent we're building today will track subscription expenses in Google Sheets. When you type something like "I just subscribed to n8n for 20 euros a month," the agent will process your natural language input, confirm the details with you, and automatically add a properly formatted row to your subscription tracker spreadsheet with columns for Expense, Charge Date, Cadence, Cost, and Status.
Creating the brain of your AI agent starts with establishing how you'll communicate with it. In n8n, begin by creating a new workflow and adding a chat trigger. This chat interface allows you to send messages to your agent in natural language.
Next, connect an AI Agent node to your chat trigger. Think of this connection like a relay race – the chat trigger passes your message to the AI Agent, which then needs to process it. The AI Agent node might look intimidating at first, but it's simply showing you what it receives (your chat input) and what it needs to process.
Your AI agent needs a chat model to think and respond. Connect an OpenAI chat model to your AI Agent node. If this is your first time, you'll need to create API credentials:
For model selection, the latest mini models strike an excellent balance between cost and performance. These models are powerful enough for most tasks while keeping API costs manageable.
Here's where things get interesting. Without memory, your AI agent suffers from permanent amnesia.
Adding Simple Memory solves this problem. Set the Context Window Length to 14 messages – this means if you send messages twice daily, your agent will still remember Monday's conversation on Sunday. This continuity transforms your agent from a goldfish into a helpful assistant that maintains context across interactions.
Tools give your AI agent the ability to interact with external services. For our subscription tracker, we'll connect Google Sheets as our primary tool.
Before connecting the tool, create a new Google Sheet with these columns:
Name the tab "tracker" and keep this window open – you'll need the URL shortly.
Back in n8n, add a Google Sheets tool to your AI Agent. The connection process is straightforward:
Rename this tool to "AddEntry" for clarity. This naming convention becomes important when we write the system prompt, as we'll need to reference this specific tool by name.
The system prompt is where the magic happens. It's the instruction manual that tells your AI agent how to use its brain and tools effectively. Without a proper system prompt, your agent has all the capabilities but no direction.
Writing system prompts can be daunting, but here's a powerful shortcut:
## TASK ##
Your task is to output a clear, precise, and comprehensive system message for my n8n AI agent designed to keep track of my subscriptions (i.e. recurring expenses).
## CONTEXT ##
The AI Agent is connected to a Google Sheet and has access to the "AddEntry" tool.
When the user sends a message like "I just subscribed to ChatGPT for 20 usd a month" the AI agent should first confirm its understanding then fill out the columns in the Google Sheet.
For example:
Expense = ChatGPT
Charge Date = By default use today’s date (date chat was sent) unless stated otherwise
Cadence = Monthly
Cost = $20
Status = Active
I've attached a .json file and screenshot for you to reference.
ChatGPT will analyze your workflow structure and create detailed instructions that tell your agent exactly how to handle subscription data, when to use the AddEntry tool, and how to format the information correctly.
One common issue you'll encounter is date accuracy. Your agent might guess the wrong date when processing entries. The solution involves making your system prompt dynamic.
In n8n, you can drag variables from the input context (like the actual date and time of your message) directly into the system prompt. This ensures your agent always uses the correct date instead of making assumptions.
Once your agent is assembled, testing reveals its true capabilities. Type "I just subscribed to iCloud for 10 USD a month" and watch the process unfold. A well-configured agent will:
If something goes wrong, you have two troubleshooting options:
Think about what you'd expect from a human assistant managing your subscription tracker. They should check for existing entries to avoid duplicates, right? This logic translates directly to your AI agent workflow.
To implement duplicate checking, you'd add another Google Sheets tool configured to "Get Row" to read existing entries first. Then, modify your AddEntry tool to "Append or Update Row" instead of just appending.
Most importantly, update your system prompt to reflect this new workflow: instruct the agent to check existing entries before making changes.
These enhancements demonstrate the flexibility of AI agents. Once you understand the building blocks, you can create increasingly sophisticated workflows that handle edge cases and provide more intelligent responses.
Check out my comprehensive guide on leveraging Google Gemini for advanced automation workflows!