Build Your First AI Agent in 4 Hours: Complete Beginner's Guide
Step-by-step tutorial for building your first AI agent from scratch -no coding experience required. Working agent in one afternoon using Zapier and Claude API.
Step-by-step tutorial for building your first AI agent from scratch -no coding experience required. Working agent in one afternoon using Zapier and Claude API.
TL;DR
Jump to prerequisites · Jump to hour 1 · Jump to hour 2 · Jump to hour 3 · Jump to hour 4 · Jump to FAQs
Right, let's build an actual working AI agent this afternoon. Not a toy example -a real automation that'll handle tasks while you sleep.
I'm assuming you've never written code before. That's fine. We'll use no-code tools that do the heavy lifting. By hour 4, you'll have an agent that reads your emails, decides which are urgent, categorises them, and routes them appropriately.
Sound useful? Let's start.
Agent name: Email Triage Assistant
What it does:
Why this agent? Email overload is universal. An agent that filters noise and surfaces what matters saves 30-60 minutes daily for most people. Plus, once you've built this, you can adapt the pattern to automate dozens of other workflows.
Time: 4 hours (can split across 2 days if needed)
Cost:
What you need:
Skills required: Absolutely none. If you can use Gmail, you can do this.
Anthropic makes Claude, the AI we'll use for decision-making.
sk-ant-)Cost check: Anthropic gives you £4 free credit to start. That's enough to process ~400 emails. After that, it's pay-as-you-go: roughly £0.02 per email classified.
Zapier connects apps without code.
If you don't have Slack, skip this. We'll use email notifications instead.
If you have Slack:
Before building, understand what happens:
New Gmail arrives → Zapier detects it → Sends to Claude API → Claude classifies → Zapier applies label + sends Slack alert
Key concept: Trigger → Action → Action
This pattern (trigger → decision → actions) is the foundation of all AI agents.
Now we build the "brain" -the prompt that tells Claude how to classify emails.
This is where the AI magic happens.
URL:
https://api.anthropic.com/v1/messages
Method: POST
Headers:
x-api-key: [PASTE YOUR ANTHROPIC API KEY HERE]
anthropic-version: 2023-06-01
content-type: application/json
Data (this is the prompt):
{
"model": "claude-3-5-sonnet-20241022",
"max_tokens": 256,
"messages": [
{
"role": "user",
"content": "Classify this email. Return ONLY valid JSON with no additional text.\n\nEmail Subject: {{1. Subject}}\n\nEmail Body (first 100 words): {{1. Body Plain}}\n\nReturn this exact JSON format:\n{\n \"category\": \"Urgent\" | \"Work\" | \"Personal\" | \"Newsletter\" | \"Spam\",\n \"priority\": \"High\" | \"Medium\" | \"Low\",\n \"reason\": \"brief explanation\"\n}\n\nClassification criteria:\n- Urgent: Time-sensitive, requires action today (meetings, deadlines, client requests)\n- Work: Job-related but not urgent\n- Personal: Friends, family, personal matters\n- Newsletter: Marketing emails, updates, subscriptions\n- Spam: Unsolicited, irrelevant, or suspicious\n\nPriority:\n- High: Requires response within 4 hours\n- Medium: Requires response within 24 hours\n- Low: FYI only, no response needed"
}
]
}
What's happening here?
{{1. Subject}} and {{1. Body Plain}} are Zapier variables pulling from the email trigger{
"category": "Work",
"priority": "Medium",
"reason": "Project update email from colleague"
}
If test fails, check your API key is correct and has no extra spaces.
Zapier needs to extract the classification from Claude's response.
claudeResponseconst response = JSON.parse(inputData.claudeResponse);
return {
category: response.category,
priority: response.priority,
reason: response.reason
};
Now we can use these in the next steps.
Make Gmail automatically label the email.
Click "+ New Step" → Search "Gmail" → Select "Add Label to Email"
Click "Sign in" (if not already connected)
Set fields:
Agent: {{3. Category}}This creates labels like "Agent: Urgent", "Agent: Work", etc.
Click "Test step" → Check Gmail -email should now have label applied
Note: First time, Gmail will ask you to create these labels. Click "Create" for each.
Only alert you for emails that need immediate attention.
HighThis means next step only runs if priority is High.
:rotating_light: High Priority Email
*From:* {{1. From Name}}
*Subject:* {{1. Subject}}
*Category:* {{3. Category}}
*Reason:* {{3. Reason}}
<{{1. Message URL}}|View Email>
Moment of truth. Let's test with real emails.
In Zapier, click "Publish" at top right
Turn on the Zap
Send yourself 5 test emails:
Wait 2-3 minutes (Zapier polls Gmail every 1-5 minutes on Starter plan)
Check Gmail -are labels applied correctly?
Check Slack -did only Test 1 trigger alert?
If something's wrong:
Your agent is live! Now track how well it works.
Over the next day, let it process real emails. Then review:
Example issues I've seen:
Issue: Newsletters marked as Work
Fix: Add to prompt: "Newsletters have 'unsubscribe' links -check for this"
Issue: Urgent emails missed
Fix: Add examples to prompt: "If subject contains 'ASAP', 'urgent', 'deadline', classify as Urgent"
This is where you make the agent smarter.
Current prompt vs Improved prompt:
Before:
Urgent: Time-sensitive, requires action today
After:
Urgent: Time-sensitive, requires action today
Examples:
- "Meeting in 1 hour"
- "URGENT: Client needs response by EOD"
- "Deadline tomorrow"
- Subject contains: ASAP, urgent, deadline, today, EOD
Go back to Step 6, click "Edit" on the Claude step, and add 3-5 examples for each category based on your actual emails.
Test again with 5 more emails. Accuracy should improve from ~75% to ~90%+.
Now that core agent works, extend it:
Option A: Auto-reply to Newsletters
Option B: Forward Urgent to Phone
Option C: Archive Low Priority
Pick one and implement. Should take 10-15 minutes.
Pitfall 1: API key errors
sk-ant-Pitfall 2: Gmail permission issues
Pitfall 3: Claude returns invalid JSON
Pitfall 4: Too many Slack alerts
Pitfall 5: Agent too slow
Congratulations -you've built a working AI agent. Here's what you now understand:
These skills transfer directly to building more advanced agents.
This week:
Next month:
Within 3 months:
Can I use ChatGPT instead of Claude?
Yes, but you'll need OpenAI API key instead. In Step 6, use URL https://api.openai.com/v1/chat/completions and adjust the JSON format. Claude tends to be better at following structured output instructions, but both work.
What if I have 1,000+ emails/day?
This setup works up to ~500 emails/month on £25 budget. For higher volume:
Is my email content sent to Anthropic?
Yes -Claude needs to read emails to classify them. Anthropic's API policy: they don't train on your data or store it beyond processing. If you handle sensitive data, consider running a local LLM instead (more advanced).
How do I handle emails in languages other than English?
Claude supports 100+ languages. Just add to prompt: "Email may be in [your language]. Respond in English." It'll classify correctly.
Can I classify into custom categories?
Absolutely. Change the categories in the prompt to whatever fits your workflow: "Client", "Internal", "Invoices", "Legal", etc. Test with 10 examples to make sure Claude understands your taxonomy.
You did it. In 4 hours, you've gone from zero to working AI agent. Most people talk about AI agents theoretically -you've built one that's handling real work.
The pattern you've learned (trigger, classify with AI, take action based on classification) powers 80% of business automation agents. Master this, and you can automate almost anything.
Ready for more? Check out our Multi-Agent Orchestration guide to build agents that collaborate.