Add IHostedConversationClient abstraction for hosted conversation lifecycle management#7393
Draft
rogerbarreto wants to merge 1 commit intodotnet:mainfrom
Draft
Add IHostedConversationClient abstraction for hosted conversation lifecycle management#7393rogerbarreto wants to merge 1 commit intodotnet:mainfrom
rogerbarreto wants to merge 1 commit intodotnet:mainfrom
Conversation
…ecycle management Adds a new IHostedConversationClient interface for managing server-side conversations (create, get, delete, add messages, list messages), with full middleware stack (logging, OpenTelemetry, ConfigureOptions, builder, DI registration) and OpenAI implementation wrapping ConversationClient. Key components: - IHostedConversationClient interface with 5 CRUD operations + GetService - HostedConversation, HostedConversationCreationOptions, metadata types - DelegatingHostedConversationClient for middleware chains - HostedConversationClientBuilder with Use()/Build() pipeline - LoggingHostedConversationClient, OpenTelemetryHostedConversationClient, ConfigureOptionsHostedConversationClient middleware - HostedConversationChatClient bridge enabling chatClient.GetService<IHostedConversationClient>() via UseHostedConversations() builder extension - OpenAIHostedConversationClient wrapping OpenAI Conversations API - RawRepresentation/RawRepresentationFactory escape hatches - Provider mapping report documenting OpenAI, Azure, Bedrock, Gemini, Anthropic, and Ollama support with gap analysis - 63 unit tests across abstractions, middleware, and OpenAI layers
qubitron
reviewed
Mar 13, 2026
| ### Azure AI Foundry | ||
|
|
||
| - Maps to Thread/Message APIs in Agent Service SDK | ||
| - `CreateAsync` → `threads.create()` |
There was a problem hiding this comment.
threads is agents v1, which is now deprecated -- don't recommend adding support for this one
for agents v2, we use openai
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add
IHostedConversationClientabstraction for hosted conversation lifecycle managementSummary
Adds a new
IHostedConversationClientinterface toMicrosoft.Extensions.AIfor managing server-side hosted conversations (create, get, delete, add messages, list messages). This is complementary toIChatClient— theConversationIdreturned by this client feeds intoChatOptions.ConversationIdfor inference.Includes the full middleware stack (logging, OpenTelemetry, ConfigureOptions, builder, DI registration), an OpenAI implementation wrapping
ConversationClient, and aUseHostedConversations()ChatClient builder extension that enableschatClient.GetService<IHostedConversationClient>().Components
Microsoft.Extensions.AI.Abstractions (6 files):
IHostedConversationClient— 5 CRUD operations (CreateAsync,GetAsync,DeleteAsync,AddMessagesAsync,GetMessagesAsync) +GetServiceHostedConversation— Response type withConversationId,CreatedAt,Metadata,RawRepresentation,AdditionalPropertiesHostedConversationCreationOptions— Options withMetadata,Messages,RawRepresentationFactory,Clone()HostedConversationClientMetadata—ProviderName,ProviderUriDelegatingHostedConversationClient— Base class for middleware chainsHostedConversationClientExtensions—GetService<T>convenienceMicrosoft.Extensions.AI (10 files):
HostedConversationClientBuilder—Use()/Build()pipeline builderLoggingHostedConversationClient— Debug/Trace level loggingOpenTelemetryHostedConversationClient— Activity spans + duration histogramConfigureOptionsHostedConversationClient— Options callback forCreateAsyncHostedConversationChatClient—DelegatingChatClientbridge enablingchatClient.GetService<IHostedConversationClient>()viaUseHostedConversations()builder extensionServiceCollectionregistrationMicrosoft.Extensions.AI.OpenAI (1 new file + 1 modified):
OpenAIHostedConversationClient— WrapsOpenAI.Conversations.ConversationClientwith protocol-level JSON APIsAsIHostedConversationClient()extension onConversationClientTests (8 files, 63 tests):
Documentation:
docs/HostedConversation-ProviderMapping.md— Provider mapping for OpenAI, Azure Foundry, AWS Bedrock, Google Gemini, Anthropic, Ollama with gap analysisUsage Example
Design Decisions
ChatMessagefor conversation items — no new message type needed[Experimental(MEAI001)]on all types — same diagnostic ID as other AI experimentsRawRepresentation/RawRepresentationFactoryescape hatches for 99.9% provider coverageUseHostedConversations()builder extension bridgesIChatClient→IHostedConversationClientdiscoveryMicrosoft Reviewers: Open in CodeFlow