Skip to content

Fix automatic LM tool-loop limits and final completion - #132

Open
arthurianresolve wants to merge 8 commits into
krypticmouse:mainfrom
arthurianresolve:fix-lm-tool-loop-limit
Open

arthurianresolve wants to merge 8 commits into
krypticmouse:mainfrom
arthurianresolve:fix-lm-tool-loop-limit

Conversation

@arthurianresolve

@arthurianresolve arthurianresolve commented Nov 9, 2026 •

Copy link
Copy Markdown

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_iterations for 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

  • Standalone resolved Fix LM history inspection and cache isolation on client replacement #131 + Fix automatic LM tool-loop limits and final completion #132 branch: 22 passed (13 LM lifecycle/cache tests and 9 automatic tool-loop regressions), with 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.
  • The resolved stack at 2b4590f0174dc05582347b8da75b6b58fbce9ca0 passed 209 tests with --no-default-features and 247 with default data/cache features (2 live tests ignored in each offline run). These are focused library and integration suites, not the full workspace test suite.
  • Mocks and counting tools check actual side effects; the live example matrix does not exercise native tools.
  • git diff --check — passed.

AI Disclosure

  • OpenAI Codex assisted with implementation, tests, and PR drafting.
  • all fixes and drafts have been human-architected, human-directed and human-reviewed before publication of PR requests.

@mintlify

mintlify Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 8877acd.

Approve preview

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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LM tool loop treats max_tool_iterations=1 as immediate failure

1 participant