Companion code for Generative AI in .NET, Chapter 4 section 4.2.4 ("Anthropic Agents").
Uses an AnthropicClient and hands its chat surface to a standard ChatClientAgent. The same agent API works against OpenAI, Azure OpenAI, Ollama, etc.
Why the local
AnthropicChatClient.csshim?Anthropic.SDK5.10.0 was compiled againstMicrosoft.Extensions.AI.Abstractions10.3.0, but the repo pins 10.5.0 (required byMicrosoft.Agents.AI1.3.0, which itself rejects 10.3 withCS1705). 10.5 reshapedHostedMcpServerTool.AuthorizationToken, sonew AnthropicClient(apiKey).Messages(which routes through the SDK's bundledChatClientHelper) throwsMissingMethodExceptionat runtime. The shim sidesteps the helper by callingAnthropicClient.Messages.GetClaudeMessageAsyncdirectly and translating between Anthropic's wire types andMicrosoft.Extensions.AItypes itself. WhenAnthropic.SDK5.11+ ships rebuilt against M.E.AI 10.5+, drop the shim and revert tonew AnthropicClient(apiKey).Messages. Seedocs/verification-log.md(entry2026-05-02) for the full chain of reasoning. The chapter prose describes the intended pattern; this folder ships a concrete adapter so the sample is runnable today.
export ANTHROPIC_API_KEY=sk-ant-...
dotnet run --project samples/ch04-agent-framework/04.2.4-anthropic-agentsOverride the model with ANTHROPIC_MODEL (defaults to claude-haiku-4-5-20251001).
Manuscript/Chapter-04.md, section 4.2.4.Manuscript/Appendix-B-Model-Quick-Reference.mdfor current Claude model IDs.
- .NET 9 SDK and an Anthropic API key.
A throwaway harness at tests/AnthropicVerification/ hits the live API with each model ID listed in Appendix B. The harness has no Microsoft.Agents.AI dependency, so it can pin to M.E.AI 10.3.0 and run end-to-end -- use it during the pre-print verification passes to confirm Anthropic has not rotated the cited identifiers.