Learn how to build a working AI agent workflow step‑by‑step, see real prompts, tool costs, and where most guides fail.
Last month I needed to pull leads from a LinkedIn search, enrich them with company data, and send a personalized cold email—all without hiring a VA. I built a small AI agent chain that does exactly that, and it runs on a $15/mo VPS plus a few API credits. After reading this, you’ll be able to replicate the same flow, spot where it breaks, and decide whether to build it yourself or grab the ready‑made blueprint.
What most guides get wrong about AI agents
Most tutorials start with a vague promise: “create an agent that does everything.” They skip the gritty details of tool limits, auth headaches, and the fact that LLMs hallucinate when you ask for JSON. I’ve seen guides tell you to just “plug in an API key” and then wonder why the agent stops after two steps. The truth is, an agent is only as reliable as its weakest integration.
One common mistake is assuming the model can handle multi‑step reasoning without any external memory. In practice, you need a short‑term store—something as simple as a JSON file or a Redis cache—to pass data between steps. Without it, the agent forgets the lead’s name by the time it tries to personalize the email.
Another oversight is error handling. Guides show a happy path where every tool returns 200 OK. Real APIs rate‑limit, return 429, or give malformed responses. If you don’t wrap each call in a retry loop with exponential backoff, your workflow will die silently.
Why does the agent stall after the third step?
I ran into this exact issue when I linked three tools: a scraper, an enrichment service, and an email sender. The scraper returned a list of 200 leads, the enrichment step added company size, and then the email step crashed on the 57th lead. The logs showed a 402 error from the email API—my trial credits had run out.
The stall wasn’t the agent’s fault; it was a missing guardrail. I had not checked the remaining quota before each send. Adding a simple pre‑flight check that pauses the workflow when credits fall below ten fixed the problem. The agent now skips the send, logs a warning, and continues with the next lead.
This taught me to treat every external call as a potential point of failure and to add lightweight checks early in the chain.
Choosing the right tools: cost, limits, and gotchas
When you start picking services, look beyond the headline price. I evaluated three email APIs: SendGrid, Mailgun, and Postmark. SendGrid’s free tier gives 100 emails/day but blocks you after 50 if you exceed a spam complaint threshold—something I hit on day two. Mailgun’s trial offers 5,000 emails but requires a credit card up front, which I dislike for side projects. Postmark’s $15/mo plan includes 10,000 emails and provides detailed delivery logs, making debugging trivial.
For scraping, I tried Apify and ScrapeEasy. Apify’s free tier gives 10,000 compute seconds per month, enough for a few hundred pages, but its JavaScript rendering is slow and often times out on LinkedIn. ScrapeEasy charges $0.005 per page rendered, which added up to about $12 for my 2,400‑page run, but it never failed and returned clean HTML.
The enrichment step used Clearbit via their API. Their free plan offers 50 lookups/month—useless for anything beyond a demo. The paid tier starts at $99/mo for 2,000 lookups, which felt steep until I realized each lookup saved me roughly five minutes of manual research. At my hourly rate, the API paid for itself in under two weeks.
Building the agent step by step
Here’s the actual flow I used, broken into bite‑size pieces you can copy.
- Step 1 – Trigger: a cron job runs every morning at 08:00 UTC and calls a small Node script.
- Step 2 – Scrape: the script calls ScrapeEasy with a LinkedIn search URL, receives raw HTML, and extracts name, title, and company URL into a JSON array.
- Step 3 – Enrich: for each entry, the script hits Clearbit’s company enrichment endpoint using the company domain, adds employee count and industry, and writes the enriched object to a temporary SQLite DB.
- Step 4 – Send: the script reads the DB, checks Postmark’s remaining credits via their /stats endpoint, and if credits > 10, sends a templated email via Postmark’s /send endpoint.
- Step 5 – Log: after each send, the script writes a log entry (status, timestamp, message ID) to a file for later review.
Below is a simplified version of the core loop. Note that error handling is deliberately verbose—this is what keeps the agent alive.
const leads = await scrapeLinkedIn(url);
for (const lead of leads) {
try {
const enriched = await enrichWithClearbit(lead.companyDomain);
const { name, title, company, employees, industry } = { ...lead, ...enriched };
const credits = await getPostmarkCredits();
if (credits < 10) {
console.log(`Low credits: ${credits}. Pausing.`);
break;
}
await sendEmail({
from: 'me@mydomain.com',
to: lead.email,
subject: `Hi ${name}, quick question about ${company}`,
html: template(name, title, company, employees, industry)
});
logSuccess(lead.email);
} catch (err) {
console.error(`Failed on ${lead.email}:`, err.message);
logFailure(lead.email, err.message);
// continue to next lead
}
}
Notice the try/catch around each lead. If one step fails, the agent logs the issue and moves on instead of halting the whole batch.
Real example: prompt, tool, and price
Let’s look at the actual prompt I gave the LLM for the email generation step. I used OpenAI’s gpt-4o via their API, temperature 0.7, max_tokens 150.
You are a friendly sales assistant. Write a short, personalized cold email to {{name}} who works as a {{title}} at {{company}}. Mention one specific detail about their company (e.g., recent funding, product launch, or employee count). Keep it under 120 words. End with a low‑pressure call to action: "Would you be open to a 15‑minute chat next week?"
I stored this as a template string and injected the scraped fields at runtime. The cost per call is about $0.0015, so for 2,000 leads the LLM expense is roughly $3. Add the scraping ($12), enrichment ($99 for 2,000 Clearbit lookups), and email sending ($15 for Postmark), and the total monthly spend lands near $130—still cheaper than hiring a part‑time VA.
I think the Clearbit price is high for early experiments, but the time saved makes it worth it once you’re past the proof‑of‑concept stage.
When to buy the blueprint instead
If you’ve followed the steps above and feel comfortable tweaking scripts, you can run this workflow for under $150/mo. However, assembling the pieces—finding reliable scraping endpoints, managing API keys, setting up retry logic—takes a solid afternoon of trial and error.
That’s why we packaged the exact same chain into a blueprint at deepusecase.com/vault/ai-agent-builder-kit. It includes the Dockerfile, the pre‑configured Node script, sample LinkedIn search URLs, and a ready‑to‑use Postmark template. You can deploy it in an afternoon and start generating leads the same day.
We cover this in more depth elsewhere — 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.