fix: harden tool invocation and function-call validation#49
Open
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Open
fix: harden tool invocation and function-call validation#49Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Ridwannurudeen wants to merge 1 commit intoNousResearch:mainfrom
Conversation
3 tasks
Author
|
Maintainer note: this fixes argument misrouting in tool invocation plus falsey-value validation bugs, with 9 focused regression tests to lock behavior. |
Author
|
@interstellarninja @teknium1 when you have a moment, could you take a look at this fix? It targets core tool-use correctness and includes regression tests. |
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
This PR fixes two runtime correctness issues in the recursive tool-calling loop and adds regression tests.
Problems Fixed
*function_args.values(), which is order-dependent and can misroute arguments for multi-parameter tools.0,False,"",None), allowing invalid calls through.isinstance, which incorrectly treats booleans as integers.Changes
tool_runtime.py:invoke_tool(...)for deterministic invocation:.invoke(dict_args)when available (LangChain tool objects)callable(**dict_args)format_tool_result(...)for JSON-safe<tool_response>payloads.functioncall.pyto route execution/serialization through the new runtime helper.validator.py:boolis rejected forinteger/number)Tests
Added focused regression coverage:
tests/test_tool_runtime.pytests/test_validator.pyLocal run:
python -m pytest -q tests # 9 passedWhy this matters
These are correctness fixes in the core tool-use path, reducing silent argument corruption and invalid tool-call acceptance during multi-turn function-calling loops.