Duck
Tutorials6 min read

AI Agents Examples: Building a Lead Enrichment Agent from Scratch

Samet Turan— Editor··6 min read

Learn to build a working AI agent that scrapes LinkedIn, writes personalized emails, and logs to CRM—step by step, with real prompts, costs, and debugging tips.

AI Agents Examples: Building a Lead enrichment agent from Scratch

You spend hours copying LinkedIn profiles, drafting cold emails, and logging results into a spreadsheet. It’s tedious, error‑prone, and scales poorly. After reading this, you’ll be able to assemble a no‑code AI agent that does those steps for you, and you’ll know where to tweak it when things go sideways.

Why does my agent hallucinate when scraping LinkedIn?

One of the first surprises I hit was the agent making up job titles or company names that never existed on the profile. The root cause wasn’t the AI model itself; it was the way the raw HTML was fed into the prompt. When the scraper returned a blob of JavaScript‑heavy markup, the language model tried to “fill in the gaps” and invented plausible‑sounding details.

Fixing it meant cleaning the scraped data before it ever reached the LLM. I used Apify’s LinkedIn scraper actor, which returns a clean JSON array of fields like firstName, lastName, headline, companyName. By mapping those fields directly into the prompt, I removed the noise that caused hallucinations.

Here’s the exact prompt I use (note the placeholders):

Write a short, personalized cold email to {{firstName}} {{lastName}} who works as a {{headline}} at {{companyName}}. Mention one specific detail from their headline that shows you did your research. Keep it under 120 words.

The templating is handled by Make.com’s text parser module, which swaps the double‑braces for the scraped values before sending the string to OpenAI.

What most guides get wrong about AI agent prompts

Many tutorials tell you to “be clear and specific” but then give a vague example like “Write a professional email.” That leaves too much room for the model to drift. In practice, specificity isn’t just about length; it’s about constraining the output format and giving the model a concrete anchor.

What works better is to give the model a strict structure and a single source of truth. For the lead‑enrichment agent I built, I added three constraints:

  • Limit the email to exactly two sentences.
  • Include the prospect’s first name in the greeting.
  • End with a clear call‑to‑action: “Let me know if you’d like to see a short demo.”

When I enforced those rules, the variance in tone dropped dramatically and the edit‑time per email fell from five minutes to under thirty seconds.

Choosing the right no‑code stack

You don’t need a PhD in machine learning to wire this together. The stack I settled on consists of four pieces, each handling a distinct slice of the workflow:

  1. Apify – runs the LinkedIn scraper actor and returns clean JSON.
  2. Make.com – orchestrates the flow, handles authentication, and calls OpenAI.
  3. OpenAI API – generates the email copy using the prompt above.
  4. HubSpot’s CRM (or any CRM you prefer) – stores the prospect data and the generated email for follow‑up.

All of these offer free tiers that are enough to test the idea. Apify gives you 10,000 scraper credits monthly, which covers roughly 200 LinkedIn profiles. Make.com’s free plan allows 1,000 operations a month—more than enough for a solopreneur testing a few dozen leads per week. OpenAI’s pricing is token‑based; a typical email generation uses about 150 tokens, costing roughly $0.002. HubSpot’s free CRM stores unlimited contacts.

I think the combined monthly cost of running this agent at a modest volume (500 leads) stays under $15, which feels fair for the time saved.

Setting up the scraper in Apify

First, create an Apify account and navigate to the Actors store. Search for “LinkedIn Profile Scraper” and click “Deploy.” You’ll need to provide a list of profile URLs; I store mine in a Google Sheet and use Make’s HTTP module to fetch them as a JSON array.

The scraper returns a payload like this:

[{"firstName":"Ada","lastName":"Lovelt","headline":"Senior Data Engineer at Futurice","companyName":"Futurice"}]

Note that the actor automatically strips scripts and ads, leaving only the fields you need. That clean output is why the hallucination problem disappeared.

How to debug when your agent fails silently

Silent failures are the worst kind because you don’t get an error message; you just see no output in your CRM. My first silent failure happened when the OpenAI module returned an empty string. The log in Make showed a 200 OK status, but the response body was blank.

I traced it to two issues:

  1. The prompt exceeded the model’s token limit because I accidentally included the full HTML blob instead of the cleaned JSON.
  2. The OpenAI API key had a restriction that blocked calls from certain IP ranges; Make’s outgoing IP fell into that block.

To catch these, I added two simple checks in Make:

  1. A router that checks the length of the prompt text; if it’s over 800 characters, the flow stops and sends me an email alert.
  2. A second HTTP module that calls OpenAI’s /models endpoint to verify the key is valid; if it fails, the flow logs a clear “Invalid API key” message.

After adding those guards, I now get a Slack notification whenever something deviates from the expected pattern, which cuts downtime from hours to minutes.

Pricing and trade‑offs you should know

Let’s talk real numbers. Apify’s free tier gives 10,000 credits each month. Each LinkedIn profile scrape costs about 20 credits, so you get roughly 500 profiles for free. If you need more, their $49/mo plan bumps you to 100,000 credits—enough for 5,000 profiles.

Make.com’s core plan starts at $29/mo and gives you 10,000 operations. That’s plenty for running the scraper, the OpenAI call, and the CRM update for each lead. I think $29/mo is fair for the automation power you get; the free plan would throttle you after a few dozen leads, which quickly becomes frustrating.

OpenAI’s cost is negligible at low volume, but if you start generating dozens of emails per hour, keep an eye on token usage. At $0.02 per 1,000 tokens, a thousand emails still costs less than $5.

One gripe I have is with Apify’s documentation: the actor’s output schema is buried in a FAQ page, and the example JSON is outdated. I spent an hour guessing which fields were present before finding the correct schema in a community forum. — and good luck finding docs for this — but once you have it, the actor works like a charm.

My concrete love is the ability to chain HTTP modules in Make without writing a line of code. Dragging the OpenAI module onto the canvas, setting the method to POST, and pasting the JSON payload feels like assembling LEGO bricks—fast, visual, and reliable.

Putting it all together: a numbered step‑list

  1. In Apify, deploy the LinkedIn Profile Scraper actor and note its API endpoint.
  2. In Make.com, create a new scenario. Add an HTTP module → GET request to fetch your list of LinkedIn URLs from Google Sheets.
  3. Add another HTTP module → POST to the Apify actor, passing the URL array as payload.
  4. Use a Parser module to extract firstName, lastName, headline, companyName from each scraped record.
  5. Set up a Text module to render the email prompt using the placeholders shown earlier.
  6. Add an HTTP module → POST to OpenAI’s chat completions endpoint, sending the rendered prompt and your API key.
  7. Parse the OpenAI response to pull out the generated email.
  8. Finally, add a HubSpot module → Create or update a contact, storing the scraped fields and the email.
  9. Save the scenario, schedule it to run hourly, and turn on email Slack alerts for any router failures.

Follow those steps, and you’ll have a working AI agent that scrapes, writes, and logs—no custom code required.

For more on this exact angle, 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.

— The Colophon

One AI tool. Tested. Reviewed.
In your inbox every Sunday.

~3 minute read. Real outcomes from operators, not marketers.

Free. One email per Sunday. Unsubscribe in one click.