Repository navigation
fix(core): stop empty-object tool-call content from masking intact parsed arguments - #3886
Merged
juruoO-o merged 1 commit intoNov 11, 2026
Conversation
…rsed arguments
ToolCallsAccumulator fabricated content="{}" whenever a tool call arrived
without streamed argument fragments (single-chunk or non-streaming providers
that emit the complete parsed input only). The empty object is valid JSON, so
resolveToolCallArgsJson's content-first resolution short-circuited on it and
every consumer saw empty arguments: required-parameter validation rejected the
call before execution, and request builders / compaction replayed the call to
the model with empty arguments - while the intact input map sat beside them.
Three coordinated changes close the fabrication, the blind spot, and the
direct-path execution gap:
- source: the accumulator serializes the parsed arguments instead of
fabricating an empty object, through the shared guarded entry point
(JsonUtils.toJsonFallbackEmptyObject) so a serialization failure falls back
to "{}" instead of failing the reply stream; the content-always-valid-JSON
invariant and the malformed-marker paths are unchanged;
- resolution: resolveToolCallArgsJson no longer lets an empty-object content
mask intact parsed arguments (a structurally empty JSON object with a
non-empty input resolves to the input), which also covers already-persisted
blocks and directly constructed blocks for validation, request builders,
and compaction at once; malformed-marked blocks are exempt - valid content
is kept, null/empty/invalid content sanitizes to "{}", never the merged
input;
- execution: ToolExecutor, the single funnel behind direct Toolkit.callTool
paths, refuses malformed-marked calls before schema validation, mirroring
the agent loop's refusal - the merged input beside the marker may even look
complete and schema-valid.
Sixteen new tests; the core regression paths were red-verified pre-fix.
juruoO-o
approved these changes
Nov 11, 2026
juruoO-o
left a comment
Collaborator
There was a problem hiding this comment.
已核对 accumulator、参数解析、schema 校验和直接 Toolkit 执行入口。源头避免伪造空参数,解析层覆盖已有的 input-only/旧持久化调用,executor 继续拒绝 malformed 调用,三处改动对应实际消费路径。未发现不必要的接口破坏或阻塞问题;本轮为代码复核,未重跑全量测试。
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.
AgentScope-Java Version
2.1.0-SNAPSHOT (based on
main@e190a8d1b)Description
ToolCallsAccumulatorfabricatedcontent = "{}"whenever a tool call arrived without streamedargument fragments — the shape produced by providers and custom
Modelimplementations thatemit the complete call in one chunk with the parsed
inputonly (the in-repo e2e fixturesthemselves construct exactly this shape). The intact
inputmap survived beside the fabricatedcontent, but every content-first consumer of
JsonUtils.resolveToolCallArgsJsonresolved thearguments to
{}— the empty object is valid JSON, so the resolver's existing fallbacks(null/empty/invalid content) never fired:
ToolExecutor) rejected the call before execution — any tooldeclaring
requiredparameters was 100% rejected on this path, with the model told to "correct"arguments it had actually supplied;
the provider with empty arguments, so later turns showed the model a call it never made;
Nothing warned or logged; calls to tools without required parameters even executed correctly
(the invocation path reads the input map), which made the failure look model-sided.
Three coordinated changes close the fabrication, the blind spot, and the direct-path execution
gap:
object (
toJsonFallbackEmptyObject, the shared guarded entry point also used for inputserialization; a serialization failure falls back to
"{}"instead of failing the replystream). The content-always-valid-JSON invariant and the malformed-marker paths (truncated or
invalid raw content) are unchanged; a true no-argument call still produces
"{}".resolveToolCallArgsJsonno longer lets an empty-object content mask intactparsed arguments: when the content is an empty JSON object (any whitespace form) and
getInput()carries arguments, the input is used. This covers blocks that were alreadypersisted with the fabricated value (resumed sessions never pass through the accumulator
again) and blocks constructed directly by application code, for all three consumers at once
(validation, request builders, compaction). First-party adapters derive both fields from the
same source, so the branch is unreachable for well-formed provider output; an empty-object
content with an empty input resolves to
"{}"exactly as before.exempt from the input recovery in both the resolver and the executor:
resolveToolCallArgsJsonkeeps their content when it is valid JSON and sanitizesnull/empty/invalid content to
"{}"— never the merged input, never invalid JSON; andToolExecutor(the single funnel behind directToolkit.callToolpaths) now refuses anymalformed-marked call before schema validation. The merged input beside the marker may even
look complete and schema-valid — without the guard such a call would execute on paths the
agent loop already refuses (red-verified: it executed and returned its result).
Compatibility
"{}"while a non-emptyinput map sat beside it: they now resolve to the real arguments everywhere. No consumer loses
information; no-argument calls and non-empty content behave exactly as before (pinned by the
existing suites). Malformed/interrupted fragments keep their agent-loop behaviour (the loop
already refuses them); on direct
Toolkitpaths they now return an ERROR result instead ofpossibly executing from the merged input — the same refusal the loop applies.
when schema validation rejects the
{}fallback (tools without required constraints keepexecuting from the input map); a dedicated "arguments could not be serialized" reason is left
as a follow-up.
Known residual (deliberately out of scope)
content(raw JSON text) andinput(parsed map) remain two representations on a toolcall. First-party adapters keep them consistent, and this PR removes the one divergence the
framework itself created (the fabricated
"{}"). But the accumulator's pre-existing mergerule (streamed content fragments only fill keys missing from the input map, and the raw text
is kept as content) means a provider emitting both representations with conflicting
values still yields a block where content-first consumers (validation, replay, compaction)
see one value while execution merges the other. Unifying the representations (e.g. content ≡
serialized input at accumulation time) trades away raw-payload replay fidelity and changes
persisted state — a contract decision left out of this PR on purpose.
empty-object-with-args predicate) is fix(agent): validate tool input before the permission gate #3321's track; with this PR's resolver change the two
converge on the same outcome and do not conflict.
Tests
Sixteen new cases. The core ones were red-verified against pre-fix code — verbatim failure
output:
testInputOnlyCompleteBlockSerializesInputAsContenttestUnserializableInputFallsBackToEmptyObjectContent"{}"and the input map stays available to a call that passes schema validationtestTruncatedInputOnlyBlockWithArgsIsNotMalformedtruncated=true) after the parsed input arrived complete leaves the call unmarked and executable — truncation alone is not malformationtestTruncatedInputOnlyBlockWithoutArgsIsMalformedtestNoArgInputOnlyBlockStaysUnmarked"{}"content, no markertestEmptyObjectContentWithArgsFallsBackToInput"{}"and arguments are present (legacy/directly constructed blocks)testWhitespaceEmptyObjectContentWithArgsFallsBackToInput"{ \n }") fall back to the input too — the predicate is structural, not a literaltestEmptyObjectContentWithoutArgsStaysEmpty"{}"testMalformedBlockKeepsContentDespiteInputtestMalformedBlockWithoutUsableContentResolvesEmpty"{}"(never invalid JSON, never the merged input)testMalformedBlockWithValidContentKeepsContentinputOnlySingleChunkToolCallWithRequiredArgsExecutesrequired: ["query"]called via a single-chunk input-only response executes successfully and receives the argument (search:alpha), instead of a validation rejectionunserializableInputCompletesTurnWithRecoverableErrorResultAgentEndEvent, and a pairedToolResultEndEventforc1exists with stateERRORand the same id in the contextshouldNotExecuteMalformedCallWithPartialInputToolkit.callTool(no agent-loop malformed filter), a truncated call whose merged input looks complete is refused instead of executed — red-verified pre-guard (not executed from merged input: 30); the error message pins the guard (not schema validation) as the rejecting layershouldNotExecuteMalformedCallWithBlankContentToolkitpaths (content sanitizes to"{}"; no fall-back to the merged input); message-pinned to the guard as wellshouldNotExecuteMalformedCallWithValidContentlooks complete: 30 ==> expected: <ERROR> but was: <RUNNING>)The existing malformed/interrupted-content tests (
"{}"+ empty input, malformed markers) and theresolver's null/empty/invalid-content fallback tests stay green unchanged, pinning that only the
fabricated-empty-object path changed.
Regression: full
agentscope-coresuite — 2963 tests, 0 failures, 8 pre-existing skips;spotless:checkclean.