Last quarter I tried to automate lead follow‑up with a chain of GPT‑4 calls and kept hitting rate limits and hallucinated outputs.
After wasting two weeks on brittle prompts, I settled on a simple loop that checks its own work and only calls the model when needed.
By the end of this article you’ll have a repeatable pattern for building AI agent projects that stay under budget and actually finish tasks.
How do you keep an agent from looping forever?
The first trap is the endless “think‑then‑act” loop where the agent asks itself the same question over and over.
I ran into this when I gave the agent a goal like “find three qualified leads” and let it decide when to stop.
Without a hard stop it would keep querying the model, burning tokens and never returning.
The fix is simple: give the agent a counter and a ceiling.
Each loop increments a step variable; when it hits the limit the agent forces a final output.
In practice I set the ceiling to five iterations—enough for research, reflection, and a final summary, but low enough to avoid runaway costs.
You can see the pattern in the pseudocode below.
- Set
max_steps = 5andstep = 0. - While
step < max_steps: - Ask the model to perform the next sub‑task.
- Increment
step. - When the loop exits, ask the model to synthesize the collected data into the final answer.
This tiny guardrail stops the agent from spiraling and makes the runtime predictable.
What most guides get wrong about prompt chaining
Many tutorials treat each prompt as an independent call and then glue the outputs together with string concatenation.
That approach ignores context drift: the model forgets earlier constraints after a couple of turns.
I tried that with a three‑step chain for lead enrichment and watched the agent start adding fake phone numbers after the second step.
The better method is to pass a short “memory blob” that summarizes what has been done so far.
Before each new prompt I prepend a one‑sentence recap like “So far we have verified the company domain and identified the decision‑maker’s title.”
That keeps the model anchored to the original goal and reduces hallucinations.
It also makes debugging easier because you can inspect the memory blob at any step.
A concrete named example: building a lead‑qualifier agent with GPT‑4 and Make (formerly Integromat)
Here’s the exact flow I use for a solo consulting business.
First, I created a scenario in **Make.com** that watches a Google Sheet for new rows.
When a row appears, the scenario pulls the company name and website, then calls GPT‑4 with a prompt that asks for three pieces of info: industry, estimated employee count, and whether the company uses a CRM.
The prompt looks like this:
You are a research assistant. Given the company name "{{company}}" and its website "{{website}}", return a JSON object with the fields: industry, employee_range, uses_crm. If you cannot find an answer, set the value to null.
Make.com parses the JSON and writes the results back to the sheet.
If the model returns null for any field, the scenario routes the row to a Slack channel where I manually check the data.
I love how the built‑in error handling in Make lets you route a failed HTTP call to a Slack alert without writing any code.
The concrete gripe I have is the way Make.com hides its webhook URL behind a “Deploy” button that only appears after you’ve already spent 20 minutes configuring the scenario.
Which, yes, is annoying when you’re trying to iterate quickly.
On the cost side, Make’s core plan is $29/mo and gives you enough operations for a few hundred agent runs per day.
$199/mo for the enterprise tier feels ridiculous unless you’re running thousands of agents or need advanced team features.
For the model, I use the standard GPT‑4 API at $0.06 per 1k tokens; a typical lead‑qualifier run uses about 800 tokens, so each lead costs roughly $0.05.
At ten leads a day that’s $0.50—well under the $29/mo Make fee.
