-
Notifications
You must be signed in to change notification settings - Fork 883
.NET: [Breaking] Prevent loss of input messages & streamed updates when resuming streaming #2748
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…e able to use them in the last successful stream resumption call.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR introduces the ChatClientAgentContinuationToken type to prevent loss of input messages and streamed updates when resuming streaming operations in ChatClientAgent. The new token wraps the underlying chat client's continuation token and stores input messages from the initial call and all streamed updates received during stream-resumption calls.
Key Changes
- New
ChatClientAgentContinuationTokenclass that extendsResponseContinuationTokento preserve input messages and response updates across streaming resumptions - Updated
ChatClientAgentto wrap continuation tokens and restore input messages/updates when resuming streams - Refactored validation logic to distinguish between streaming resumption and polling scenarios
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
ChatClientAgentContinuationToken.cs |
Implements new continuation token type with serialization support for input messages and response updates |
ChatClientAgent.cs |
Updates streaming logic to wrap/unwrap continuation tokens and restore messages/updates when resuming |
ChatClientAgentStructuredOutput.cs |
Wraps continuation tokens in structured output responses |
AgentRunResponse.cs |
Removes automatic propagation of continuation tokens from ChatResponse constructor |
AgentRunResponseUpdate.cs |
Removes automatic propagation of continuation tokens from ChatResponseUpdate constructor |
ChatClientAgent_BackgroundResponsesTests.cs |
Updates tests to use new token type and adds comprehensive tests for streaming resumption scenarios |
ChatClientAgentContinuationTokenTests.cs |
New test file with serialization and roundtrip tests for the new token type |
AgentRunResponseUpdateTests.cs |
Removes test assertions for automatic continuation token propagation |
AgentRunResponseTests.cs |
Removes test assertions for automatic continuation token propagation |
AgentJsonUtilities.cs |
Adds JSON serialization support for ChatMessage and ChatResponseUpdate collections |
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentContinuationToken.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentContinuationToken.cs
Outdated
Show resolved
Hide resolved
...t/tests/Microsoft.Agents.AI.UnitTests/ChatClient/ChatClientAgent_BackgroundResponsesTests.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentContinuationToken.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentContinuationToken.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentContinuationToken.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentContinuationToken.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI/ChatClient/ChatClientAgentContinuationToken.cs
Outdated
Show resolved
Hide resolved
…nuationToken.cs Co-authored-by: Copilot <[email protected]>
…nuationToken.cs Co-authored-by: Copilot <[email protected]>
…ntAgent_BackgroundResponsesTests.cs Co-authored-by: Copilot <[email protected]>
…nuationToken.cs Co-authored-by: Copilot <[email protected]>
…nuationToken.cs Co-authored-by: Copilot <[email protected]>
Context:
Description:
This PR adds the
ChatClientAgentContinuationTokentoken type forChatClientAgent. This token type retains the agent's input messages provided during the initial call of theRunStreamingAsyncmethod, as well as the streamed updates received through all subsequent stream-resumption calls of the method.ChatClientAgentwraps all continuation tokens received from the chat client into the new token type, and it adds both input messages and streamed updates to the token before returning it as part of the response update to the caller. Upon receiving the token back from the caller via run options, the agent retrieves the input messages and updates from the token and provides them to the configured message store and AI context provider.