LightAgent icon indicating copy to clipboard operation
LightAgent copied to clipboard

Tool-call loop (while True:) has no max-iteration / max-tool-call cap

Open VamsiSudhakaran1 opened this issue 4 months ago • 1 comments

Hi — thanks for LightAgent. One robustness issue in the streaming run loop:

LightAgent/core.py — _run_stream_logic

for _ in range(max_retry): try: while True: # line 1165 — inner tool-call loop ... for chunk in response: ... The outer for _ in range(max_retry) bounds retries, but the inner while True: drives multi-turn tool calls and only exits when the model decides to emit the finish tool (finish_called). There's no cap on iterations, tool calls, or cumulative tokens. If the model keeps emitting tool calls — or oscillates between two tools, which happens under prompt injection or with a flaky tool — the loop spins and burns tokens/budget with no ceiling.

Relatedly, the intent-detection call has no output ceiling:

core.py:1710

response = self.client.chat.completions.create( model=self.model, messages=[{"role": "system", "content": prompt}] ) # no max_tokens Suggested fix: add a max_tool_iterations (or max_tool_calls) guard to the inner loop with a clean break + logged reason, so a non-converging agent can't spin unbounded. The uncapped call is minor on its own, but pairs with the loop to make runaway cost a real path.

Found with release-gate, an open-source pre-deploy checker for agent-runtime risks.

VamsiSudhakaran1 avatar Jul 05 '26 14:07 VamsiSudhakaran1

I can take this. Plan: keep the change small by aligning the streaming tool-call loop with the existing max_retry guard used by the non-streaming path, emit a clear max-tool-iterations error when the stream keeps requesting tools, and add a regression test for a looping tool-call stream.

helloJamest avatar Jul 06 '26 02:07 helloJamest