Links: Architecture: docs/Architecture/Overview.md Modules: ClaudeCodeSharpSDK.Extensions.AgentFramework, ClaudeCodeSharpSDK.Extensions.AI ADRs: 004-microsoft-agent-framework-integration.md, 003-microsoft-extensions-ai-integration.md
Enable ClaudeCodeSharpSDK consumers to use Microsoft Agent Framework (AIAgent) on top of the existing ClaudeChatClient adapter, with a first-class opt-in package and DI registration helpers that match the repository's adapter-per-boundary approach.
- new optional package
ManagedCode.ClaudeCodeSharpSDK.Extensions.AgentFramework - DI helpers
AddClaudeCodeAgent()andAddKeyedClaudeCodeAgent() - composition of
ClaudeChatClientwithMicrosoft.Agents.AIChatClientAgent - README and docs updates showing direct
AsAIAgent(...)and DI usage - prerelease package publishing while upstream
Microsoft.Agents.AIremains prerelease
- new custom
AIAgentruntime parallel toChatClientAgent - Microsoft Agent Framework hosting/workflows helpers (
Microsoft.Agents.AI.Hosting, durable agents, DevUI) - changes to core SDK execution, thread state, parsing, or CLI contracts
- Microsoft Agent Framework integration MUST remain opt-in via a separate package and MUST NOT add a
Microsoft.Agents.AIdependency toManagedCode.ClaudeCodeSharpSDKcore orManagedCode.ClaudeCodeSharpSDK.Extensions.AI. - The integration MUST compose the existing
ClaudeChatClient(IChatClient) with the canonical MAFAsAIAgent(...)/ChatClientAgentpath instead of introducing a bespoke agent runtime. AddClaudeCodeAgent()MUST register bothIChatClientandAIAgentso consumers can resolve either abstraction from the same container.AddKeyedClaudeCodeAgent()MUST register keyedIChatClientand keyedAIAgentusing the same service key.- Agent configuration supplied through
ChatClientAgentOptionsMUST flow into the created agent without mutating Claude-specific chat client defaults. - Claude provider metadata exposed through
ChatClientMetadataMUST remain available from the agent-resolved chat client. ManagedCode.ClaudeCodeSharpSDK.Extensions.AgentFrameworkMUST be published as a prerelease package while its upstreamMicrosoft.Agents.AIdependency is prerelease.
-
Direct MAF usage over
ClaudeChatClient- Actor: consumer code using
AIAgent - Trigger:
new ClaudeChatClient().AsAIAgent(...) - Steps: construct
ClaudeChatClient-> call MAFAsAIAgent(...)-> run prompt viaRunAsync/RunStreamingAsync - Result: standard
AIAgentbacked by Claude CLI through the existingIChatClientadapter
- Actor: consumer code using
-
DI registration
- Actor: ASP.NET / worker / console host using
IServiceCollection - Trigger:
services.AddClaudeCodeAgent(...) - Steps: register
ClaudeChatClient-> createChatClientAgentwith configured options -> resolveAIAgent - Result: one-line registration for MAF consumers
- Actor: ASP.NET / worker / console host using
-
Keyed DI registration
- Actor: multi-agent / multi-provider host
- Trigger:
services.AddKeyedClaudeCodeAgent("claude-main", ...) - Steps: register keyed
IChatClient-> create keyedAIAgent-> resolve by key - Result: keyed Claude-backed agents coexist with other providers in the same DI container
- null
IServiceCollectionor null keyed service key -> throw argument exceptions from the registration layer - missing
ChatClientAgentOptionsconfiguration -> registration still succeeds with defaultChatClientAgent - MAF middleware decoration wraps the underlying chat client -> Claude metadata must still be discoverable via the resolved agent chat client
- Entry points:
ClaudeServiceCollectionExtensions.AddClaudeCodeAgent,ClaudeServiceCollectionExtensions.AddKeyedClaudeCodeAgent - Reads from:
ClaudeChatClientOptions,ChatClientAgentOptions, DIILoggerFactory - Writes to: DI service collection only
- Side effects / emitted events: creates singleton
ClaudeChatClientand singleton/keyedChatClientAgent - Idempotency: follows standard DI additive registration semantics; repeated registration adds additional descriptors
- Error handling: null guard exceptions on registration inputs; runtime agent execution errors are delegated to existing
ClaudeChatClient/ MAF behaviour - Security / permissions: no new permissions beyond existing
claudeCLI prerequisites; MAF function invocation remains opt-in through consumer-supplied tools/options - Observability: MAF logger factory is passed into
ChatClientAgent, preserving standard MAF logging hooks
flowchart LR
Consumer["Consumer code / Host"]
DI["IServiceCollection"]
MAF["ChatClientAgent (MAF)"]
MEAI["ClaudeChatClient (IChatClient)"]
Core["ClaudeClient / ClaudeThread"]
CLI["claude -p --output-format stream-json"]
Consumer --> DI
DI --> MAF
MAF --> MEAI
MEAI --> Core
Core --> CLI
- build:
dotnet build ManagedCode.ClaudeCodeSharpSDK.slnx -c Release -warnaserror - test:
dotnet test --solution ManagedCode.ClaudeCodeSharpSDK.slnx -c Release
- unit tests: ClaudeServiceCollectionExtensionsTests.cs
ManagedCode.ClaudeCodeSharpSDK.Extensions.AgentFrameworkexists as a separate opt-in package- the package is published with a prerelease suffix while
Microsoft.Agents.AIremains prerelease - direct
ClaudeChatClient+AsAIAgent(...)usage is documented inREADME.md - DI helpers register non-keyed and keyed
AIAgentinstances over Claude chat clients - automated tests cover happy path and keyed-edge path registration behaviour
- architecture overview, feature doc, ADR, and development setup docs reflect the new module boundary