fix(agent-core-v2): coerce string-typed tool arguments at the parse boundary
Related Issue
Resolve #2118
Problem
Some third-party models emit tool-call arguments as JSON strings ("3") instead of the declared JSON types (3) — reported in the linked issue on 0.29.0 with Qwen. The arguments are decoded faithfully and validated strictly, so the call is rejected with Invalid args for tool ... and the turn stalls, even though the model's intent is unambiguous.
What changed
The fix sits at the tool-call parse boundary — the earliest point the harness controls — and keeps validation itself strict. Two moves, as discussed in the issue:
-
A normalization layer before validation. It is generic and bounded by design, so it stays a single schema-driven rule rather than growing into a catalog of model-specific hacks: only lossless
string → integer / number / booleancoercions, only when the schema does not already accept strings at that position;$refnodes and ambiguous schemas are left untouched. -
A warning that keeps the provider's violation visible. Coerced calls succeed, but the tool result carries a model-visible note (rendered to the model at projection time, never shown in UIs) describing exactly what was coerced — the non-conforming output is absorbed without being silently hidden.
When coercion cannot fix the arguments, the rejection now says what actually arrived (e.g. /line_offset must be integer (received string "3")) so the model can self-correct, and duplicate type errors from union branches are deduplicated.
Scope: the v2 engine only, which is what the current CLI runs on. The v1 engine has an isomorphic parse/validate path; happy to mirror the change there if the team wants both covered.
Tests: unit coverage for the normalization rules and the new error wording, plus executor integration tests covering coercion with the warning note, note merging with the tool's own note, honest rejection, and clean passthrough. Roughly half of the +571/−11 diff is tests.
Checklist
- [x] I have read the CONTRIBUTING document.
- [x] I have linked a related issue, or explained the problem above.
- [x] I have added tests that prove my feature works.
- [x] Ran
gen-changesetsskill, or this PR needs no changeset. - [x] Ran
gen-docsskill, or this PR needs no doc update.
🦋 Changeset detected
Latest commit: 1cc8d4f4f532d5bcba5f94fbb9a42f7e84e52f29
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 1 package
| Name | Type |
|---|---|
| @moonshot-ai/kimi-code | Patch |
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR
@Codex review
I’m inclined to close this PR after revisiting it.
I. Kimi Code already does strict schema validation well. Returning clearer, actionable errors to the model can still be considered separately, such as including the expected schema or applicable recovery actions. II. But coercing string-typed tool arguments before validation is not the right approach. This is not about making the Harness generic, nor is it a product decision.
Closing for now.