.NET: [POC] Alternative design for AF background responses #1875
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation and Context
This PR presents a POC for an alternative design for background responses in AF. It proposes using the
RunBackgroundAsyncandRunBackgroundStreamingAsyncmethods for background responses, as well as for non-background responses, instead of theRunAsyncandRunStreamingAsyncmethods withAgentRunOptions.AllowBackgroundResponses.The reason for introducing a new pair of methods is to allow developers to explicitly call them when their code is ready to handle both background and non-background responses. The concern with the current approach, which uses
AgentRunOptions.AllowBackgroundResponses, is that in a large application, agent run options with enabled background responses can inadvertently propagate through the system and may enable background responses for agents even when the application code is not prepared to handle them, leading to potential silent errors.Pros:
Cons:
ChatClientAgent.Run{Streaming}Asyncmethods viaChatClientOptionsbut will have to be continued/resumed viaRunBackgroundStreamingAsync.ChatClientOptions.AllowBackgroundResponses.Related to: #1841