All articles
EngineeringAI AgentsAI Research Agent

Why Our AI Research Agents Were Slow (It Wasn't the Model)

Our AI research agents took 17 minutes to fill a grid, and the model was not the cause. How we found the wait in our orchestration and fixed it.

7 min read
On this page

Short answer: most of our AI agent latency was not in the model. A 22-row grid took 17 minutes because our scheduler left slots idle, held database connections during network calls, and sent retries to the back of the queue. We made seven fixes, found eight more problems with a free load test and a second review, and expect the same grid to finish in about 9 to 10 minutes.

Why our AI research agents were slow

One of our GridIQ grids had 22 researchers as rows and four questions as columns: each researcher's email, research focus, most relevant publication, and where they work today. Filling it took 17 minutes.

GridIQ answers each question with a research agent that searches the web, reads pages and cites its sources. One agent working on one row is a task, and we run up to eight tasks at a time, one per slot.

The grid didn't fill evenly. Seven tasks failed at the same moment and had to start again from the back of the queue. Three more were cut off part way. The last rows arrived long after the rest, so the grid looked stuck.

How we measured AI agent latency

We logged how long each task waited for a slot and why each retry happened, then counted, second by second, how many slots were busy. All eight were busy for only 290 of the run's roughly 1,040 seconds. In the chart, every yellow bar is time when a slot was free and work was waiting.

Seconds of the 17-minute run spent with each number of slots busy. All 8 slots were busy for only 290 of 1,038 seconds.

The failed and cut-off attempts alone used about a quarter of all slot time and produced no answers.

Seven AI agent orchestration fixes that cut latency

Database connections held during network calls

Some code kept a database connection open while it waited on another service. The small pool ran dry, and seven tasks failed at once. Now every network call happens first, and a connection is held only for the short write.

BeforeAfter
Each task kept its database connection open while it waited for an HTTP or queue call. When all 11 were busy, the next request waited 30 s and failed. In our largest traced run, 7 tasks failed this way at the same moment.

Retries went to the back of the line

A failed task queued behind everything created after it, so unlucky rows finished last. A retry now keeps its place.

BeforeAfter
A failed task got a new timestamp, and dispatch sorts by timestamp. So every other waiting task ran first. In the largest run, retried tasks started again 2 to 8 minutes later.

Tasks waited for a question rewrite

GridIQ rewrites each question into clearer wording before research. The first task did it while the others waited inside their slots, sometimes for minutes. Tilak, one of our engineers, asked why we managed the wait at all. Now one small prepare task writes the wording before any row starts, so nothing waits.

BeforeAfter
The first row task wrote the improved wording of the questions. Every other row task checked the claim and went back to the queue for 10 s. If the writer died, the claim counted as dead only after 10 minutes.

A row's questions ran one after another

The location lookup waited for the email lookup, even though neither needs the other. Lookups now run together, and only a judgement waits for the facts.

BeforeAfter
Task 2 of a row waited for task 1, even with free slots. A judgement does need the lookup answers, but the rule applied to every task. Illustration with 6 rows and invented task lengths.

One big grid could take every slot

Each organization with work now gets a fair share, and a free slot is refilled as soon as a task ends.

BeforeAfter
The cap counted running tasks across every org. One large grid could fill all 8 slots, and every other org waited until it finished.

The grid page reloaded everything

An open page fetched every row every 10 seconds, and each read wrote to the database. It now fetches only changed rows and never writes on a read.

BeforeAfter
While a run was active, the grid page asked for the full page of rows every 10 s, with every cell's text. Each read also ran two database writes to mark old cells.

The page reader thought too long

We also let the page reader, the small model that reads web pages for the agent, think less. Its reasoning took about 30 seconds of a 71-second task. In a five-row test, tasks got 12% faster and 28 of 30 answers stayed the same.

Fewer reasoning tokens also lower the cost of each task. Our LLM cost optimization article shows how we measure cost per completed task.

Stress testing AI agents without spending credits

A real grid run costs credits, and the web changes between runs. So we built a simulated mode. The scheduler, queue, database and grid page run for real. Every model, search and service call is a stub that waits as long as the real call did in our traces, then returns a stored answer.

We sized it like our servers (half a CPU, 1 GB, eight slots) and pushed it past capacity, up to ten organizations at once with 30 open grid pages. We also failed 15% of model calls on purpose and killed a worker in the middle of a run. To keep each scenario short, the stubs ran at a quarter to a third of real speed.

It found five scheduling bugs in the fixes above. A second code review of those fixes found three more problems, including a check that got slower as the backlog grew. We fixed all of them:

BugBefore the fixAfter the fix
A big grid starved small onesSmall grids waited 1,054 to 1,225 seconds for a first answer10 to 14 seconds
Free slots were not refilled at onceSlots sat empty for 15-second stretches7 to 8 seconds at most
With more organizations than slots, one kept every free slotTwo organizations waited about 1,300 secondsEvery organization answered within 40 seconds
Blocked or unused shares sat emptyIdle stretches of up to 33 secondsUp to 8 seconds

With every fix in, a three-organization load finished 49% faster (1,461 to 745 seconds), and slots stayed 91% to 94% busy. No task ran twice, no work was lost when the worker died, and the database never came close to its limits. The first thing to strain was the grid page, which stays fast up to about 10 open tabs on today's half CPU.

Results

TimeFailed or cut-off attempts
The production run, before the fixes17.4 minutes10 of 51
The same work, estimated with the fixesabout 9 to 10 minutesnone expected

The estimate takes the production run's own task times, removes the attempts that failed or were cut off, and adds the scheduling waste that remained on our test grid after the fixes. These fixes reach production in our next release, and we'll replace the estimate with a measured run.

How to reduce AI agent latency: what we learned

Measure where the time goes before you change the model. Ours had capacity to spare. The waste was in our scheduler. LangChain gives the same advice in How do I speed up my agent?

Work out the floor: total task time divided by the number of slots. Close to it, only shorter tasks or more slots help.

Stress test the fix, not only the bug. Our load test found five new problems in code we thought was finished, and a review of those fixes found three more.

FAQ

Why is my AI agent so slow?

Often the model is not the cause. Check how long each task waits before it starts, how often it retries, and whether independent tool calls run one after another. In our grid, idle slots and failed attempts cost more time than the model did.

How do you reduce AI agent latency?

Measure first. Then run independent calls in parallel, let a retry keep its place in the queue, and never hold a database connection during a network call. Where answers stay the same, let a small model reason less.

How can you load test an AI agent without paying for API calls?

Replace each model, search and service call with a stub that waits as long as the real call did and returns a stored answer. Keep the scheduler, queue and database real. Our load test found five scheduling bugs this way before release.

GridIQ is the research grid inside alkemy. See how it fills a grid with sourced answers.

Put the ideas to work.

Explore how alkemy helps you research accounts and prepare your next client conversation.

Explore alkemy