fix: handle bracketless list arguments from LLM#785
Open
octo-patch wants to merge 3 commits into
Open
Conversation
added 3 commits
April 19, 2026 09:33
The GLM NLP adapter in glm_service.py used the OpenAI client to access the bigmodel.cn API, while the Zhipu adapter (zhipu_service.py) already provides proper integration using the official zhipuai SDK with support for GLM-4 model variants. Remove the duplicate glm_service.py and the NLPServices.glm() factory method from the SDK. Users should use NLPServices.zhipu() instead. Signed-off-by: octo-patch <octo-patch@github.com>
Signed-off-by: octo-patch <octo-patch@github.com>
LLMs occasionally produce list arguments as comma-separated values without the surrounding brackets (e.g. "red, green" instead of "['red', 'green']"). This caused ValueError/SyntaxError in: - split_arg_list() in core/tools.py - split_arg_list() in core/services/tools/mcp_service.py - _validate_argument_value() in the two tool-calling batch modules The fix: when literal_eval() fails (str/Enum item types), fall back to comma-splitting; for scalar types, strip optional brackets then split by comma, making both paths robust to the bracketless LLM output format. Also adds unit tests covering both the bracketed and bracketless cases for str, Enum, and int item types. Signed-off-by: octo-patch <octo-patch@github.com>
Contributor
|
Hi @octo-patch - thanks for the contribution! Can you please resolve the conflicts and push? |
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.
Fixes #431
Problem
LLMs occasionally produce list arguments as comma-separated values without surrounding brackets (e.g.
red, greeninstead of['red', 'green']). This non-deterministic hallucination caused crashes in:split_arg_list()incore/tools.py— raisedValueError(invalid list format)split_arg_list()incore/services/tools/mcp_service.py— raisedValueError_validate_argument_value()in both tool-calling batch modules —ast.literal_eval()raisedSyntaxError/ValueErrorSolution
split_arg_list()(str/Enum item types): Tryliteral_eval()first; fall back to comma-splitting with strip when it fails.split_arg_list()(scalar types like int/float): Strip optional[...]brackets if present, then split by comma — making brackets optional._validate_argument_value()(both batch files): Wrapast.literal_eval()in a try/except and fall back to comma-splitting for array enum validation.Testing
Added 13 unit tests in
tests/core/stable/test_tool_argument_handling.pycovering:cast_tool_argumentwith bracketlesslist[int],list[str], andlist[Enum]All 13 tests pass. Ruff lint and mypy checks pass (pre-existing mypy errors in optional adapter stubs are unrelated to this change).