-
Notifications
You must be signed in to change notification settings - Fork 832
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 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
@dotnet-policy-service agree company="Microsoft" |
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 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.
- Adds
ResumptionToken
base class andBackgroundResponsesOptions
for continuation token support - Updates
ChatOptions
,ChatResponse
, andChatResponseUpdate
with background response properties - Implements background response functionality in
OpenAIResponsesChatClient
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
File | Description |
---|---|
ResumptionToken.cs | Introduces base class for continuation tokens with byte serialization |
BackgroundResponsesOptions.cs | Defines options for enabling background responses |
ChatOptions.cs | Adds continuation token and background response options properties |
ChatResponse.cs | Adds continuation token property for background response polling |
ChatResponseUpdate.cs | Adds continuation token property for stream resumption |
ChatClientExtensions.cs | Provides extension methods for background response operations |
OpenAIResponsesContinuationToken.cs | Implements OpenAI-specific continuation token with JSON serialization |
OpenAIResponsesChatClient.cs | Core implementation of background response support with polling and streaming |
FunctionInvokingChatClient.cs | Updates to handle continuation tokens in function calling scenarios |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesChatClient.cs
Outdated
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.AI.Integration.Tests/VerbatimHttpHandler.cs
Outdated
Show resolved
Hide resolved
test/Libraries/Microsoft.Extensions.AI.OpenAI.Tests/OpenAIResponseClientTests.cs
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/BackgroundResponsesOptions.cs
Outdated
Show resolved
Hide resolved
/// This property only takes effect if the API it's used with supports background responses. | ||
/// If the API does not support background responses, this property will be ignored. | ||
/// </remarks> | ||
public bool? Allow { get; set; } |
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.
Should it be Enabled instead of Allow?
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.
It could be, though there is an opinion that it may mislead consumers into thinking that setting that property should enable or disable background responses. In reality, it may not have any effect because the chat client implementation may not support background responses, or the underlying SDK does not allow for controlling the behavior. Allow
is more permissive than Enable
and is intended to communicate that it can enable or disable the feature if supported; otherwise, it will have no effect. On the other hand, the Enable
semantic presumes that the values should be respected once set.
src/Libraries/Microsoft.Extensions.AI.Abstractions/BackgroundResponsesOptions.cs
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.Abstractions/CHANGELOG.md
Outdated
Show resolved
Hide resolved
public static Task<ChatResponse> GetResponseAsync( | ||
this IChatClient client, | ||
ResumptionToken continuationToken, | ||
ChatOptions? options = null, |
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.
What is the purpose of the options being accepted here?
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.
Good question. We need to supply functions for subsequent calls if they were advertised in the initial call; otherwise, the called tools won't be found by FICC.
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesContinuationToken.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesContinuationToken.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesContinuationToken.cs
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI.OpenAI/OpenAIResponsesContinuationToken.cs
Outdated
Show resolved
Hide resolved
src/Libraries/Microsoft.Extensions.AI/Microsoft.Extensions.AI.csproj
Outdated
Show resolved
Hide resolved
…atClient.cs Co-authored-by: Copilot <[email protected]>
…ntinuationToken.cs Co-authored-by: Stephen Toub <[email protected]>
…ykh/extensions into background-responses
…gs in code generators.
…ykh/extensions into background-responses
This PR adds a model for supporting background responses (long-running operations), updates the chat completion model to use it, and integrates this functionality into
OpenAIResponsesChatClient
.Background responses use a continuation token returned by the
GetResponseAsync
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-streaming
GetResponseAsync
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:
Streaming API:
Microsoft Reviewers: Open in CodeFlow
CC: @westey-m