Skip to content

feat: add native support for Microsoft Agent Framework - #13

Merged
philasmar merged 2 commits into
devfrom
asmarp/native-ms-agent-framework-support
May 7, 2026
Merged

feat: add native support for Microsoft Agent Framework#13
philasmar merged 2 commits into
devfrom
asmarp/native-ms-agent-framework-support

Conversation

@philasmar

@philasmar philasmar commented May 7, 2026

Copy link
Copy Markdown
Contributor

Issue #, if available:
DOTNET-8638

Description of Changes

Integrates Microsoft Agent Framework into AWS.AgentCore so that users get the full MS AF pipeline (middleware, context providers, sessions, tool calling) when building agents deployed to AgentCore Runtime.

What changed

Core library (src/AWS.AgentCore/)

  • AgentCoreOptions — Added ChatClient, AgentOptions, ConfigureAgent properties. ModelId is now nullable/optional (no longer throws if unset).
  • AddAgentCore() — Refactored to register AIAgent and ChatClientAgent in DI with IChatClient priority resolution: explicit ChatClient > pre-registered DI > ModelId Bedrock fallback. Also registers AgentCoreRuntimeContextProvider.
  • New AgentCoreRuntimeContextProvider — An AIContextProvider that makes AgentCore runtime context available in the MS AF pipeline.
  • New AgentCoreSessionFactory — Internal helper for creating sessions with AgentCore session IDs stored in the session state bag.
  • Added InternalsVisibleTo for the unit test project.

Sample apps (all updated to new pattern)

  • MicrosoftAgentFrameworkSample — Demonstrates agent middleware, function-calling middleware, system instructions, and multiple tools configured via AgentOptions and ConfigureAgent.
  • StreamingAgent — Uses ChatClientAgent from DI with RunStreamingAsync.
  • AnnotationsSample — Uses ChatClientAgent via constructor injection, instance-method tools via ChatClientAgentRunOptions.
  • AnnotationsStreamingAgent — Same pattern with streaming.
  • NativeAotAnnotations / NativeAotExtensions — Updated to new pattern, NativeAOT compatible.

Tests

  • 11 unit tests for DI registration logic (IChatClient priority, agent options forwarding, ConfigureAgent callback, error paths).
  • 2 unit tests for AgentCoreRuntimeContextProvider.
  • 4 unit tests for AgentCoreSessionFactory.
  • 4 new integration tests for middleware verification (weather tool, flight tool, CloudWatch log assertions).
  • All existing tests pass (54 unit, 8 source generator).

Design philosophy

Thin layer — we don't wrap MS AF features. Users configure tools, middleware, and context providers through standard MS AF APIs (ChatClientAgentOptions, AsBuilder().Use()). When Microsoft adds new features, our library doesn't need changes to support them.

How to use

builder.AddAgentCore(options =>
{
    options.ModelId = "global.anthropic.claude-opus-4-7";
    options.AgentOptions = new ChatClientAgentOptions
    {
        ChatOptions = new()
        {
            Instructions = "You are a helpful assistant.",
            Tools = [AIFunctionFactory.Create(MyTool)]
        }
    };
    options.ConfigureAgent = agent => agent
        .AsBuilder()
        .Use(runFunc: MyMiddleware, runStreamingFunc: null)
        .Build();
});

Breaking changes

  • AgentCoreOptions.ModelId changed from string (default "") to string? (default null). Existing code that sets ModelId continues to work.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@philasmar philasmar added the Release Not Needed Add this label if a PR does not need to be released. label May 7, 2026
@philasmar
philasmar force-pushed the asmarp/native-ms-agent-framework-support branch from dd91f78 to ae66901 Compare May 7, 2026 15:54
@philasmar
philasmar force-pushed the asmarp/native-ms-agent-framework-support branch from ae66901 to 05905de Compare May 7, 2026 16:18
@philasmar
philasmar marked this pull request as ready for review May 7, 2026 16:31
@philasmar
philasmar requested review from a team as code owners May 7, 2026 16:31
@philasmar
philasmar requested review from GarrettBeatty and normj May 7, 2026 16:31
Comment thread src/AWS.AgentCore/Extensions/AgentCoreBuilderExtensions.cs Outdated
Comment thread src/AWS.AgentCore/Extensions/AgentCoreBuilderExtensions.cs Outdated
Comment thread src/AWS.AgentCore/Internal/AgentCoreSessionFactory.cs Outdated
@philasmar
philasmar requested a review from normj May 7, 2026 18:04
@philasmar
philasmar merged commit d7d5bfb into dev May 7, 2026
3 checks passed
@dscpinheiro
dscpinheiro deleted the asmarp/native-ms-agent-framework-support branch June 29, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Release Not Needed Add this label if a PR does not need to be released.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants