-
Notifications
You must be signed in to change notification settings - Fork 683
.NET: reformat event sequence in OpenAI Responses hosting #1542
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
Conversation
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
Reformats the streaming response event sequence to align with the OpenAI Responses API spec by introducing additional intermediate event types and altering the emitted event order.
- Adds new streaming event model classes (content part, text delta/done, in-progress).
- Adjusts processor logic to emit the new event sequence.
- Removes prior output_item.added emission but still emits output_item.done (likely unintended).
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
| ResponseStreamEvent.cs | Adds new derived streaming event classes and updates polymorphic type registrations. |
| AIAgentResponsesProcessor.cs | Modifies streaming emission logic to use new event types and revised sequencing. |
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Model/ResponseStreamEvent.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/AIAgentResponsesProcessor.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/AIAgentResponsesProcessor.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/AIAgentResponsesProcessor.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Model/ResponseStreamEvent.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Model/ResponseStreamEvent.cs
Outdated
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Model/ResponseStreamEvent.cs
Show resolved
Hide resolved
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/Model/ResponseStreamEvent.cs
Outdated
Show resolved
Hide resolved
| using Microsoft.AspNetCore.Http.Features; | ||
| using Microsoft.Extensions.AI; | ||
| using OpenAI.Responses; | ||
| using ChatMessage = Microsoft.Extensions.AI.ChatMessage; |
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.
Why is this necessary?
| { | ||
| var sequenceNumber = 1; | ||
| var outputIndex = 1; | ||
| Dictionary<string, int> messageIdOutputIndexes = new(); |
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.
nit:
| Dictionary<string, int> messageIdOutputIndexes = new(); | |
| Dictionary<string, int> messageIdOutputIndexes = []; |
| CreatedAt = update.CreatedAt, | ||
| RawRepresentation = update.RawRepresentation | ||
| }; | ||
| var messageId = chatMessage.MessageId ?? "<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.
Why is this using "<null>"? Is that just an arbitrary sentinel to use to group together all messages without IDs?
|
This is superseded by #1550 |
|
was intended to be a quick fix for compatibility with openai responses streaming; but Reuben has already provided a stable change (see #1550); closing |
Reformatted event sequence in streaming responses as per spec example: https://platform.openai.com/docs/api-reference/responses/create