Most AI agent tutorials show a flashy demo then leave you stuck when the agent hallucinates or loops.
By the end of this guide you’ll have a working lead‑qualification agent that calls an API, checks its own output, and stops when it’s done.
You’ll also know where to look when things break and whether a pre‑built blueprint saves you hours.
How do you stop the agent from hallucinating when it calls external data?
Hallucinations happen when the model makes up facts because it lacks grounding.
A simple fix is to ask the agent to verify any claim against a trusted source before it proceeds.
In practice you can add a verification step that calls a known API and compares the response.
If the data does not match, the agent asks for clarification or falls back to a safe default.
This pattern works whether you are using OpenAI, Anthropic, or a local model.
Here is a short prompt that forces verification:
You are a lead‑qualification agent.
1. Receive a lead email.
2. Extract the company name and website.
3. Call the Clearbit API to get the real company size.
4. Compare the size you guessed with the API result.
5. If they differ by more than 20%, say "I need to check the company size again" and stop.
6. Otherwise continue to the next step.
Notice the explicit stop condition.
Without it the agent would keep guessing and could send a wrong qualification to your CRM.
This verification step adds almost no latency because the Clearbit call is fast and cheap.
What most guides get wrong about agent memory
Many tutorials treat memory as an afterthought.
They show you how to store a single variable and then forget about it.
In a real workflow the agent needs to remember multiple turns of conversation, the outcome of API calls, and any user‑provided constraints.
If you only keep the last message you will lose context after two steps and the agent will start repeating itself.
A better approach is to keep a short rolling buffer of the last three interactions.
Each buffer entry stores the user message, the agent response, and any API data returned.
When the agent decides what to do next it reads the whole buffer.
This simple structure prevents the agent from contradicting itself and makes debugging easier.
A concrete example: lead‑qualification agent with Make and OpenAI
We will build an agent that runs in Make (formerly Integromat) and uses the OpenAI GPT‑4o model.
The agent receives a new lead from a webhook, qualifies it, and writes the result to a Google Sheet.
First, set up a webhook in Make that captures the incoming lead JSON.
Next, add an HTTP module to call OpenAI with the following prompt:
You are a sales assistant.
Given the lead details below, decide if the lead is qualified.
Qualified means: company size > 50 employees, located in the US, and the lead title contains "Manager" or "Director".
Return ONLY the word "qualified" or "not qualified".
Lead details:
{{lead.json}}
Make will replace {{lead.json}} with the actual payload.
After the OpenAI call, add a Router that checks the output.
If the output is “qualified” send a row to Google Sheet with status “Qualified”.
If the output is “not qualified” send a row with status “Not Qualified”.
Add a final HTTP module that calls your internal CRM to create a contact only for qualified leads.
Cost breakdown:
- Make free tier allows 1,000 operations per month – enough for a solo tester.
- OpenAI GPT‑4o costs $0.03 per 1k tokens; each qualification call uses about 800 tokens, so roughly $0.024 per lead.
- If you process 200 leads a month the AI cost is under $5.
- Google Sheets and the CRM webhook are free on their free tiers.
At $29/mo for the Make Core plan you get unlimited operations, which is fair if you expect more than 5k operations a month.
$199/mo for the Make Enterprise plan feels steep for what you get unless you need dedicated support and higher concurrency.
