.NET: fix inline skill string arguments#6047
Open
he-yufeng wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR adds support for AgentInlineSkillScript to accept arguments passed as a JSON string containing an encoded JSON object (in addition to a direct JSON object), and adds a unit test to validate the behavior.
Changes:
- Parse string-typed arguments as JSON and then treat them as the arguments object.
- Ensure values are safe to use after the parsed document is disposed.
- Add a unit test covering string-encoded object arguments.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentInlineSkillScriptTests.cs | Adds coverage for passing arguments as a JSON string that encodes an object. |
| dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentInlineSkillScript.cs | Parses string arguments into JSON and converts them into AIFunctionArguments. |
Comment on lines
+95
to
112
| var argumentElement = arguments.Value; | ||
| using var parsedStringArguments = ParseStringArguments(argumentElement); | ||
| if (parsedStringArguments is not null) | ||
| { | ||
| argumentElement = parsedStringArguments.RootElement; | ||
| } | ||
|
|
||
| if (argumentElement.ValueKind != JsonValueKind.Object) | ||
| { | ||
| throw new InvalidOperationException( | ||
| $"Inline skill scripts expect arguments as a JSON object but received a JSON element of kind '{arguments.Value.ValueKind}'."); | ||
| $"Inline skill scripts expect arguments as a JSON object but received a JSON element of kind '{argumentElement.ValueKind}'."); | ||
| } | ||
|
|
||
| var dict = new Dictionary<string, object?>(); | ||
| foreach (var property in arguments.Value.EnumerateObject()) | ||
| foreach (var property in argumentElement.EnumerateObject()) | ||
| { | ||
| dict[property.Name] = property.Value; | ||
| dict[property.Name] = parsedStringArguments is null ? property.Value : property.Value.Clone(); | ||
| } |
Comment on lines
+46
to
+60
| [Fact] | ||
| public async Task RunAsync_WithStringEncodedObjectArguments_PassesArgumentsAsync() | ||
| { | ||
| // Arrange | ||
| var script = new AgentInlineSkillScript("add", (int a, int b) => a + b); | ||
| var skill = new AgentInlineSkill("calc-skill", "Calc.", "Instructions."); | ||
| using var argsDoc = JsonDocument.Parse("\"{\\\"a\\\":3,\\\"b\\\":7}\""); | ||
| var args = argsDoc.RootElement; | ||
|
|
||
| // Act | ||
| var result = await script.RunAsync(skill, args, null, CancellationToken.None); | ||
|
|
||
| // Assert | ||
| Assert.Equal(10, int.Parse(result?.ToString()!)); | ||
| } |
| // Arrange | ||
| var script = new AgentInlineSkillScript("add", (int a, int b) => a + b); | ||
| var skill = new AgentInlineSkill("calc-skill", "Calc.", "Instructions."); | ||
| using var argsDoc = JsonDocument.Parse("\"{\\\"a\\\":3,\\\"b\\\":7}\""); |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #6020
To verify
Note: plain dotnet test currently starts through the VSTest path on this Windows SDK install and fails with the Microsoft.Testing.Platform opt-in error before test execution, so I ran the built MTP test assembly directly.