Manage Multiple Chat Clients
- 3 minutes to read
The WPF AI Chat Control supports multiple AI services in a single application, which enables you to compare AI providers, separate conversation contexts, and provide specialized AI assistants for different user tasks.
Register Multiple AI Services
Register multiple AI services and service providers, and distinguish them by a unique key.
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.Chat;
using DevExpress.Xpf.Core;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
using OllamaSharp;
using System;
using System.ClientModel;
using System.Windows;
namespace DXWPFMultipleChatClients {
public partial class App : Application {
static App() {
CompatibilitySettings.UseLightweightThemes = true;
// Create an Azure OpenAI chat client.
var azureOpenAiClient = new AzureOpenAIClient(AzureOpenAIEndpoint, AzureOpenAIKey)
.GetChatClient(ModelId)
.AsIChatClient();
// Create an Ollama API client.
IChatClient ollamaClient = new OllamaApiClient(
new Uri("http://localhost:11434/"),
"gemma3:4b"
);
// Create a service collection to register AI chat clients.
var serviceCollection = new ServiceCollection();
// Register a keyed IChatResponseProvider for Azure OpenAI.
// This provider is resolved when "azureAiProviderServiceKey" is specified.
serviceCollection.AddKeyedScoped<IChatResponseProvider>(
"azureAiProviderServiceKey",
(serviceProvider, _) => azureOpenAiClient.AsIChatResponseProvider()
);
// Register the Azure OpenAI chat client as a keyed IChatClient.
serviceCollection.AddKeyedScoped<IChatClient>(
"azureAiClient",
(serviceProvider, _) => azureOpenAiClient
);
// Register a keyed IChatResponseProvider for the Ollama client.
// This provider is resolved when "ollamaAiProviderServiceKey" is specified.
serviceCollection.AddKeyedScoped<IChatResponseProvider>(
"ollamaAiProviderServiceKey",
(serviceProvider, _) => ollamaClient.AsIChatResponseProvider()
);
// Register the Ollama chat client as a keyed IChatClient.
serviceCollection.AddKeyedScoped<IChatClient>(
"ollamaAiClient",
(serviceProvider, _) => ollamaClient
);
// Register a default (non-keyed) IChatResponseProvider.
// This provider is used when no ChatResponseProviderServiceKey is specified.
serviceCollection.AddScoped<IChatResponseProvider>(
(serviceProvider) => azureOpenAiClient.AsIChatResponseProvider()
);
// Add DevExpress AI Desktop services (required for AIChatControl).
serviceCollection.AddDevExpressAIDesktop();
}
private static Uri AzureOpenAIEndpoint = new Uri("YOUR_AZURE_END_POINT");
private static ApiKeyCredential AzureOpenAIKey = new ApiKeyCredential("YOUR_OPENAI_API_KEY");
static string ModelId = "MODEL_NAME"; // For example, gpt-4o-mini
}
}
Run Independent AI Chats Side by Side
Place several AIChatControl instances within a window and specify a different ChatResponseProviderServiceKey for each chat control to interact with different AI services.
<dx:ThemedWindow
x:Class="DXWPFMultipleChatClients.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxaichat="http://schemas.devexpress.com/winfx/2008/xaml/aichat"
Title="MainWindow" Height="800" Width="1000">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<dxaichat:AIChatControl
x:Name="azureChat"
ChatResponseProviderServiceKey="azureAiProviderServiceKey"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="10"/>
<dxaichat:AIChatControl
x:Name="ollamaChat"
ChatResponseProviderServiceKey="ollamaAiProviderServiceKey"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Margin="10"
Grid.Column="1"/>
</Grid>
</dx:ThemedWindow>
The following animation illustrates the result:

Switch Between AI Services or AI Agents
Use a single AIChatControl and modify its ChatResponseProviderServiceKey property to switch between AI services or AI agents.
Troubleshooting
The IChatResponseProvider service is not registered
Add IChatResponseProvider to the service collection at application startup:
// Create an Azure OpenAI chat client.
var azureOpenAiClient = new AzureOpenAIClient(AzureOpenAIEndpoint, AzureOpenAIKey)
.GetChatClient(ModelId)
.AsIChatClient();
// Register a keyed IChatResponseProvider.
serviceCollection.AddKeyedScoped<IChatResponseProvider>(
"azureAiProviderServiceKey",
(serviceProvider, _) => azureOpenAiClient.AsIChatResponseProvider()
);
// Register the Azure OpenAI chat client as a keyed IChatClient.
serviceCollection.AddKeyedScoped<IChatClient>(
"azureAiClient",
(serviceProvider, _) => azureOpenAiClient
);
There is no registered service of type Microsoft.Extensions.AI.IChatClient
This error occurs when the AIChatControl cannot find a registered chat client that matches its configuration.
Do one of the following:
- Check ChatResponseProviderServiceKey
- Ensure that the
AIChatControl.ChatResponseProviderServiceKeyproperty matches the key of one of the chat client providers you registered in the service collection. - Register a Default Chat Client
If you do not assign a
ChatResponseProviderServiceKeyto the chat control, register a default chat client in the desktop container to ensure that the chat control can automatically resolve the AI service:AIExtensionsContainerDesktop.Default.RegisterChatClient(chatClient);
See the following help topic for more information: Register AI Client.