Skip to content

Add Claude (Anthropic SDK) sample agent for .NET#285

Open
Yogeshp-MSFT wants to merge 2 commits intomicrosoft:mainfrom
Yogeshp-MSFT:Claude-Dotnet-Sample
Open

Add Claude (Anthropic SDK) sample agent for .NET#285
Yogeshp-MSFT wants to merge 2 commits intomicrosoft:mainfrom
Yogeshp-MSFT:Claude-Dotnet-Sample

Conversation

@Yogeshp-MSFT
Copy link
Copy Markdown

Adds a new .NET sample agent under dotnet/claude/sample-agent that uses Anthropic Claude as the LLM provider via the Anthropic.SDK NuGet package.

What this does

  • Demonstrates using Anthropic.SDK 5.10.0 as an IChatClient drop-in replacement for Azure OpenAI, working seamlessly with ChatClientAgent and the Microsoft.Extensions.AI ecosystem.
  • Follows the same architecture as dotnet/agent-framework/sample-agent — identical MCP tooling, agentic auth, observability, and hosting patterns.
  • Includes streaming responses, typing indicators, multi-turn conversation sessions, file attachment handling, and prompt injection sanitization.

Key files

File Purpose
Program.cs Registers AnthropicClient as IChatClient with function invocation + OpenTelemetry
Agent/MyAgent.cs Message handling, MCP tool loading, session management, observability
telemetry/ Full OpenTelemetry setup (metrics, tracing, A365 baggage) — mirrors reference sample
ToolingManifest.json MCP server declarations (Mail)
Agent-Code-Walkthrough.md Detailed code walkthrough

Package notes

Microsoft.Agents.AI is pinned to 1.0.0-rc4 — the last version compiled against Microsoft.Extensions.AI.Abstractions 10.3.0, which is binary-compatible with Anthropic.SDK 5.10.0. Newer versions (rc5+) target Abstractions 10.4.0+ and break at runtime due to removed HostedMcpServerTool.AuthorizationToken.

Copilot AI review requested due to automatic review settings April 24, 2026 06:02
@Yogeshp-MSFT Yogeshp-MSFT requested a review from a team as a code owner April 24, 2026 06:02
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a new .NET sample agent under dotnet/claude/sample-agent demonstrating how to use Anthropic Claude (via Anthropic.SDK) as an IChatClient in the Agent 365 / Microsoft 365 Agents hosting and tooling patterns.

Changes:

  • Introduces a new Claude-based sample agent project (hosting, auth, MCP tooling, sessions, streaming UX).
  • Adds OpenTelemetry setup plus custom agent metrics helpers/wrappers.
  • Adds sample configuration, MCP ToolingManifest, and Teams app package artifacts.

Agent 365 Sample Validation Report (high-level)

  • Documentation: README and code walkthrough are present.
  • Configuration: appsettings.json and appsettings.Playground.json are present with placeholders (no obvious committed secrets).
  • Project structure: .csproj, solution file, ToolingManifest, and Teams app package files are present.
  • Issues found (require changes): telemetry wrappers do not correctly await async operations / mark failures; custom metrics likely not exported due to meter registration; attachment handling currently risks leaking tokenized file URLs to the LLM provider.

Reviewed changes

Copilot reviewed 17 out of 19 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
dotnet/claude/sample-agent/Tools/DateTimeFunctionTool.cs Adds a local function tool for date/time.
dotnet/claude/sample-agent/ToolingManifest.json Declares MCP server configuration (Mail tools).
dotnet/claude/sample-agent/telemetry/AgentOTELExtensions.cs Adds OpenTelemetry configuration for the sample host.
dotnet/claude/sample-agent/telemetry/AgentMetrics.cs Adds ActivitySource/Meter helpers and wrapper methods.
dotnet/claude/sample-agent/telemetry/A365OtelWrapper.cs Adds A365 baggage/token-cache integration wrapper.
dotnet/claude/sample-agent/README.md Documents the sample and key behaviors.
dotnet/claude/sample-agent/Program.cs Configures DI, Anthropic IChatClient, routing, and endpoints.
dotnet/claude/sample-agent/m365agents.yml Adds Teams toolkit metadata file.
dotnet/claude/sample-agent/m365agents.playground.yml Adds Teams toolkit metadata for playground env usage.
dotnet/claude/sample-agent/ClaudeSampleAgent.csproj New web project with A365 + Anthropic dependencies.
dotnet/claude/sample-agent/AspNetExtensions.cs Adds JWT bearer token validation utilities for the host.
dotnet/claude/sample-agent/appsettings.Playground.json Adds playground config (token validation disabled, placeholders).
dotnet/claude/sample-agent/appsettings.json Adds default config (A365 options, connections, Anthropic settings).
dotnet/claude/sample-agent/appPackage/outline.png Teams app icon asset.
dotnet/claude/sample-agent/appPackage/manifest.json Teams app manifest for the sample agent.
dotnet/claude/sample-agent/appPackage/color.png Teams app icon asset.
dotnet/claude/sample-agent/Agent/MyAgent.cs Implements message handling, sessions, MCP tool loading, streaming UX.
dotnet/claude/sample-agent/Agent-Code-Walkthrough.md Provides a detailed walkthrough of the sample’s code.
dotnet/claude/ClaudeSampleAgent.sln Adds a solution file for the new sample.

Comment thread dotnet/claude/sample-agent/telemetry/AgentMetrics.cs
Comment thread dotnet/claude/sample-agent/telemetry/AgentMetrics.cs
Comment thread dotnet/claude/sample-agent/telemetry/AgentOTELExtensions.cs
Comment thread dotnet/claude/sample-agent/Tools/DateTimeFunctionTool.cs
Comment thread dotnet/claude/sample-agent/Agent/MyAgent.cs
Comment thread dotnet/claude/sample-agent/telemetry/A365OtelWrapper.cs Outdated
Comment thread dotnet/claude/sample-agent/Program.cs
Comment thread dotnet/claude/sample-agent/Program.cs
@Yogeshp-MSFT Yogeshp-MSFT force-pushed the Claude-Dotnet-Sample branch from d000d8b to de27a27 Compare April 28, 2026 07:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants