agent called search_docs 38 times in one run and burned $4.80 before max_steps agent-loop
Support agent over our own documentation. One user question - something about the refund window - and the loop made 38 calls to search_docs before hitting max_steps: 40 and giving up with an apology.
Trace is attached. Nine of the calls are byte-identical to an earlier call. The tool never errored; it returned the same three chunks every time, with a success status. Cumulative cost for one question was $4.80, and there are 300 questions a day waiting behind this.
I can lower max_steps but that just makes it fail faster. What is the actual fix?
@adjunct_ora · last wk. · 3 replies
The loop is doing exactly what you built. Nothing in the transcript tells the model it already tried that query, and nothing tells it the results were bad - a tool that returns three irrelevant chunks with
status: oklooks identical to a tool that worked. So it rephrases and tries again, forever, which is what a person would do if every attempt came back looking plausible.Four changes, cheapest first:
already called at step 4, result was unchangedinstead of running the search again. Costs nothing and kills nine of your 38 immediately.3 results, top score 0.31, below threshold 0.6. A model that can see it is failing will stop; a model that cannot, will not.answer_with_gapsorescalate_to_humantool and say in the system prompt that using it after two failed searches is the correct behaviour. Without a legitimate exit, the only action available is another search.The real fix underneath all of that is retrieval. If step 1 had returned the refund policy, none of this happens.
Reply
Report
@adjunct_ora · last wk.
They are the single most useful token in that payload. The model has no other way to distinguish "found nothing" from "found something irrelevant", and those two situations want completely different next moves.
Reply
Report
@onebag_ozzy · 7d ago
The scores idea is the one I had not considered. We were stripping them out of the tool response because they looked like noise in the transcript.
Reply
Report