You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
LM tool loop treats max_tool_iterations=1 as immediate failure #61
LM::execute_tool_loop currently executes the initial tool call, then iterates with for iteration in 1..max_iterations.
When max_tool_iterations is set to 1, that follow-up loop runs zero times and the function always returns Max tool iterations reached, even though one iteration was explicitly allowed.
Why this matters
This makes max_tool_iterations=1 unusable for valid single-iteration tool workflows and can surface as an unexpected hard failure.
Reproduction
Configure an LM with max_tool_iterations = 1.
Make a request that triggers a tool call.
Observe that the initial tool is executed, then the call fails with Max tool iterations reached.
Expected
With max_tool_iterations=1, one follow-up completion turn should be attempted after the initial tool result is appended, or the setting semantics should be clarified and enforced consistently.
Actual
No follow-up completion turn is attempted; the function exits with a max-iterations error.
Candidate fixes
Adjust loop bounds (for example 1..=max_iterations) if the current setting represents allowed completion iterations after the initial tool call.
Or redefine semantics so max_tool_iterations is total tool-call budget and update logic/docs accordingly.
When max_tool_iterations = 1, max_iterations = 1, so 1..1 is an empty range — zero iterations.
Fix:1..=max_iterations (inclusive range) if the semantics are "number of follow-up completion turns allowed after the initial tool call".
Alternatively, if max_tool_iterations should mean "total tool-call budget including the initial one", the initial execution already counts as 1, so the loop should be 1..max_iterations (current behavior is correct for that interpretation, but then max_tool_iterations=1 means "execute the tool but don't do a follow-up completion", which is arguably a valid no-op). Clarify the semantics and update the doc comment on the field.
Activity
darinkishore commentedon Feb 12, 2026
Confirmed — exact location
crates/dspy-rs/src/core/lm/mod.rs:281:When
max_tool_iterations = 1,max_iterations = 1, so1..1is an empty range — zero iterations.Fix:
1..=max_iterations(inclusive range) if the semantics are "number of follow-up completion turns allowed after the initial tool call".Alternatively, if
max_tool_iterationsshould mean "total tool-call budget including the initial one", the initial execution already counts as 1, so the loop should be1..max_iterations(current behavior is correct for that interpretation, but thenmax_tool_iterations=1means "execute the tool but don't do a follow-up completion", which is arguably a valid no-op). Clarify the semantics and update the doc comment on the field.