fix: normalize Skill tool args to prevent TypeError when models pass objects - #186
Open
linhongyu510 wants to merge 1 commit into
Open
linhongyu510 wants to merge 1 commit into
linhongyu510 wants to merge 1 commit into
Conversation
…objects
Small/open models on custom providers often wrap tool input in an
object ({'args': {...}}) or a list. _skill_tool handed the raw value
to substitute_arguments, which called prompt.replace("", args)
and crashed with 'TypeError: replace() argument 2 must be str, not
dict' — surfaced verbatim to the model, which retried the same call
and gave up on the skill (SAIL-Research-Lab#182).
Add _normalize_args(): unwrap a single-string-value dict, join a list
of strings, and return a concrete correction for anything else so the
model gets an actionable error instead of a traceback.
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.
Problem
When a model calls the
Skilltool withargsas an object instead of a string, the tool crashes:Observed tool call (from a saved session,
mr_sessions/session_latest.json):{"name": "Skill", "input": {"name": "recall", "args": {"args": "--corpus \"$MEMORY_CORPUS\" --k 5"}}}_skill_tooldoesargs = params.get("args", "")with no type check and hands the value tosubstitute_arguments, which callsprompt.replace("$ARGUMENTS", args)→TypeError. The raw traceback is surfaced verbatim to the model, which retries the identical call and eventually gives up on the skill and hallucinates the answer (observed: 4 identical retries withgpt-oss-120bvia llama-server). Small/open models on custom providers wrap tool input in an object fairly often because every tool appears to them asinput: {...}.Fix
Add
_normalize_args()incheetahclaws/skill/tools.pyand call it at the top of_skill_tool:str→ unchanged.dictwith a single string value (the observed{"args": "..."}shape) → unwrap the value.listof strings (e.g.["--env", "prod"]) → join with spaces.None, …) → return a concreteError: Skill 'args' must be a string…message with a suggested shape, so the model gets something it can act on instead of a traceback.Tests
4 new tests in
tests/test_skills.py(all fail onmain, pass here):The shared
skill_dirfixture now also writes the existingdeployskill (theARGS_MDfixture constant already defined in the file) so the new tests exercise a prompt containing$ARGUMENTS;test_load_skillscount assertion updated 2 → 3 accordingly.Verification:
tests/test_skills.py30 passed (26 pre-existing + 4 new). Full non-e2e suite: 2782 passed; the 5 failures and 33 web-api import errors are environment-related and reproduce identically onmain(macOS rlimit/case-sensitivity, missing SQLAlchemy for thewebextra).ruff checkon the two touched files reports only the 6 pre-existing findings — no new lint issues.Honest caveat: the tool's agent run is mocked in tests (
_fake_run), so the fix is verified at the unit level; no live model run was performed.