Skip to content

.NET: [Feature]: AIAgent.AsIChatClient #3496

Description

There are more and more APIs across the .NET ecosystem now accepting IChatClient. It'd be helpful if any AIAgent could be used as an IChatClient, at least for basic operations.

cc: westey (@westey-m)

Activity

  1. changed the title [-][Feature]: AIAgent.AsIChatClient[/-] [+].NET: [Feature]: AIAgent.AsIChatClient[/+] on Jan 29, 2026
  2. shyamnamboodiripad commented on Jan 29, 2026

    @shyamnamboodiripad

    One use case where this would be helpful is for the Microsoft.Extensions.AI.Evaluation framework which defines .NET abstractions for (AI) evaluation along with a set of in-built evaluators. These abstractions currently rely on IChatClient for all AI / LLM interactions. It would be great to have the ability to leverage agents (e.g., Copilot SDK) to perform these evaluations the same way one would otherwise use an LLM (with or without tools).

    (You can read more about the above framework and the functionality it supports in this blog post.)

  3. tomas-rampas commented on Aug 16, 2026

    @tomas-rampas
    Contributor

    I'd like to take this on, as described below — happy to adjust the shape based on maintainer feedback.

    Proposed API, mirroring the existing AsAIFunction(this AIAgent, ..., AgentSession?) extension and the M.E.AI AsIChatClient naming convention already used across this repo:

    // Microsoft.Agents.AI / AIAgentExtensions
    public static IChatClient AsIChatClient(this AIAgent agent, AgentSession? session = null)

    Backed by an internal AIAgentChatClient : IChatClient that:

    • maps GetResponseAsync / GetStreamingResponseAsync to RunAsync / RunStreamingAsync, reusing the existing AsChatResponse() / AsChatResponseUpdatesAsync() converters;
    • carries ChatOptions through ChatClientAgentRunOptions (so ChatClientAgent honors temperature/tools/instructions/ConversationId), additionally copying ResponseFormat onto the base AgentRunOptions so structured output (GetResponseAsync<T>) works for every agent type;
    • defaults to stateless per call (full history each request); the optional bound session mirrors AsAIFunction semantics;
    • forwards GetService to the agent, synthesizing ChatClientMetadata from AIAgentMetadata as fallback; Dispose is a no-op (the caller owns the agent lifetime).

    Unit tests (no live LLM) covering argument guards, options/session pass-through, raw ChatResponse/ConversationId preservation, streaming conversion, GetService, and an end-to-end ChatClientAgent + structured-output case. PR to follow shortly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

.NETUsage: [Issues, PRs], Target: .Net

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions