-
Notifications
You must be signed in to change notification settings - Fork 798
.NET: support agentThread management in OpenAI Responses #2282
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
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 adds thread management support to the OpenAI Responses hosting layer, enabling conversation state to persist across agent invocations. The implementation mirrors the existing A2A hosting pattern by integrating AgentThreadStore to save and restore thread state based on conversation IDs.
- Introduces
IsNewConversationtracking inIdGeneratorandAgentInvocationContext - Implements thread retrieval and persistence in
HostedAgentResponseExecutor - Removes
ConversationIdfromChatOptionsas thread management now handles conversation tracking
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/HostedAgentResponseExecutor.cs | Implements thread management by retrieving threads from AgentThreadStore for existing conversations and saving them after agent execution |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/AgentInvocationContext.cs | Adds IsNewConversation property to expose new conversation detection from the underlying IdGenerator |
| dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/IdGenerator.cs | Adds IsNewConversation boolean property that tracks whether a conversation ID was provided or generated, enabling detection of new vs. existing conversations |
Comments suppressed due to low confidence (1)
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/HostedAgentResponseExecutor.cs:92
- The
ConversationIdproperty has been removed fromChatOptions, but it's still being set inAIAgentResponseExecutor.cs(line 39). This creates an inconsistency between the two executor implementations.
If the removal is intentional because thread management now handles conversation tracking via the thread parameter, consider:
- Documenting why it was removed in a comment
- Ensuring
AIAgentResponseExecutorfollows the same pattern if applicable - Verifying that downstream code doesn't rely on
ChatOptions.ConversationId
If the removal is not intentional, it should be restored:
var chatOptions = new ChatOptions
{
ConversationId = conversationId,
Temperature = (float?)request.Temperature,
// ...
}; var chatOptions = new ChatOptions
{
Temperature = (float?)request.Temperature,
TopP = (float?)request.TopP,
MaxOutputTokens = request.MaxOutputTokens,
Instructions = request.Instructions,
ModelId = request.Model,
};
dotnet/src/Microsoft.Agents.AI.Hosting.OpenAI/Responses/HostedAgentResponseExecutor.cs
Show resolved
Hide resolved
| var agent = this._serviceProvider.GetRequiredKeyedService<AIAgent>(agentName); | ||
| var threadStore = this._serviceProvider.GetKeyedService<AgentThreadStore>(agent.Name); |
Copilot
AI
Nov 17, 2025
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.
The variable declaration uses var instead of an explicit type. According to the C# Sample Code Guidelines (CodingGuidelineID: 1000000), you should "Prefer defining variables using types rather than var, to help users understand the types involved."
Consider changing to:
AIAgent agent = this._serviceProvider.GetRequiredKeyedService<AIAgent>(agentName);
AgentThreadStore? threadStore = this._serviceProvider.GetKeyedService<AgentThreadStore>(agent.Name);
Adds the code to restore and save thread accross the agent invocation
Contribution Checklist