$npx -y skills add DevExpress/agent-skills --skill devexpress-winforms-ai-chatAI agent skill for the DevExpress WinForms AIChatControl. Covers NuGet setup, the project SDK change, AI client registration (OpenAI, Azure OpenAI, Ollama), adding the control to a form, streaming, Markdown rendering, manual message handling (MessageSending), and chat history (Sa
| 1 | # DevExpress WinForms AI Chat Control |
| 2 | |
| 3 | `AIChatControl` (namespace `DevExpress.AIIntegration.WinForms.Chat`) embeds a ready-made chat UI in a WinForms app. It is a Blazor/WebView2-hosted control: you register an `IChatClient` (OpenAI, Azure OpenAI, Ollama) once at startup, drop the control on a form, and it handles the message list, streaming, Markdown rendering, and history. It is **.NET 8+ only** (the project must use the `Microsoft.NET.Sdk.Razor` SDK). |
| 4 | |
| 5 | ## When to Use This Skill |
| 6 | |
| 7 | - Add a conversational AI chat panel to a WinForms app (assistant, copilot, support bot). |
| 8 | - Register an AI provider client (OpenAI / Azure OpenAI / Ollama) for the chat control. |
| 9 | - Stream responses, render Markdown safely, show a header, or add prompt suggestions. |
| 10 | - Intercept user messages before they are sent (`MessageSending`) to inject instructions or answer yourself. |
| 11 | - Save and restore chat history (`SaveMessages` / `LoadMessages`). |
| 12 | |
| 13 | ## Before You Start — Ask the Developer |
| 14 | |
| 15 | If the host agent has a structured question-asking tool available, use it to ask these questions one at a time with clear options — for example, Claude Code's `AskUserQuestion` tool or GitHub Copilot's `askQuestions` tool. If no such tool is available, ask the questions directly in the chat response before generating code. |
| 16 | |
| 17 | 1. **Target framework?** `AIChatControl` requires **.NET 8+** with the `Microsoft.NET.Sdk.Razor` SDK. On .NET Framework it is unsupported — see [references/getting-started-dotnet-fw.md](references/getting-started-dotnet-fw.md). |
| 18 | 2. **Which AI provider?** OpenAI, Azure OpenAI, or a local model via Ollama? This decides the provider NuGet package and the `IChatClient` registration. |
| 19 | 3. **One provider or several?** A single `RegisterChatClient`, or multiple keyed providers selected via `ChatResponseProviderServiceKey`? |
| 20 | 4. **How are credentials supplied?** Environment variables, a secrets store, or configuration — never hardcode API keys. |
| 21 | 5. **Markdown output?** If the model returns Markdown, enable `ContentFormat = Markdown` and sanitize the HTML (`MarkdownConvert` + `HtmlSanitizer`). |
| 22 | 6. **Deployment target?** Windows 10 / Server needs the WebView2 runtime distributed; it is built into Windows 11. |
| 23 | |
| 24 | ## Reference Files |
| 25 | |
| 26 | | Topic | File | |
| 27 | |---|---| |
| 28 | | NuGet packages, SDK change, AI client registration, control setup, all configuration patterns, troubleshooting | [references/getting-started.md](references/getting-started.md) | |
| 29 | | .NET Framework support (unsupported — alternatives) | [references/getting-started-dotnet-fw.md](references/getting-started-dotnet-fw.md) | |
| 30 | |
| 31 | --- |
| 32 | |
| 33 | ## Quick Start (Minimal Working Example) |
| 34 | |
| 35 | ```csharp |
| 36 | // 1. Install: DevExpress.AIIntegration.WinForms.Chat, DevExpress.Win.Design |
| 37 | // + one AI provider package, e.g. OpenAI (≥ 2.2.0) + Microsoft.Extensions.AI.OpenAI |
| 38 | // 2. Change .csproj: <Project Sdk="Microsoft.NET.Sdk.Razor"> |
| 39 | // 3. Target .NET 8+ |
| 40 | |
| 41 | // Program.cs |
| 42 | using Microsoft.Extensions.AI; |
| 43 | using DevExpress.AIIntegration; |
| 44 | |
| 45 | Application.EnableVisualStyles(); |
| 46 | Application.SetCompatibleTextRenderingDefault(false); |
| 47 | |
| 48 | IChatClient chatClient = new OpenAI.OpenAIClient( |
| 49 | Environment.GetEnvironmentVariable("OPENAI_API_KEY")) |
| 50 | .GetChatClient("gpt-4o-mini") |
| 51 | .AsIChatClient(); |
| 52 | |
| 53 | AIExtensionsContainerDesktop.Default.RegisterChatClient(chatClient); |
| 54 | Application.Run(new Form1()); |
| 55 | ``` |
| 56 | |
| 57 | ```csharp |
| 58 | // Form1.cs |
| 59 | using DevExpress.AIIntegration.WinForms.Chat; |
| 60 | using DevExpress.XtraEditors; |
| 61 | |
| 62 | public partial class Form1 : XtraForm |
| 63 | { |
| 64 | public Form1() |
| 65 | { |
| 66 | InitializeComponent(); |
| 67 | var chat = new AIChatControl { Dock = DockStyle.Fill }; |
| 68 | Controls.Add(chat); |
| 69 | } |
| 70 | } |
| 71 | ``` |
| 72 | |
| 73 | > **If you add `AIChatControl` in the WinForms designer instead of code, wrap its setup in `BeginInit`/`EndInit`.** `AIChatControl` implements `ISupportInitialize`, so a correct `*.Designer.cs` must surround its configuration in `InitializeComponent()` with `((System.ComponentModel.ISupportInitialize)(this.aiChatControl1)).BeginInit();` … `EndInit();` (the designer normally emits this — verify generated co |