-
Notifications
You must be signed in to change notification settings - Fork 606
.NET: Refactor A2A and AIAgent hosting extensions #1625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
49ed229
a2a reformat
DeagleGross 027a7a4
and refactor extensions on serviceCollection
DeagleGross 7c7943d
Merge branch 'main' into dmkorolev/a2ahost-removal
DeagleGross a7e446c
units
DeagleGross 8a7d443
merge main
DeagleGross 3bc5397
fix build
DeagleGross 3dcb34d
add remark for agentcard overloads
DeagleGross 602dda0
Merge branch 'main' into dmkorolev/a2ahost-removal
DeagleGross 9c3be9a
Merge branch 'main' into dmkorolev/a2ahost-removal
DeagleGross 972e9c8
Merge branch 'main' into dmkorolev/a2ahost-removal
DeagleGross File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
103 changes: 103 additions & 0 deletions
103
dotnet/src/Microsoft.Agents.AI.Hosting.A2A.AspNetCore/EndpointRouteBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,103 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using A2A; | ||
| using A2A.AspNetCore; | ||
| using Microsoft.Agents.AI; | ||
| using Microsoft.Agents.AI.Hosting.A2A; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.AspNetCore.Routing; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Logging; | ||
|
|
||
| namespace Microsoft.AspNetCore.Builder; | ||
|
|
||
| /// <summary> | ||
| /// Provides extension methods for configuring A2A (Agent2Agent) communication in a host application builder. | ||
| /// </summary> | ||
| public static class MicrosoftAgentAIHostingA2AEndpointRouteBuilderExtensions | ||
| { | ||
| /// <summary> | ||
| /// Attaches A2A (Agent2Agent) communication capabilities via Message processing to the specified web application. | ||
| /// </summary> | ||
| /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the A2A endpoints to.</param> | ||
| /// <param name="agentName">The name of the agent to use for A2A protocol integration.</param> | ||
| /// <param name="path">The route group to use for A2A endpoints.</param> | ||
| /// <returns>Configured <see cref="ITaskManager"/> for A2A integration.</returns> | ||
| public static ITaskManager MapA2A(this IEndpointRouteBuilder endpoints, string agentName, string path) | ||
| { | ||
| var agent = endpoints.ServiceProvider.GetRequiredKeyedService<AIAgent>(agentName); | ||
| return endpoints.MapA2A(agent, path); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attaches A2A (Agent2Agent) communication capabilities via Message processing to the specified web application. | ||
| /// </summary> | ||
| /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the A2A endpoints to.</param> | ||
| /// <param name="agentName">The name of the agent to use for A2A protocol integration.</param> | ||
| /// <param name="path">The route group to use for A2A endpoints.</param> | ||
| /// <param name="agentCard">Agent card info to return on query.</param> | ||
| /// <returns>Configured <see cref="ITaskManager"/> for A2A integration.</returns> | ||
| /// <remarks> | ||
| /// This method can be used to access A2A agents that support the | ||
| /// <see href="https://github.com/a2aproject/A2A/blob/main/docs/topics/agent-discovery.md#2-curated-registries-catalog-based-discovery">Curated Registries (Catalog-Based Discovery)</see> | ||
| /// discovery mechanism. | ||
| /// </remarks> | ||
| public static ITaskManager MapA2A(this IEndpointRouteBuilder endpoints, string agentName, string path, AgentCard agentCard) | ||
DeagleGross marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| var agent = endpoints.ServiceProvider.GetRequiredKeyedService<AIAgent>(agentName); | ||
| return endpoints.MapA2A(agent, path, agentCard); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attaches A2A (Agent2Agent) communication capabilities via Message processing to the specified web application. | ||
| /// </summary> | ||
| /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the A2A endpoints to.</param> | ||
| /// <param name="agent">The agent to use for A2A protocol integration.</param> | ||
| /// <param name="path">The route group to use for A2A endpoints.</param> | ||
| /// <returns>Configured <see cref="ITaskManager"/> for A2A integration.</returns> | ||
| public static ITaskManager MapA2A(this IEndpointRouteBuilder endpoints, AIAgent agent, string path) | ||
| { | ||
| var loggerFactory = endpoints.ServiceProvider.GetRequiredService<ILoggerFactory>(); | ||
| var taskManager = agent.MapA2A(loggerFactory: loggerFactory); | ||
| return endpoints.MapA2A(taskManager, path); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Attaches A2A (Agent2Agent) communication capabilities via Message processing to the specified web application. | ||
| /// </summary> | ||
| /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the A2A endpoints to.</param> | ||
| /// <param name="agent">The agent to use for A2A protocol integration.</param> | ||
| /// <param name="path">The route group to use for A2A endpoints.</param> | ||
| /// <param name="agentCard">Agent card info to return on query.</param> | ||
| /// <returns>Configured <see cref="ITaskManager"/> for A2A integration.</returns> | ||
| /// <remarks> | ||
| /// This method can be used to access A2A agents that support the | ||
| /// <see href="https://github.com/a2aproject/A2A/blob/main/docs/topics/agent-discovery.md#2-curated-registries-catalog-based-discovery">Curated Registries (Catalog-Based Discovery)</see> | ||
| /// discovery mechanism. | ||
| /// </remarks> | ||
| public static ITaskManager MapA2A(this IEndpointRouteBuilder endpoints, AIAgent agent, string path, AgentCard agentCard) | ||
| { | ||
| var loggerFactory = endpoints.ServiceProvider.GetRequiredService<ILoggerFactory>(); | ||
| var taskManager = agent.MapA2A(agentCard: agentCard, loggerFactory: loggerFactory); | ||
| return endpoints.MapA2A(taskManager, path); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Maps HTTP A2A communication endpoints to the specified path using the provided TaskManager. | ||
| /// TaskManager should be preconfigured before calling this method. | ||
| /// </summary> | ||
| /// <param name="endpoints">The <see cref="IEndpointRouteBuilder"/> to add the A2A endpoints to.</param> | ||
| /// <param name="taskManager">Pre-configured A2A TaskManager to use for A2A endpoints handling.</param> | ||
| /// <param name="path">The route group to use for A2A endpoints.</param> | ||
| /// <returns>Configured <see cref="ITaskManager"/> for A2A integration.</returns> | ||
| public static ITaskManager MapA2A(this IEndpointRouteBuilder endpoints, TaskManager taskManager, string path) | ||
| { | ||
| // note: current SDK version registers multiple `.well-known/agent.json` handlers here. | ||
| // it makes app return HTTP 500, but will be fixed once new A2A SDK is released. | ||
| // see https://github.com/microsoft/agent-framework/issues/476 for details | ||
DeagleGross marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| A2ARouteBuilderExtensions.MapA2A(endpoints, taskManager, path); | ||
| endpoints.MapHttpA2A(taskManager, path); | ||
|
|
||
| return taskManager; | ||
| } | ||
| } | ||
67 changes: 0 additions & 67 deletions
67
dotnet/src/Microsoft.Agents.AI.Hosting.A2A.AspNetCore/WebApplicationExtensions.cs
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.