Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

add support for background responses#6854

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
stephentoub merged 61 commits intodotnet:mainfromSergeyMenshykh:background-responses
Oct 11, 2025

Conversation

@SergeyMenshykh
Copy link
Contributor

@SergeyMenshykhSergeyMenshykh commentedSep 25, 2025
edited
Loading

This PR adds a model for supporting background responses (long-running operations), updates the chat completion model to use it, and integrates this functionality intoOpenAIResponsesChatClient.

Background responses use a continuation token returned by theGetResponseAsync andGetStreamingResponseAsync methods in theChatResponse andChatResponseUpdate classes, respectively, when background responses are enabled and supported by the chat client.

The continuation token contains all necessary details to enable polling for a background response using the non-streamingGetResponseAsync method. It also allows resuming a streamed background response with theGetStreamingResponseAsync method if the stream is interrupted. In both cases, the continuation token obtained from the initial chat result or the streamed update received before the interruption should be supplied as input for follow-up calls.

When a background response has completed, failed, or cannot proceed further (for example, when user input is required), the continuation token returned by either method will be null, signaling to consumers that processing is complete and there is nothing to poll or resume. The result returned by either method can then be used for further processing.

Non-streaming API:

varchatOptions=newChatOptions{BackgroundResponsesOptions=new(){Allow=true}};// Get initial response with continuation tokenvarresponse=awaitchatClient.GetResponseAsync("What's the biggest animal?",chatOptions);// Continue to poll until the final response is receivedwhile(response.ContinuationTokenis notnull){chatOptions.ContinuationToken=response.ContinuationToken;response=awaitchatClient.GetResponseAsync([],chatOptions);}Console.WriteLine(response);

Streaming API:

ChatOptionschatOptions=new(){BackgroundResponsesOptions=newBackgroundResponsesOptions{Allow=true},};stringresponse="";ResumptionToken?continuationToken=null;awaitforeach(varupdateinchatClient.GetStreamingResponseAsync("What is the capital of France?",chatOptions)){response+=update;// Simulate an interruptioncontinuationToken=update.ContinuationToken;break;}// Resume streaming from the point captured by the continuation tokenchatOptions.ContinuationToken=continuationToken!awaitforeach(varupdateinchatClient.GetStreamingResponseAsync([],chatOptions)){response+=update;}Console.WriteLine(response);
Microsoft Reviewers:Open in CodeFlow

CC:@westey-m

@github-actionsgithub-actionsbot added the area-aiMicrosoft.Extensions.AI libraries labelSep 25, 2025
@SergeyMenshykh
Copy link
ContributorAuthor

@dotnet-policy-service agree company="Microsoft"

@SergeyMenshykhSergeyMenshykh removed their assignmentSep 26, 2025
@SergeyMenshykhSergeyMenshykh marked this pull request as ready for reviewSeptember 26, 2025 17:40
@SergeyMenshykhSergeyMenshykh requested a review froma team as acode ownerSeptember 26, 2025 17:40
CopilotAI review requested due to automatic review settingsSeptember 26, 2025 17:40
Copy link
Contributor

CopilotAI 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 introduces support for background responses (long-running operations) in the AI chat framework. The feature enables clients to initiate operations that can be polled or resumed from interruption points using continuation tokens.

  • AddsResumptionToken base class andBackgroundResponsesOptions for continuation token support
  • UpdatesChatOptions,ChatResponse, andChatResponseUpdate with background response properties
  • Implements background response functionality inOpenAIResponsesChatClient with polling and stream resumption

Reviewed Changes

Copilot reviewed 23 out of 23 changed files in this pull request and generated 3 comments.

Show a summary per file
FileDescription
ResumptionToken.csIntroduces base class for continuation tokens with byte serialization
BackgroundResponsesOptions.csDefines options for enabling background responses
ChatOptions.csAdds continuation token and background response options properties
ChatResponse.csAdds continuation token property for background response polling
ChatResponseUpdate.csAdds continuation token property for stream resumption
ChatClientExtensions.csProvides extension methods for background response operations
OpenAIResponsesContinuationToken.csImplements OpenAI-specific continuation token with JSON serialization
OpenAIResponsesChatClient.csCore implementation of background response support with polling and streaming
FunctionInvokingChatClient.csUpdates to handle continuation tokens in function calling scenarios

Tip: Customize your code reviews with copilot-instructions.md.Create the file orlearn how to get started.

SergeyMenshykhand others added18 commitsSeptember 27, 2025 10:09
…atClient.csCo-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ntinuationToken.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
SergeyMenshykhand others added11 commitsOctober 10, 2025 10:55
…ion/ChatOptions.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
…ion/ChatOptions.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
…ion/ChatResponseUpdate.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
…ion/ChatOptions.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
Co-authored-by: Stephen Toub <stoub@microsoft.com>
…tinuationToken.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
…tinuationToken.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
…tinuationToken.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
…atClient.csCo-authored-by: Stephen Toub <stoub@microsoft.com>
@stephentoubstephentoubenabled auto-merge (squash)October 10, 2025 21:27
@stephentoub
Copy link
Member

@SergeyMenshykh, why do you keep merging in main? It keeps resetting CI.

@stephentoubstephentoub merged commit1eb963e intodotnet:mainOct 11, 2025
6 checks passed
joperezr pushed a commit to joperezr/extensions that referenced this pull requestOct 14, 2025
* add support for background responsesAdds a model for supporting background responses (long-running operations), updates the chat completion model to use it, and integrates this functionality into OpenAIResponsesChatClient.---------Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>Co-authored-by: Stephen Toub <stoub@microsoft.com>Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull requestOct 21, 2025
* add support for background responsesAdds a model for supporting background responses (long-running operations), updates the chat completion model to use it, and integrates this functionality into OpenAIResponsesChatClient.---------Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>Co-authored-by: Stephen Toub <stoub@microsoft.com>Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
jeffhandley pushed a commit to jeffhandley/extensions that referenced this pull requestOct 21, 2025
* add support for background responsesAdds a model for supporting background responses (long-running operations), updates the chat completion model to use it, and integrates this functionality into OpenAIResponsesChatClient.---------Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>Co-authored-by: Stephen Toub <stoub@microsoft.com>Co-authored-by: westey <164392973+westey-m@users.noreply.github.com>
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsNov 10, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.

Reviewers

@stephentoubstephentoubstephentoub approved these changes

Copilot code reviewCopilotCopilot left review comments

+1 more reviewer

@westey-mwestey-mwestey-m left review comments

Reviewers whose approvals may not affect merge requirements

Assignees

@SergeyMenshykhSergeyMenshykh

Labels

area-aiMicrosoft.Extensions.AI libraries

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

3 participants

@SergeyMenshykh@stephentoub@westey-m

[8]ページ先頭

©2009-2025 Movatter.jp