-
Notifications
You must be signed in to change notification settings - Fork 5.1k
Implement non-streaming API for PersistentAgentsChatClient.GetResponseAsync #54602
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
This change modifies the GetResponseAsync method to use the non-streaming API from the innerClient instead of delegating to GetStreamingResponseAsync. Key changes: - GetResponseAsync now uses CreateRunAsync with stream: false - Polling loop to wait for run completion using GetRunAsync - Fetches messages using GetMessagesAsync after run completes - Handles RequiresAction status for function calls - Converts PersistentThreadMessage to ChatMessage format Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
|
@copilot I don't see implementation to handle MCP results neither CodeInterpreterResults from the content similar hows is done in the streaming. Please have a look on the below samples: Code Interpreter: |
…ResponseAsync This change adds handling for CodeInterpreter and MCP tool call results in the non-streaming GetResponseAsync implementation: Key changes: - Fetch run steps after run completion using GetRunStepsAsync - For RunStepCodeInterpreterToolCall: - Extract Input and convert to CodeInterpreterToolCallContent - Extract Outputs (logs/images) and convert to CodeInterpreterToolResultContent - For RunStepMcpToolCall: - Extract Output and convert to McpServerToolResultContent This matches the behavior of the streaming implementation that processes RunStepDetailsUpdate for CodeInterpreter content. Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Addressed in commit 0324512. Added handling for:
This mirrors the behavior of the streaming implementation that handles |
|
@copilot Both GetResponse and GetResponseStreaming methods now share a same initial logit for thread.GetRuns and some other lines, can we improve the reusability of this implementation as best as possible to avoid duplicated code/impl. |
…on initialization logic Extract shared run initialization code into: - PreparedRunContext class: Holds prepared run state - PrepareRunContextAsync method: Gets thread ID, active run, and tool results - EnsureThreadAsync method: Creates thread if needed or cancels active run This reduces code duplication between streaming and non-streaming implementations while maintaining the same behavior. Co-authored-by: rogerbarreto <19890735+rogerbarreto@users.noreply.github.com>
Addressed in commit 968be26. Extracted the shared initialization logic into:
Both |
Description
Changes
GetResponseAsyncinPersistentAgentsChatClientto use the non-streaming API (CreateRunAsyncwithstream: false) instead of delegating toGetStreamingResponseAsync. This provides a proper non-streaming implementation that follows the SDK's standard polling pattern.Changes
GetResponseAsyncimplementation: UsesCreateRunAsync(stream: false)with polling viaGetRunAsync(500ms interval, matching SDK samples)BuildChatResponseFromRunAsynchelper: Handles run completion states:ErrorContentor throws onRunStatus.FailedFunctionCallContent/McpServerToolApprovalRequestContentonRunStatus.RequiresActionGetRunStepsAsyncto extract CodeInterpreter and MCP resultsGetMessagesAsyncon completionRunStepCodeInterpreterToolCallto produce:CodeInterpreterToolCallContentfor Python code inputCodeInterpreterToolResultContentfor outputs (logs and images)RunStepMcpToolCallto produceMcpServerToolResultContentwith tool call outputConvertThreadMessageToChatMessagehelper: ConvertsPersistentThreadMessage→ChatMessagewith annotation handling for file citations and pathsGetResponseAsyncandGetStreamingResponseAsync:PreparedRunContextclass: Holds prepared run state (RequestContext, RunOptions, ThreadId, ActiveRun, ToolOutputs, ToolApprovals)PrepareRunContextAsyncmethod: Creates RequestContext, calls CreateRunOptionsAsync, gets thread ID, finds active runsEnsureThreadAsyncmethod: Creates new thread if needed or cancels active runNote
Recorded test sessions will need updates since requests now contain
stream: falseinstead ofstream: true.This checklist is used to make sure that common guidelines for a pull request are followed.
General Guidelines
Testing Guidelines
SDK Generation Guidelines
*.csprojandAssemblyInfo.csfiles have been updated with the new version of the SDK.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.