Skip to content

Commit 2a7470a

Browse files
authored
.NET: Publish synthetic terminal responses with their events (microsoft#8885)
1 parent 4b1c231 commit 2a7470a

2 files changed

Lines changed: 397 additions & 6 deletions

File tree

‎dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/InMemoryResponsesService.cs‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -556,7 +556,7 @@ private async Task ExecuteResponseAsync(string responseId, ResponseState state,
556556
// Update response status to completed if not already in a terminal state
557557
if (!state.IsTerminal)
558558
{
559-
state.Response = state.Response! with
559+
var completedResponse = state.Response! with
560560
{
561561
Status = ResponseStatus.Completed
562562
};
@@ -565,7 +565,7 @@ private async Task ExecuteResponseAsync(string responseId, ResponseState state,
565565
var completedEvent = new StreamingResponseCompleted
566566
{
567567
SequenceNumber = sequenceNumber,
568-
Response = state.Response
568+
Response = completedResponse
569569
};
570570

571571
state.AddStreamingEvent(completedEvent);
@@ -574,7 +574,7 @@ private async Task ExecuteResponseAsync(string responseId, ResponseState state,
574574
catch (OperationCanceledException)
575575
{
576576
// Update response status to cancelled
577-
state.Response = state.Response! with
577+
var cancelledResponse = state.Response! with
578578
{
579579
Status = ResponseStatus.Cancelled
580580
};
@@ -583,15 +583,15 @@ private async Task ExecuteResponseAsync(string responseId, ResponseState state,
583583
var cancelledEvent = new StreamingResponseCancelled
584584
{
585585
SequenceNumber = sequenceNumber,
586-
Response = state.Response
586+
Response = cancelledResponse
587587
};
588588

589589
state.AddStreamingEvent(cancelledEvent);
590590
}
591591
catch (Exception ex)
592592
{
593593
// Update response status to failed
594-
state.Response = state.Response! with
594+
var failedResponse = state.Response! with
595595
{
596596
Status = ResponseStatus.Failed,
597597
Error = new ResponseError
@@ -605,7 +605,7 @@ private async Task ExecuteResponseAsync(string responseId, ResponseState state,
605605
var failedEvent = new StreamingResponseFailed
606606
{
607607
SequenceNumber = sequenceNumber,
608-
Response = state.Response
608+
Response = failedResponse
609609
};
610610

611611
state.AddStreamingEvent(failedEvent);

0 commit comments

Comments
 (0)