Repository navigation
Fix automatic LM tool-loop limits and final completion - #132
Open
arthurianresolve wants to merge 8 commits into
Open
arthurianresolve wants to merge 8 commits into
arthurianresolve wants to merge 8 commits into
Conversation
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
This was referenced Nov 10, 2026
arthurianresolve
added a commit
to arthurianresolve/DSRs
that referenced
this pull request
Nov 19, 2026
Integrate krypticmouse#132 — Fix automatic LM tool-loop limits and final completion
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Fix
Includes #131's resolved LM lifecycle changes. Merge #131 before this PR, then #133.
Allow a final completion after the last permitted tool-execution round, so
max_tool_iterations(1)can execute one round of tools and return the model's final answer.Define the limit as tool-execution rounds, including the initial round. Parallel tool calls in one model response count as one round.
Reject tool requests beyond the limit before executing them. A zero limit prevents automatic tool execution while still allowing text responses.
Document the limit and add regressions for limits of 0, 1, and 2, exhaustion, text-only responses, and caller-managed loops.
Return typed iteration-limit and execution errors while preserving the original tool error as a source. Keep unknown-tool feedback recoverable so the model can finish without executing another tool.
Fixes #61
Why
The automatic LM loop executed the initial tool round, then used
1..max_iterationsfor follow-up completions. With a limit of 1, that range was empty, so a valid tool workflow failed before the model could produce its final answer. A zero limit still executed the initial tools.The inclusive follow-up range permits the final answer. A check before initial execution and another before executing tool requests on the final allowed follow-up keep tool side effects within the configured limit. Caller-managed loops and IR agents retain their separately controlled limits.
Related work
Testing
cargo +1.99.1 test -p dspy-rs --no-default-features --test test_lm --test test_lm_tool_loop_limits --locked -j1.test_lm_tool_loop_limits— 9 passed on the resolved stack: limits 0/1/2, exhaustion, text-only and caller-managed paths, preserved execution causes, and recoverable unknown tools.2b4590f0174dc05582347b8da75b6b58fbce9ca0passed 209 tests with--no-default-featuresand 247 with defaultdata/cachefeatures (2 live tests ignored in each offline run). These are focused library and integration suites, not the full workspace test suite.git diff --check— passed.AI Disclosure