Microsoft extensions ai

From managedcode/dotnet-skills · View interactive version

Microsoft extensions ai is an AI agent skill from the GitHub repository managedcode/dotnet-skills. Build provider-agnostic .NET AI integrations with `Microsoft.Extensions.AI`, `IChatClient`, embeddings, middleware, structured output, vector search, and evaluation. USE FOR: building or reviewing .NET code that uses Microsoft.Extensions.AI, Microsoft.Extensions.AI.Abstractions, IChatClient, IEmbedd

How to use this skill

Skill file

Microsoft.Extensions.AI

Trigger On

Workflow

  1. Classify the request first: plain model access, tool calling, embeddings/vector search, evaluation, image generation, local-model prototyping, MCP bootstrap, or true agent orchestration.
  2. Default to Microsoft.Extensions.AI for application and service code that needs provider-agnostic chat, embeddings, middleware, structured output, and testability.
  3. Reference Microsoft.Extensions.AI.Abstractions directly only when authoring provider libraries or lower-level reusable integration packages.
  4. Model IChatClient and IEmbeddingGenerator composition explicitly in DI. Keep options, caching, telemetry, logging, and tool invocation inspectable in the pipeline.
  5. Treat chat state deliberately. For stateless providers, resend history. For stateful providers, propagate ConversationId rather than assuming all providers behave the same way.
  6. Use Microsoft.Extensions.VectorData and Microsoft.Extensions.DataIngestion as adjacent building blocks for RAG instead of hand-rolling store abstractions prematurely. Treat the embedding model, vector dimensions, and collection schema as one owned contract: changing any of them means reindexing rather than reusing old vector data. Keep vector API source-breaking notes version-aware; in the 10.5+ line, named-argument usage of VectorStoreVectorAttribute uses dimensions:.
  7. Treat the .NET AI quickstarts as bootstrap paths, not finished architecture. They now cover minimal assistants, MCP client/server flows, local models, app templates, and image generation. Start there for a vertical slice, then harden the DI, telemetry, and evaluation story here.
  8. Escalate to microsoft-agent-framework when the requirement becomes agent threads, multi-agent orchestration, higher-order workflows, durable execution, or remote agent hosting.
  9. Validate with real providers, realistic prompts, and evaluation gates so the abstraction layer actually buys portability and reliability.

Architecture

flowchart LR
  A["Task"] --> B{"Need agent threads, multi-agent orchestration, or remote agent hosting?"}
  B -->|Yes| C["Use Microsoft Agent Framework on top of `Microsoft.Extensions.AI.Abstractions`"]
  B -->|No| D{"Need provider-agnostic chat, embeddings, tools, typed output, or evaluation?"}
  D -->|Yes| E["Use `Microsoft.Extensions.AI`"]
  E --> F["Compose `IChatClient` / `IEmbeddingGenerator` in DI"]
  F --> G["Add caching, telemetry, tools, vector data, and evaluation deliberately"]
  D -->|No| H["Use plain provider SDKs or deterministic .NET code"]

Core Knowledge

Decision Cheatsheet

| If you need | Default choice | Why |

|---|---|---|

| App-level provider abstraction with middleware | Microsoft.Extensions.AI | Highest leverage for apps and services |

| A reusable provider or connector library | Microsoft.Extensions.AI.Abstractions | Keeps your package at the contract layer |

| Typed chat or UI streaming | IChatClient with GetResponseAsync / GetStreamingResponseAsync | Common request/response shape across providers |

| Tool calling from .NET methods | AIFunction + FunctionInvokingChatClient | Native function metadata and invocation pipeline |

| Typed structured output | IChatClient.GetResponseAsync<T> extensions | Keeps schema intent in code instead of prompt parsing |

| Vector search or RAG | IEmbeddingGenerator + Microsoft.Extensions.VectorData.Abstractions | Standardizes embeddings and store access |

| Local model prototyping | IChatClient with an Ollama-backed implementation | Keeps the app on the MEAI abstractions while you validate prompts or UX locally |

| Text-to-image or image-generation middleware | IImageGenerator | Use the dedicated image abstraction instead of overloading chat APIs |

| Evaluation and regression gates | Microsoft.Extensions.AI.Evaluation.* | Relevance, safety, task adherence, caching, reports |

| Agent threads or multi-step autonomous orchestration | microsoft-agent-framework | This is beyond plain provider abstraction |

Common Failure Modes

Deliver

Validate

When exact wording, edge-case API behavior, or less-common examples matter, check the local official docs snapshot before relying on summaries.

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.