Skip to content

.NET: BugFix #3433 ChatClientAgent streaming responses missing messageid#4615

Merged
rogerbarreto merged 9 commits intomicrosoft:mainfrom
rogerbarreto:issues/3433-bug-chatclientagent-streaming-responses-missing-messageid
Mar 30, 2026
Merged

.NET: BugFix #3433 ChatClientAgent streaming responses missing messageid#4615
rogerbarreto merged 9 commits intomicrosoft:mainfrom
rogerbarreto:issues/3433-bug-chatclientagent-streaming-responses-missing-messageid

Conversation

@rogerbarreto
Copy link
Copy Markdown
Member

@rogerbarreto rogerbarreto self-assigned this Mar 11, 2026
Copilot AI review requested due to automatic review settings March 11, 2026 09:36
@github-actions github-actions bot changed the title .Net: BugFix #3433 ChatClientAgent streaming responses missing messageid .NET: BugFix #3433 ChatClientAgent streaming responses missing messageid Mar 11, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes .NET streaming MessageId propagation for ChatClientAgent so AGUI/CopilotKit event conversion doesn’t emit messageId: null (Issue #3433).

Changes:

  • Add fallback MessageId generation for streaming chunks when providers omit it.
  • Sync MessageId from AgentResponseUpdate back into a ChatResponseUpdate RawRepresentation during conversion.
  • Add unit tests for ChatClientAgent, AgentResponseUpdate conversion, and an AGUI pipeline coverage test.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgent.cs Adds per-stream fallback MessageId assignment for streaming updates.
dotnet/src/Microsoft.Agents.AI.Abstractions/AgentResponseExtensions.cs Ensures AsChatResponseUpdate() can recover MessageId into RawRepresentation when missing.
dotnet/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgentTests.cs Adds tests for fallback MessageId generation and preserving provider IDs.
dotnet/tests/Microsoft.Agents.AI.Abstractions.UnitTests/AgentResponseUpdateExtensionsTests.cs Adds tests verifying MessageId syncing behavior in AsChatResponseUpdate().
dotnet/tests/Microsoft.Agents.AI.AGUI.UnitTests/AGUIStreamingMessageIdTests.cs Adds an end-to-end pipeline test verifying AGUI events include non-null messageId.

rogerbarreto added a commit to rogerbarreto/agent-framework-public that referenced this pull request Mar 12, 2026
- Fix MessageId seeding: use first-seen provider MessageId (or generate
  fallback) and apply consistently to all chunks in the stream, preventing
  message splitting when providers set MessageId only on the first chunk
- Add test for mixed MessageId scenario (first chunk only)
- Fix skipped TextStreaming test: assert Empty (not NotEmpty) to match
  actual null==null behavior
- Fix skipped ToolCalls test: assert empty ParentMessageId to match
  actual empty-string passthrough behavior
rogerbarreto added a commit to rogerbarreto/agent-framework-public that referenced this pull request Mar 12, 2026
- Fix MessageId seeding: use first-seen provider MessageId (or generate
  fallback) and apply consistently to all chunks in the stream, preventing
  message splitting when providers set MessageId only on the first chunk
- Add test for mixed MessageId scenario (first chunk only)
- Fix skipped TextStreaming test: assert Empty (not NotEmpty) to match
  actual null==null behavior
- Fix skipped ToolCalls test: assert empty ParentMessageId to match
  actual empty-string passthrough behavior
Copilot AI review requested due to automatic review settings March 12, 2026 13:59
@rogerbarreto rogerbarreto force-pushed the issues/3433-bug-chatclientagent-streaming-responses-missing-messageid branch from 5facc45 to 3f3042e Compare March 12, 2026 13:59
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

rogerbarreto and others added 4 commits March 12, 2026 18:52
Generate fallback MessageId in ChatClientAgent.RunCoreStreamingAsync when
the underlying LLM provider does not set ChatResponseUpdate.MessageId.
Without a MessageId the AGUI converter's null==null check silently drops
all text content, causing CopilotKit Zod validation errors.

Changes:
- ChatClientAgent: generate msg_{Guid} fallback via ??= in streaming loop
- AgentResponseExtensions: sync wrapper MessageId back to RawRepresentation
  in AsChatResponseUpdate() so downstream consumers see the value
- Add unit tests for both fixes and AGUI streaming MessageId scenarios

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
- Fix MessageId seeding: use first-seen provider MessageId (or generate
  fallback) and apply consistently to all chunks in the stream, preventing
  message splitting when providers set MessageId only on the first chunk
- Add test for mixed MessageId scenario (first chunk only)
- Fix skipped TextStreaming test: assert Empty (not NotEmpty) to match
  actual null==null behavior
- Fix skipped ToolCalls test: assert empty ParentMessageId to match
  actual empty-string passthrough behavior
Treat empty/whitespace MessageId the same as null when syncing from
the AgentResponseUpdate wrapper back to RawRepresentation. Providers
that return empty string MessageId (e.g. tool call responses) now get
the wrapper value recovered correctly.

Add test for empty string MessageId recovery scenario.
@rogerbarreto rogerbarreto force-pushed the issues/3433-bug-chatclientagent-streaming-responses-missing-messageid branch from 3f3042e to 2b04b70 Compare March 12, 2026 19:00
Move fallback MessageId generation from ChatClientAgent to
AsAGUIEventStreamAsync, addressing the architectural concern that
MessageId is nullable in the AIAgent abstraction and the requirement
for non-null values is specific to the AGUI protocol.

The AGUI layer now generates a fallback MessageId for null or
empty/whitespace values, covering all agent types (not just
ChatClientAgent) including external implementations.

Changes:
- Revert MessageId generation from ChatClientAgent.RunCoreStreamingAsync
- Add fallback MessageId generation in AsAGUIEventStreamAsync for
  null/empty MessageId values (handles both null and whitespace)
- Unskip and update AGUI tests to verify fallback generation
- Update ChatClientAgent tests to reflect passthrough behavior
Remove the MessageId sync-back logic from AsChatResponseUpdate() as it
is no longer needed. With fallback generation moved to the AGUI layer,
the abstraction layer should not mutate the RawRepresentation object.

Revert to the original passthrough behavior for AsChatResponseUpdate()
and update tests accordingly.
@rogerbarreto rogerbarreto added this pull request to the merge queue Mar 27, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 27, 2026
@rogerbarreto rogerbarreto enabled auto-merge March 27, 2026 12:38
@rogerbarreto rogerbarreto added this pull request to the merge queue Mar 27, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 27, 2026
@rogerbarreto rogerbarreto enabled auto-merge March 30, 2026 09:37
@rogerbarreto rogerbarreto added this pull request to the merge queue Mar 30, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 30, 2026
@rogerbarreto rogerbarreto added this pull request to the merge queue Mar 30, 2026
Merged via the queue into microsoft:main with commit ca02146 Mar 30, 2026
21 checks passed
@github-project-automation github-project-automation bot moved this from In Review to Done in Agent Framework Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: ChatClientAgent streaming responses missing MessageId causing AGUI/CopilotKit validation failures

5 participants