Skip to content

.NET: [Bug]: AGUI client crashes on non-JSON TOOL_CALL_RESULT content from handoff with JsonException ('T' is an invalid start of a value) #5587

Closed

Description

Description

I’m seeing a crash in AGUI streaming when a workflow handoff emits a TOOL_CALL_RESULT with plain text content.

Environment

  1. Microsoft Agent Framework (latest main as of 2026-04-30)
  2. AGUI client via AGUIChatClient
  3. Workflow built with handoff builder and exposed via AGUI endpoint

Repro

  1. Build workflow with handoff orchestration.
  2. Consume endpoint with AGUIChatClient.
  3. Call RunStreamingAsync.
  4. Observe AGUI SSE events:
  • RUN_STARTED
  • TOOL_CALL_START (handoff_to_1)
  • TOOL_CALL_ARGS
  • TOOL_CALL_END
  • TOOL_CALL_RESULT with content: Transferred.

Actual
Client throws:
System.Text.Json.JsonException: 'T' is an invalid start of a value
at ChatResponseUpdateAGUIExtensions.DeserializeResultIfAvailable(ToolCallResultEvent ...)

Expected
Non-JSON tool result content should not crash deserialization.
Either:

treat content as raw string result, or
deserialize as JsonElement only when content is valid JSON.
Root cause candidate
In ChatResponseUpdateAGUIExtensions:

SerializeResultContent returns raw string for FunctionResultContent strings.
DeserializeResultIfAvailable always attempts JsonSerializer.Deserialize(... JsonElement ...) for non-empty content.
This fails for plain text like Transferred.
Suggested fix
Fallback to raw string when JsonElement deserialization fails.

Code Sample

Error Messages / Stack Traces

Package Versions

Microsoft.Agents.AI.AGUI: 1.3.0-preview.260423.1

.NET Version

NET 10.0

Additional Context

No response

Activity

  1. added
    bugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)
    .NETUsage: [Issues, PRs], Target: .Net
    on Apr 30, 2026
  2. added and removed
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on May 4, 2026
  3. awaescher commented on May 4, 2026

    @awaescher

    Seems to be related:

    This missing function exception ...

    "Error: Requested function \"ExecuteFormAction\" not found."
    

    ... gets hidden by this follow up exception:

    System.Text.Json.JsonReaderException: ''E' is an invalid start of a value. LineNumber: 0 | BytePositionInLine: 0.'
    
    Image
    Image
  4. max-meng1 commented on May 20, 2026

    @max-meng1
    <PackageReference Include="Microsoft.Agents.AI.Hosting.AGUI.AspNetCore" Version="1.0.0-preview.251125.1" />
    
    message	{"threadId":"thread_0431523053504a11b04bbd6fd50ed360","runId":"run_9a5e473fdc8c4fdbb7b61e6056c07478","type":"RUN_STARTED"}
    message	{"toolCallId":"call_oHFqbbIQTM5N6qEiy7WGsVnb","toolCallName":"GetRecordingFields","parentMessageId":"chatcmpl-DhOeiwRS1QsVvSGhHbvlfvX2KRIAI","type":"TOOL_CALL_START"}	
    message	{"toolCallId":"call_oHFqbbIQTM5N6qEiy7WGsVnb","delta":"{}","type":"TOOL_CALL_ARGS"}	
    message	{"toolCallId":"call_oHFqbbIQTM5N6qEiy7WGsVnb","type":"TOOL_CALL_END"}
    message	{"threadId":"thread_0431523053504a11b04bbd6fd50ed360","runId":"run_9a5e473fdc8c4fdbb7b61e6056c07478","result":null,"type":"RUN_FINISHED"}
    
    /*Failed*/
    <PackageReference Include="Microsoft.Agents.AI.Hosting.AGUI.AspNetCore" Version="1.6.1-preview.260514.1" />
    
    message	{"threadId":"thread_d87185f9bab54954913eafdc0c5243d8","runId":"run_e27e114213174f638c11de78f1ec4ae8","type":"RUN_STARTED"}	
    message	{"toolCallId":"call_rGsqLxDT6Hud5ophOVfmIirV","toolCallName":"GetRecordingFields","parentMessageId":"chatcmpl-DhOoT2W5d3zcxh3DEuTGr6rSQfgzU","type":"TOOL_CALL_START"}	
    message	{"toolCallId":"call_rGsqLxDT6Hud5ophOVfmIirV","delta":"{}","type":"TOOL_CALL_ARGS"}	
    message	{"toolCallId":"call_rGsqLxDT6Hud5ophOVfmIirV","type":"TOOL_CALL_END"}	
    message	{"messageId":"ffa3714dd6e04ab899e3155258023886","toolCallId":"call_rGsqLxDT6Hud5ophOVfmIirV","content":"Success: Function completed.","role":"tool","type":"TOOL_CALL_RESULT"}	
    

    Same issue, there is an extra message TOOL_CALL_RESULT after TOOL_CALL_END, after upgrade the package.

  5. javiercn commented on Aug 18, 2026

    @javiercn
    Contributor

    This issue is resolved by the current AGUI.Client implementation.

    The former converter serialized string tool results as plain text but then unconditionally attempted to deserialize that text as a JsonElement. Values such as "Transferred." or "Success: Function completed." therefore failed at their first non-JSON character.

    The current SDK passes ToolCallResultEvent.Content directly into FunctionResultContent:

    new FunctionResultContent(
        toolResult.ToolCallId,
        toolResult.Content);

    We exercised plain text, JSON-looking text, empty text, and null results. Plain-text results were returned as strings without exceptions in repeated runs. JSON-looking results are also preserved as strings; consumers that require a JSON DOM should parse them explicitly.

    Applications should use AGUI.Client instead of the removed Microsoft.Agents.AI.AGUI package. Since the failing conversion path has been replaced and the reported scenario now succeeds, this issue can be closed as resolved.

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

Metadata

Metadata

Labels

.NETUsage: [Issues, PRs], Target: .Netag-uiUsage: [Issues, PRs], Target: AG-UI protocol integrationbugUsage: [Issues], Target: all issues (Legacy, prefer issue type: bug)

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions