How I Built 3 AI Email Agents in One Session
A technical walkthrough of building autonomous email agents with Claude, Redis, and Cloudflare — from problem to production in a single focused session.
The Problem
I was deep in a job search. Dozens of conversations happening at once — recruiters, hiring managers, scheduling coordinators. Every email needed a thoughtful, timely response. But I was also building, writing, and running operations full-time.
I needed something that could represent me accurately when I wasn’t available. Not a chatbot with canned responses. An agent that actually knew my work and could hold a real conversation.
So I built three.
The Architecture
Each agent handles a different domain:
- Interview Agent — answers questions about my experience, skills, and approach to operations
- Substack Agent — engages with readers of my published writing
- Calendar Agent — coordinates meeting scheduling with live calendar availability
The email flow is straightforward:
Inbound Email
→ Cloudflare Email Routing (parses recipient address)
→ Cloudflare Worker (forwards to correct endpoint)
→ Vercel Serverless Function (agent logic)
→ Claude API (generates response with full context)
→ Resend (sends reply from @withjhinna.com)
Every inbound email also gets forwarded to a monitoring inbox so I have full visibility.
The Key Decisions
Conversation persistence was the first design choice. Without it, every email would be a cold start. I used Upstash Redis to store up to 20 message pairs per sender per agent, with a 7-day TTL. The agent remembers what you’ve discussed and builds on it.
Escalation detection was the second. Some conversations need a human — job offers, salary discussions, sensitive topics. The system monitors Claude’s responses for escalation signals and sends priority notifications with full conversation context. I can step in seamlessly without the sender knowing there was ever an agent involved.
Calendar integration was the trickiest. The scheduling agent fetches live free/busy data from Google Calendar via OAuth2, injecting real availability into each response. Token refresh is automatic with a 5-minute cache buffer. When someone asks “when are you free this week?”, the agent checks my actual calendar and proposes specific times.
Guardrails keep it stable: rate limiting (50 messages/day per sender), message validation, empty reply detection, and quoted-text stripping to keep conversation threads clean.
What I Learned
System prompts are knowledge bases. Each agent has a comprehensive system prompt — the interview agent’s is nearly 10,000 characters of professional context. The quality of the responses is directly proportional to the quality of the knowledge you give the model.
Escalation is the escape hatch that makes autonomy safe. The agents can handle 90% of conversations independently. But the 10% that needs human judgment gets flagged immediately. This is what makes the system trustworthy — not perfection, but knowing when to hand off.
The stack matters less than the decisions. Node.js, Vercel, Cloudflare, Redis, Resend — all standard tools. The interesting work was in the conversation design: how to persist context, when to escalate, how to inject real-time data.
The whole system went from idea to production in a single focused session. That’s the workflow: identify what needs to exist, build it, deploy it.
Want the deeper story?
I write essays about identity, transition, and building a life that fits — on Substack.
Read With Jhi