-
Notifications
You must be signed in to change notification settings - Fork 1k
.NET: Map additional props <-> A2A metadata #3137
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
SergeyMenshykh
merged 10 commits into
microsoft:main
from
SergeyMenshykh:a2a-map-metadata-and-additional-props
Jan 8, 2026
+907
−7
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
3b895c4
map additional props from agent run options to a2a request metadata
SergeyMenshykh 8897774
small touches
SergeyMenshykh 51e6b6b
Merge branch 'main' into a2a-map-metadata-and-additional-props
SergeyMenshykh 095a2c7
add unit tests for new extension methods
SergeyMenshykh 90ad1df
Merge branch 'a2a-map-metadata-and-additional-props' of https://githu…
SergeyMenshykh 7ed6aa9
Sort using
SergeyMenshykh f6068c4
add unit test
SergeyMenshykh 99b0aff
add additiona unit tests
SergeyMenshykh 0f79ac4
special case json element to avoid unnecessary serialization
SergeyMenshykh c654e9c
Merge branch 'main' into a2a-map-metadata-and-additional-props
SergeyMenshykh 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
Some comments aren't visible on the classic Files Changed page.
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
44 changes: 44 additions & 0 deletions
44
dotnet/src/Microsoft.Agents.AI.A2A/Extensions/AdditionalPropertiesDictionaryExtensions.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,44 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Text.Json; | ||
| using Microsoft.Agents.AI; | ||
|
|
||
| namespace Microsoft.Extensions.AI; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods for AdditionalPropertiesDictionary. | ||
| /// </summary> | ||
| internal static class AdditionalPropertiesDictionaryExtensions | ||
| { | ||
| /// <summary> | ||
| /// Converts an <see cref="AdditionalPropertiesDictionary"/> to a dictionary of <see cref="JsonElement"/> values suitable for A2A metadata. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This method can be replaced by the one from A2A SDK once it is available. | ||
| /// </remarks> | ||
| /// <param name="additionalProperties">The additional properties dictionary to convert, or <c>null</c>.</param> | ||
| /// <returns>A dictionary of JSON elements representing the metadata, or <c>null</c> if the input is null or empty.</returns> | ||
| internal static Dictionary<string, JsonElement>? ToA2AMetadata(this AdditionalPropertiesDictionary? additionalProperties) | ||
| { | ||
| if (additionalProperties is not { Count: > 0 }) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var metadata = new Dictionary<string, JsonElement>(); | ||
|
|
||
| foreach (var kvp in additionalProperties) | ||
| { | ||
| if (kvp.Value is JsonElement) | ||
| { | ||
| metadata[kvp.Key] = (JsonElement)kvp.Value!; | ||
| continue; | ||
| } | ||
|
|
||
| metadata[kvp.Key] = JsonSerializer.SerializeToElement(kvp.Value, A2AJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object))); | ||
SergeyMenshykh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| return metadata; | ||
| } | ||
| } | ||
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
36 changes: 36 additions & 0 deletions
36
dotnet/src/Microsoft.Agents.AI.Hosting.A2A/Converters/A2AMetadataExtensions.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,36 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Text.Json; | ||
| using Microsoft.Extensions.AI; | ||
|
|
||
| namespace Microsoft.Agents.AI.Hosting.A2A.Converters; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods for A2A metadata dictionary. | ||
| /// </summary> | ||
| internal static class A2AMetadataExtensions | ||
| { | ||
| /// <summary> | ||
| /// Converts a dictionary of metadata to an <see cref="AdditionalPropertiesDictionary"/>. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This method can be replaced by the one from A2A SDK once it is public. | ||
| /// </remarks> | ||
| /// <param name="metadata">The metadata dictionary to convert.</param> | ||
| /// <returns>The converted <see cref="AdditionalPropertiesDictionary"/>, or null if the input is null or empty.</returns> | ||
| internal static AdditionalPropertiesDictionary? ToAdditionalProperties(this Dictionary<string, JsonElement>? metadata) | ||
| { | ||
| if (metadata is not { Count: > 0 }) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var additionalProperties = new AdditionalPropertiesDictionary(); | ||
| foreach (var kvp in metadata) | ||
| { | ||
| additionalProperties[kvp.Key] = kvp.Value; | ||
| } | ||
| return additionalProperties; | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
...rc/Microsoft.Agents.AI.Hosting.A2A/Converters/AdditionalPropertiesDictionaryExtensions.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,45 @@ | ||
| // Copyright (c) Microsoft. All rights reserved. | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Text.Json; | ||
| using A2A; | ||
SergeyMenshykh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| using Microsoft.Extensions.AI; | ||
|
|
||
| namespace Microsoft.Agents.AI.Hosting.A2A.Converters; | ||
|
|
||
| /// <summary> | ||
| /// Extension methods for AdditionalPropertiesDictionary. | ||
| /// </summary> | ||
| internal static class AdditionalPropertiesDictionaryExtensions | ||
| { | ||
| /// <summary> | ||
| /// Converts an <see cref="AdditionalPropertiesDictionary"/> to a dictionary of <see cref="JsonElement"/> values suitable for A2A metadata. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This method can be replaced by the one from A2A SDK once it is available. | ||
SergeyMenshykh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// </remarks> | ||
| /// <param name="additionalProperties">The additional properties dictionary to convert, or <c>null</c>.</param> | ||
| /// <returns>A dictionary of JSON elements representing the metadata, or <c>null</c> if the input is null or empty.</returns> | ||
| internal static Dictionary<string, JsonElement>? ToA2AMetadata(this AdditionalPropertiesDictionary? additionalProperties) | ||
| { | ||
| if (additionalProperties is not { Count: > 0 }) | ||
| { | ||
| return null; | ||
| } | ||
|
|
||
| var metadata = new Dictionary<string, JsonElement>(); | ||
|
|
||
| foreach (var kvp in additionalProperties) | ||
| { | ||
| if (kvp.Value is JsonElement) | ||
| { | ||
| metadata[kvp.Key] = (JsonElement)kvp.Value!; | ||
| continue; | ||
| } | ||
|
|
||
| metadata[kvp.Key] = JsonSerializer.SerializeToElement(kvp.Value, A2AJsonUtilities.DefaultOptions.GetTypeInfo(typeof(object))); | ||
| } | ||
|
|
||
| return metadata; | ||
| } | ||
| } | ||
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
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.