Skip to content

fix(core): stop empty-object tool-call content from masking intact parsed arguments - #3886

Merged
juruoO-o merged 1 commit into
agentscope-ai:mainfrom
birdie7761:fix/input-only-tool-call-arguments
Nov 11, 2026
Merged

juruoO-o merged 1 commit into
agentscope-ai:mainfrom
birdie7761:fix/input-only-tool-call-arguments

Conversation

@birdie7761

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.1.0-SNAPSHOT (based on main @ e190a8d1b)

Description

ToolCallsAccumulator fabricated content = "{}" whenever a tool call arrived without streamed
argument fragments
— the shape produced by providers and custom Model implementations that
emit the complete call in one chunk with the parsed input only (the in-repo e2e fixtures
themselves construct exactly this shape). The intact input map survived beside the fabricated
content, but every content-first consumer of JsonUtils.resolveToolCallArgsJson resolved the
arguments to {} — the empty object is valid JSON, so the resolver's existing fallbacks
(null/empty/invalid content) never fired:

  • Required-parameter validation (ToolExecutor) rejected the call before execution — any tool
    declaring required parameters was 100% rejected on this path, with the model told to "correct"
    arguments it had actually supplied;
  • Request builders (e.g. the OpenAI message converter) replayed the assistant's tool call to
    the provider with empty arguments, so later turns showed the model a call it never made;
  • Compaction serialized the same empty arguments into summaries.

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:

  1. Source — the accumulator serializes the parsed arguments instead of fabricating an empty
    object (toJsonFallbackEmptyObject, the shared guarded entry point also used for input
    serialization; a serialization failure falls back to "{}" instead of failing the reply
    stream). 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 "{}".
  2. Resolution — resolveToolCallArgsJson no longer lets an empty-object content mask intact
    parsed 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 already
    persisted
    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.
  3. Malformed-argument blocks (truncated/corrupt raw content, marked by the accumulator) are
    exempt from the input recovery in both the resolver and the executor:
    resolveToolCallArgsJson keeps their content when it is valid JSON and sanitizes
    null/empty/invalid content to "{}" — never the merged input, never invalid JSON; and
    ToolExecutor (the single funnel behind direct Toolkit.callTool paths) now refuses any
    malformed-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

  • Behavior change is confined to blocks that carried a fabricated "{}" while a non-empty
    input 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 Toolkit paths they now return an ERROR result instead of
    possibly executing from the merged input — the same refusal the loop applies.
  • A serialization failure still surfaces to the model as the generic parameter-correction message
    when schema validation rejects the {} fallback (tools without required constraints keep
    executing from the input map); a dedicated "arguments could not be serialized" reason is left
    as a follow-up.
  • No public signatures, serialized state formats, or event payloads change.

Known residual (deliberately out of scope)

  • content (raw JSON text) and input (parsed map) remain two representations on a tool
    call. 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 merge
    rule (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.
  • Executor-side schema validation ahead of the permission gate (including the same
    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.
  • A serialization failure does not yet produce a dedicated failure reason/marker (see above).

Tests

Sixteen new cases. The core ones were red-verified against pre-fix code — verbatim failure
output:

ToolCallsAccumulatorTest.testInputOnlyCompleteBlockSerializesInputAsContent:367
  content: {} ==> expected: <true> but was: <false>
JsonUtilsTest.testEmptyObjectContentWithArgsFallsBackToInput
  result: {} ==> expected: <true> but was: <false>
ReActAgentNewLoopE2ETest.inputOnlySingleChunkToolCallWithRequiredArgsExecutes
  (ToolResultEndEvent state: expected SUCCESS but was ERROR — parameter validation failed)
ToolExecutorTest.shouldNotExecuteMalformedCallWithValidContent:200
  malformed calls must not execute even when the merged input looks complete: 30
  ==> expected: <ERROR> but was: <RUNNING>
Test Asserts
testInputOnlyCompleteBlockSerializesInputAsContent a single-chunk input-only block builds with content carrying the parsed arguments (valid JSON containing them) and the input map preserved
testUnserializableInputFallsBackToEmptyObjectContent an unserializable input value never throws out of the accumulator: content falls back to "{}" and the input map stays available to a call that passes schema validation
testTruncatedInputOnlyBlockWithArgsIsNotMalformed an output-limit stop (truncated=true) after the parsed input arrived complete leaves the call unmarked and executable — truncation alone is not malformation
testTruncatedInputOnlyBlockWithoutArgsIsMalformed an output-limit stop on an argument-less input-only start cannot establish a complete no-arg call, so the malformed marker is set
testNoArgInputOnlyBlockStaysUnmarked the other matrix cell: no fragments and no arguments on a completed stream is a legitimate no-arg call — "{}" content, no marker
testEmptyObjectContentWithArgsFallsBackToInput the resolver uses the input when the content is exactly "{}" and arguments are present (legacy/directly constructed blocks)
testWhitespaceEmptyObjectContentWithArgsFallsBackToInput whitespace-padded empty objects ("{ \n }") fall back to the input too — the predicate is structural, not a literal
testEmptyObjectContentWithoutArgsStaysEmpty an empty-object content with an empty input still resolves to "{}"
testMalformedBlockKeepsContentDespiteInput malformed-argument blocks keep their content even with a non-empty input — the merged input must not leak through
testMalformedBlockWithoutUsableContentResolvesEmpty malformed blocks with null, empty, or invalid content resolve to "{}" (never invalid JSON, never the merged input)
testMalformedBlockWithValidContentKeepsContent malformed blocks with valid non-empty content keep that content — replay/compaction see the raw payload; the marker blocks execution, it does not rewrite history
inputOnlySingleChunkToolCallWithRequiredArgsExecutes through the full ReAct loop, a tool with required: ["query"] called via a single-chunk input-only response executes successfully and receives the argument (search:alpha), instead of a validation rejection
unserializableInputCompletesTurnWithRecoverableErrorResult an unserializable input does not fail the reply stream: the turn ends with AgentEndEvent, and a paired ToolResultEndEvent for c1 exists with state ERROR and the same id in the context
shouldNotExecuteMalformedCallWithPartialInput through a direct Toolkit.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 layer
shouldNotExecuteMalformedCallWithBlankContent a malformed marker with no usable content is also refused on direct Toolkit paths (content sanitizes to "{}"; no fall-back to the merged input); message-pinned to the guard as well
shouldNotExecuteMalformedCallWithValidContent a malformed marker whose content and merged input are both complete and schema-valid is still refused before validation — red-verified pre-guard (looks complete: 30 ==> expected: <ERROR> but was: <RUNNING>)

The existing malformed/interrupted-content tests ("{}" + empty input, malformed markers) and the
resolver's null/empty/invalid-content fallback tests stay green unchanged, pinning that only the
fabricated-empty-object path changed.

Regression: full agentscope-core suite — 2963 tests, 0 failures, 8 pre-existing skips;
spotless:check clean.

…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.
@jujn jujn added the P0 重要紧急 label Nov 3, 2026

@juruoO-o juruoO-o left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已核对 accumulator、参数解析、schema 校验和直接 Toolkit 执行入口。源头避免伪造空参数,解析层覆盖已有的 input-only/旧持久化调用,executor 继续拒绝 malformed 调用,三处改动对应实际消费路径。未发现不必要的接口破坏或阻塞问题;本轮为代码复核,未重跑全量测试。

@juruoO-o
juruoO-o merged commit 8437de1 into agentscope-ai:main Nov 11, 2026
5 checks passed
chickenlj added a commit that referenced this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

P0 重要紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants