Skip to content

Stabilize ResponseContinuationToken / background-response APIs#7512

Merged
jozkee merged 4 commits into
mainfrom
dacantu/rct-stabilization
May 7, 2026
Merged

Stabilize ResponseContinuationToken / background-response APIs#7512
jozkee merged 4 commits into
mainfrom
dacantu/rct-stabilization

Conversation

@jozkee
Copy link
Copy Markdown
Member

@jozkee jozkee commented May 6, 2026

Microsoft Reviewers: Open in CodeFlow

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@jozkee jozkee requested review from ericstj and jeffhandley May 6, 2026 05:21
@jozkee jozkee requested a review from a team as a code owner May 6, 2026 05:21
Copilot AI review requested due to automatic review settings May 6, 2026 05:21
@jozkee jozkee requested a review from a team as a code owner May 6, 2026 05:21
@github-actions github-actions Bot added the area-ai Microsoft.Extensions.AI libraries label May 6, 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

This PR stabilizes the background-response continuation token surface area in Microsoft.Extensions.AI.Abstractions by removing the experimental gating and updating tests/metadata to reflect the now-stable API.

Changes:

  • Removes Experimental annotations (and the associated diagnostic ID) from ResponseContinuationToken and background-response related properties.
  • Promotes ContinuationToken / AllowBackgroundResponses properties to be the directly-serialized public properties (removing the prior *Core indirection pattern).
  • Updates stabilization and unit tests to validate JSON roundtripping using AIJsonUtilities.DefaultOptions, and marks API stages as Stable in the API metadata JSON.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated no comments.

Show a summary per file
File Description
test/Libraries/Microsoft.Extensions.AI.Stabilization.Tests/Microsoft.Extensions.AI.Stabilization.Tests.csproj Adds the continuation-token test to the stabilization test suite.
test/Libraries/Microsoft.Extensions.AI.Abstractions.Tests/ResponseContinuationTokenTests.cs Updates JSON roundtrip test to use AIJsonUtilities.DefaultOptions for serialization/deserialization.
src/Shared/DiagnosticIds/DiagnosticIds.cs Removes the unused experiment ID entry for response continuations.
src/Libraries/Microsoft.Extensions.AI.OpenAI/ResponsesClientContinuationToken.cs Removes experimental annotation/imports in line with stabilization.
src/Libraries/Microsoft.Extensions.AI.Abstractions/ResponseContinuationToken.cs Removes experimental annotation/imports to make the token type stable.
src/Libraries/Microsoft.Extensions.AI.Abstractions/Microsoft.Extensions.AI.Abstractions.json Marks ResponseContinuationToken and related background-response members as Stable.
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponseUpdate.cs Makes ContinuationToken the public JSON-included property (removes prior wrapper + core split).
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatResponse.cs Same stabilization pattern for ChatResponse.ContinuationToken.
src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatOptions.cs Same stabilization pattern for ChatOptions.AllowBackgroundResponses and ChatOptions.ContinuationToken.

@jozkee
Copy link
Copy Markdown
Member Author

jozkee commented May 6, 2026

The canonical way to drive a background response is still:

var chatOptions = new ChatOptions { AllowBackgroundResponses = true };

// Get initial response with continuation token
var response = await ChatClient.GetResponseAsync("What's the biggest animal?", chatOptions);

// Continue to poll until we get the final response
while (response.ContinuationToken is not null)
{
   chatOptions.ContinuationToken = response.ContinuationToken;
   response = await ChatClient.GetResponseAsync([], chatOptions);
   await Task.Delay(1000);
}

Anything other than [] throws InvalidOperationException "Messages are not allowed when continuing a background response using a continuation token.". So, every consumer has to know the empty-list convention.
Worth considering a small extension pair to express the intent better:

 public static Task<ChatResponse> ContinueResponseAsync(
     this IChatClient client, ChatOptions options, CancellationToken cancellationToken = default);
 public static IAsyncEnumerable<ChatResponseUpdate> ContinueStreamingResponseAsync(
     this IChatClient client, ChatOptions options, CancellationToken cancellationToken = default);

As of today, only OpenAI Responses honors continuation, so it's a small surface bloat for a single-provider feature.
Also, there's currently no way to cancel the response.
Thoughts?

@jozkee
Copy link
Copy Markdown
Member Author

jozkee commented May 6, 2026

@SergeyMenshykh thanks, I agree with adding them at a later stage if necessary.

Comment thread src/Libraries/Microsoft.Extensions.AI.Abstractions/ChatCompletion/ChatOptions.cs Outdated
Agent-Logs-Url: https://github.com/dotnet/extensions/sessions/9ce4ad36-d6d2-4c9a-8020-7ec92eae60f2

Co-authored-by: jozkee <16040868+jozkee@users.noreply.github.com>
Copilot finished work on behalf of jozkee May 6, 2026 23:28
Copy link
Copy Markdown
Member

@tarekgh tarekgh left a comment

Choose a reason for hiding this comment

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

LGTM!

@jozkee jozkee merged commit 40f805f into main May 7, 2026
6 checks passed
@jozkee jozkee deleted the dacantu/rct-stabilization branch May 7, 2026 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area-ai Microsoft.Extensions.AI libraries

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants