fix(agents): trim whitespace from LLM tool call names to prevent lookup failures#27313
Closed
Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Closed
fix(agents): trim whitespace from LLM tool call names to prevent lookup failures#27313Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Sid-Qin wants to merge 1 commit intoopenclaw:mainfrom
Conversation
…up failures Some models return tool call names with leading/trailing whitespace (e.g. " read " instead of "read"). The agent loop in pi-agent-core uses an exact-match lookup (`tools.find(t => t.name === toolCall.name)`) which fails on these names, producing "Tool not found" errors. Wrap the stream function to intercept response events and trim toolCall content block names in-place before they reach the agent loop's tool dispatch. Closes openclaw#27045
Contributor
Greptile SummaryFixes intermittent "Tool not found" errors by trimming whitespace from LLM-returned tool names before lookup. Some models return tool names like Key changes:
Implementation notes:
Safety:
Confidence Score: 5/5
Last reviewed commit: 5bc6e02 |
jeancloud007
approved these changes
Feb 26, 2026
jeancloud007
left a comment
There was a problem hiding this comment.
LGTM. Defensive fix for LLM quirks - trimming tool names in the stream wrapper is clean and targeted. The in-place mutation approach avoids creating new objects while ensuring the trimmed names propagate to the done event. Good documentation.
Member
|
Superseded by #27094 (merged on main). |
Member
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
" read "instead of"read"), causing the agent loop's exact-match lookup to fail with "Tool not found" errors.wrapStreamFnTrimToolNames()stream wrapper that intercepts response events and trimstoolCallcontent block names in-place before they reach the agent loop's tool dispatch.Change Type (select all)
Scope (select all touched areas)
Linked Issue/PR
User-visible / Behavior Changes
Tool calls with whitespace-padded names (e.g.
" read "," exec") now resolve correctly instead of failing with "Tool not found".Security Impact (required)
Testing
npx vitest run src/agents/pi-embedded-runner/run/attempt— 9 tests ✓Rollback Plan
Revert the single commit. No migration or data changes involved.