A walkthrough of Microsoft.Extensions.AI 11.0's IChatClient for a provider-agnostic ASP.NET Core support chat: swap OpenAI, Ollama or a scripted provider through configuration while streaming, tool calling, caching and OpenTelemetry stay in one pipeline.
Key points
- IChatClient has just three members: GetResponseAsync, GetStreamingResponseAsync and GetService.
- Vendor-specific code is a single keyed singleton IChatClient selected from configuration.
- UseFunctionInvocation, UseDistributedCache and UseOpenTelemetry wrap outside-in; the first Use* call is outermost.
- Leaving provider and model out of the cache key lets one model's answer be served as another's.
- Per-user tools belong in ChatOptions, not in the singleton pipeline.
- Microsoft.Extensions.AI 11.0.0 ships net8.0 through net11.0, netstandard2.0 and net462; the core chat APIs are not experimental.
Real-world use
- An ASP.NET Core support chat that streams an answer while it checks the signed-in user's order status through a tool.
- The same application pointed at a local Ollama model for a customer whose data cannot leave the network.
- A cheaper model routed in for simple questions without rewriting services.
- A scripted offline provider that lets CI exercise streaming, tool calls, caching and telemetry with no API key.
This summary was generated by the agent from the original post on ABP.IO Community. The full text and all rights belong to its author and publisher. Go to original