Building AI features in .NET, from Microsoft.Extensions.AI to agents, RAG and operations, explained in depth, one at a time.
IChatClient, ChatMessage and ChatOptions against a local Ollama model: GetResponseAsync versus streaming with ToChatResponse, the ChatResponse shape with real Usage, stateless history versus ConversationId, ChatClientBuilder order proved with a DelegatingChatClient, UseLogging and UseDistributedCache measured, AddChatClient and AddKeyedChatClient in DI, GetService and ChatClientMetadata, a provider swap to a scripted fake, and the exact OllamaSharp failures.
GetResponseAsync<T> and ChatResponse<T> against a local Ollama model: the JSON schema MEAI generates and the real HTTP body with the format field, data wrapping for arrays and primitives, ResponseFormat by hand and the JsonSerializerOptions mismatch, exact failures from a scripted fake, required and Range after parsing, a bounded retry, and measured effects of enum names, descriptions, nullable fields and schema token cost.
AIFunctionFactory.Create and the JSON schema it generates, ChatOptions.Tools and a ToolMode that OllamaSharp ignores, the manual loop with FunctionCallContent and FunctionResultContent, UseFunctionInvocation call counts, iteration and error limits, IncludeDetailedErrors, AllowConcurrentInvocation, FunctionInvoker, unknown tools, bad arguments, approval with ApprovalRequiredAIFunction, validation inside the tool and the token cost of tool definitions.
AsAIAgent and ChatClientAgent, RunAsync and RunStreamingAsync with AgentResponse, the history a session resends every turn, ConversationId for stateful services, serializing a session and continuing in another process, lost messages under concurrent runs, tools and approval on the agent, an agent as another agent's tool, run and function-calling middleware, context providers that pile messages into history, structured output and OpenTelemetry.
A stdio MCP server on the generic host with tools, a prompt and a resource, a McpClient that calls them, the real JSON-RPC traffic (server/discover in spec 2026-07-28 versus the older initialize handshake), what a stray stdout write does, tool errors, the HTTP transport session modes and Mcp-Session-Id, MCP tools as AIFunctions with qwen3:4b-instruct, and prompt injection through tool output.
IEmbeddingGenerator on a local Ollama (embeddinggemma:300m): vector size and norm, batching, cosine and dot product with TensorPrimitives, task prefixes, UseDistributedCache and silent truncation, then Microsoft.Extensions.VectorData records, upsert, search, filter, get and delete with the same code on InMemory and SQLite (sqlite-vec), and why scores flip meaning between providers.
The full RAG loop in .NET on a local Ollama: measured chunking strategies, idempotent re-ingestion, citations, refusals, the context window, a poisoned chunk, an IChatClient wrapper and a regression set, with Microsoft.Extensions.DataIngestion marked as the preview it still is.