IChatResponseProvider Interface
Defines a unified contract for asynchronous AI chat responses across different AI services.
Namespace: DevExpress.AIIntegration.Chat
Assembly: DevExpress.AIIntegration.v26.1.dll
NuGet Package: DevExpress.AIIntegration
Declaration
Related API Members
The following members return IChatResponseProvider objects:
Remarks
IChatResponseProvider defines a common contract that standardizes AI-powered chat response handling in DevExpress Chat controls (DxAIChat, AIChatControl). This interface enables chat components to execute AI conversations without direct dependency on a specific AI service (such as IChatClient or AIAgent).
IChatResponseProvider ensures consistent behavior across Blazor, WinForms, and WPF applications and supports both streaming and buffered execution models.
Conversation History
The chat component passes conversation data to the GetResponseAsync(IEnumerable<ChatMessage>, Boolean, String, CancellationToken) method in two parameters:
messages- The complete conversation history. The chat component always passes the complete history, even if the AI service already stores it.
conversationId- The conversation identifier returned in the last response, or
nullif the last response had no identifier.
Some AI services (for example, the OpenAI Responses API) store conversation history on their side. Such services return a conversation identifier in the ChatResponseUpdate.ConversationId property. The chat component passes this identifier to the next GetResponseAsync call. The provider can then send only new messages to the AI service instead of the complete history.
Built-in Providers
The following methods return providers that handle conversationId automatically:
- AsIChatResponseProvider(IChatClient, ChatOptions)
- If
conversationIdis specified, the provider sends only messages added after the last assistant response. The provider passes the identifier to theIChatClientin theChatOptions.ConversationIdproperty. - AsIChatResponseProvider(AIAgent, AgentSession, AgentRunOptions)
- The provider sends only new messages if
conversationIdis specified or if you pass anAgentSessionobject to the method.
Custom Providers
A custom IChatResponseProvider implementation must handle the conversation identifier itself:
- To receive an identifier in the next
GetResponseAsynccall, set theConversationIdproperty of theChatResponseUpdateobject that your implementation returns. - If
conversationIdis specified, you can send only messages added after the last assistant message to the AI service. Otherwise, send the complete history from themessagesparameter.
Custom AIContent Types
DevExpress IChatResponseProvider implementations (including the provider returned by the AsIChatResponseProvider(IChatClient, ChatOptions) method) and the DxAIChat component do not modify custom AIContent descendants. Custom content items are passed through unchanged in both directions: from the provider to the chat component and backwards.
Pass Custom Content from the Provider to the Chat
In your GetResponseAsync method implementation, add custom AIContent items to the ChatResponseUpdate.Contents collection. DxAIChat passes these items to the BlazorChatMessage.Contents collection unchanged. You can use custom templates to display these items (for example, to show source documents or model reasoning).
In the following example, SourcesContent is a custom AIContent descendant. answer and documents are data that the provider obtains from the AI service:
using System.Runtime.CompilerServices;
// ...
public async IAsyncEnumerable<ChatResponseUpdate> GetResponseAsync(
IEnumerable<ChatMessage> messages,
bool useStreaming = true,
string conversationId = null,
[EnumeratorCancellation] CancellationToken cancellationToken = default) {
// ...
yield return new ChatResponseUpdate {
Role = ChatRole.Assistant,
Contents = [new TextContent(answer), new SourcesContent(documents)],
};
}
Pass Custom Content from the Chat to the Provider
To attach custom AIContent items to a user message, handle the MessageSending event. The IChatResponseProvider receives these items unchanged in the messages collection passed to the GetResponseAsync(IEnumerable<ChatMessage>, Boolean, String, CancellationToken) method.
async Task OnMessageSending(MessageSendingEventArgs e) {
e.Cancel = true;
await e.Chat.SendMessageAsync([new TextContent(e.Text), new MyContent(5)], e.CancellationToken);
}