Skip to content

[Bug]: AG-UI document tool results lose failure state and duplicate error diagnostics #4035

Done

Description

@pengmoubuaixuexi

Describe the bug

Failed tool results containing a document but no non-blank text lose their failure state when converted to AG-UI and back. A document-only ToolResultBlock with state=ERROR is emitted with error=""; after a real JSON round trip, toMsg restores it as SUCCESS.

There is a second failure in the same structured-content round trip: if a document result already includes an error diagnostic as text, toMsg unconditionally prepends the identical error again. Repeated history conversion duplicates the diagnostic.

To Reproduce

On current main 85fa9a60257ceb1570e6a195d0588ceba1e8a8c2 (2.1.0-SNAPSHOT), with agentscope-extensions-agui:

var converter = new AguiMessageConverter();
var document = DocumentBlock.builder()
        .id("doc-report")
        .name("report.pdf")
        .mimeType("application/pdf")
        .source(new URLSource("https://example.com/report.pdf", "application/pdf"))
        .build();
var result = ToolResultBlock.builder()
        .id("tc-document")
        .state(ToolResultState.ERROR)
        .output(document)
        .build();
var original = Msg.builder().role(MsgRole.TOOL).content(result).build();
var wire = converter.toAguiMessages(original).get(0);
var json = JsonUtils.getJsonCodec().toJson(wire);
var parsed = JsonUtils.getJsonCodec().fromJson(json, AguiMessage.class);
var restored = converter.toMsg(parsed).getFirstContentBlock(ToolResultBlock.class);
System.out.println(wire.getError());     // empty string
System.out.println(restored.getState()); // SUCCESS, expected ERROR

The same loss occurs with Base64 and provider-file document sources, blank-only diagnostic text, and a failed result expanded alongside a successful result by toAguiMessageList.

For the duplicate case, use output [TextBlock("document extraction failed"), document] with state ERROR. The first JSON round trip already restores two identical diagnostic text blocks instead of one.

Expected behavior

  • Document-bearing failed results remain ERROR, including when no textual diagnostic is supplied.
  • Preserve the document's source and tool-call ID.
  • Keep an existing error diagnostic once across repeated structured-content round trips; retain distinct frontend error text.
  • Successful document results remain successful.

Error messages / evidence

A new offline regression class exercises the public converter plus JSON serialization/deserialization. On unchanged production code: 10 tests, 6 failures, 0 errors, 0 skipped. Failures include expected: <ERROR> but was: <SUCCESS> and a diagnostic containing document extraction failed twice. The three source variants with SUCCESS and a distinct-error control pass.

Environment

  • AgentScope Java: 2.1.0-SNAPSHOT, main 85fa9a60257ceb1570e6a195d0588ceba1e8a8c2.
  • Windows, Temurin Java 17.0.15, Maven 3.9.12; UTF-8.
  • No model API, frontend, external document download or credentials needed. Stable 2.0.4 was not tested.

Additional context / root cause

The structured document/tool conversion added in #3979 reaches AguiMessageConverter.toolResultMessage, which derives error only from plain text. toMsg interprets a blank error as SUCCESS and independently prepends every non-blank error without checking existing structured text. The older fix #3932 covers plain-text tool results; these failures exercise the newly added structured-document path.

I have reproduced this and prepared a focused fix and regression tests, and am completing the remaining checks before submitting the linked PR. I will handle the implementation; please assign this issue to me if useful.

AI assistance was used for investigation, implementation and test preparation. The stated reproduction was executed locally.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions