Learn how to build a working AI agent automation pipeline with real prompts, tool choices, and debugging tips — then decide if you want the blueprint.
AI Agent Automation: A Practical Build‑From‑Scratch Guide
You’ve seen the demos: an AI agent that reads your inbox, drafts replies, and updates your CRM. In practice, most of those demos fall apart when you try to run them daily — missing context, duplicated actions, or silent failures.
By the end of this guide you’ll have a working AI agent automation that pulls leads from a form, enriches them with a web scrape, and sends a personalized email — all logged and retryable.
Context is king.
Choosing the Right Framework: No‑Code vs Code‑First
First decide how much glue you want to write. If you enjoy debugging JSON payloads and writing Python scripts, a code‑first approach with LangChain or LlamaIndex gives you full control. For most solo operators, a no‑code platform like Make (formerly Integromat) lets you wire HTTP calls, AI prompts, and email sends without touching a server.
I’ve tried both. The code route gave me flexibility but ate hours each week fixing version mismatches. The no‑code route cut my setup time from a full day to under two hours, and the visual scenario editor makes it easy to see where data flows.
That said, Make’s free tier is limited to 1,000 operations a month, which is barely enough for a lead‑enrichment flow that fires three times per lead. The paid Core plan at $29/mo is fair for the automation runs you get, but the jump to the Team plan at $99/mo feels steep unless you’re running dozens of scenarios.
If you’re just testing, start with the free tier and watch the operation counter.
Why does the agent lose context after the first step?
One common failure mode is the agent forgetting the original lead data after calling an external API. This happens when you overwrite the same variable name in each module, or when you rely on a temporary buffer that gets cleared between steps.
⚡
Recommended Reading
Prompt Engineering for Profit
50 Tested Templates
50 tested prompt templates for content, copywriting, and automation. Copy, paste, earn.
In Make, each module outputs a bundle of variables. If you map only the output of the previous module into the next, you drop everything else. The fix is to use a “Set Variables” module early in the scenario to store the lead’s name, email, and source in persistent variables, then reference those variables in every subsequent step.
I learned this the hard way after seeing personalized emails that addressed “Dear {first_name}” with the literal string because the variable had been overwritten by the scrape result.
Many tutorials treat each tool as a black box and simply chain them together with HTTP requests. They ignore error handling, rate limits, and data type mismatches. The result is a scenario that works in a test run but fails silently in production.
What they overlook is the need for a retry policy with exponential backoff, a dead‑letter queue for failed items, and a validation step that checks the shape of the JSON returned by a scraper before passing it to the LLM prompt.
In my own builds, I add a “Router” module after each HTTP call: if the status code is not 200, send the bundle to an error handler that logs the response body and waits five minutes before retrying, up to three times.
Without that, a temporary 502 from the scraper would stop the whole scenario and you’d never know why.
Concrete example: lead enrichment agent with Make, Apify, and GPT-4o
Here’s a real scenario I run for a freelance client. The goal: when a new row appears in a Google Sheet (lead capture form), fetch the lead’s LinkedIn profile via an Apify scraper, ask GPT-4o to write a one‑line icebreaker, and send a personalized Gmail.
Make scenario steps:
- Watch Google Sheets for new rows (module: Google Sheets > Watch Rows).
- Set Variables: store lead_name, lead_email, linkedin_url from the sheet.
- HTTP > Make a request to Apify API (POST to run actor) with the LinkedIn URL as input.
- Parse the Apify output (JSON) and set variable scraped_bio.
- OpenAI > Create a completion (model: gpt-4o) with prompt: “Given this LinkedIn bio: {{scraped_bio}}, write a friendly icebreaker sentence for a cold email.” Set variable icebreaker.
- Email > Send a Gmail message to lead_email with subject: “Quick question about {{lead_name}}” and body: “Hi {{lead_name}},\n\n{{icebreaker}}\n\nLet me know if you’d like to chat about [your service].\n\nBest,\n[Your Name]”.
- Set a status variable to “sent” and update the Google Sheet row.
The prompt I use is short enough to stay under the 1,000‑token limit, which keeps the cost low. At current rates, a single GPT-4o call costs about $0.006, so processing 100 leads a day runs under $1.
I love how Apify’s scraper returns structured JSON with a single click — no need to write custom parsing logic. The concrete love is the reliability of that JSON shape; it means I can map fields directly without guesswork.
My gripe? Make’s error handling hides the raw HTTP response unless you open the scenario log and click “Show details”. When a 429 hits, I have to dig through three menus to see the retry‑after header, which is annoying.
If you’ve tried Zapier automations, you know what I mean — its error UI is even more buried.
How to debug when this breaks
Start by checking the scenario execution history. Look for the module that failed and note the error code. If it’s an HTTP error, add a temporary “Set Variable” module right after the failing step to dump the raw response body into a text field, then run the scenario again with a test record.
If the LLM returns empty or garbled text, validate the prompt inputs. I often add a “Formatter” module that truncates the scraped bio to 800 characters before sending it to GPT-4o — this prevents token overflow that silently produces a blank completion.
When the email never arrives, verify the Gmail connection scope. Make sometimes loses the refresh token after a password change; re‑authorizing the connection fixes it.
Finally, enable email notifications for scenario failures so you don’t have to constantly check the dashboard.
Price check and where to cut corners
Here’s a rough monthly cost for running 500 leads through the flow above:
- Make Core plan: $29
- Apify actor usage: $10 (based on 500 scrapes at $0.02 each)
- OpenAI GPT-4o: $3 (500 calls × $0.006)
- Google Workspace (for Sheets and Gmail): $12 (if you don’t already have it)
- Total: ~$54
If you’re tight on cash, you can swap GPT-4o for the cheaper gpt-3.5-turbo ($0.0005 per call) and still get decent icebreakers, dropping the AI cost to $0.25. The tradeoff is a bit less nuance, but for a simple opening line it’s often fine.
I think the free tier of Make is a joke for any real volume — you’ll hit the operation limit before lunch on a busy day.
— and good luck finding docs for this — the Apify actor documentation is scattered across GitHub READMEs and a blog post, which makes the initial setup slower than it should be.
Adjacent reading: deeper coverage of AI agent platforms.
If you’d rather skip the build and deploy a working version in an afternoon, we’ve packaged this workflow as a blueprint at deepusecase.com/vault/ai-agent-builder-kit.