Skip to content

.NET: fix inline skill string arguments#6047

Open
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/inline-skill-string-args
Open

.NET: fix inline skill string arguments#6047
he-yufeng wants to merge 1 commit into
microsoft:mainfrom
he-yufeng:fix/inline-skill-string-args

Conversation

@he-yufeng
Copy link
Copy Markdown
Contributor

Summary

  • accept inline skill arguments when a provider sends the function arguments as a JSON string containing an object
  • keep the existing object-only contract for inline skill arguments
  • clone values parsed from the temporary JsonDocument so function invocation does not depend on a disposed document
  • add a regression test for string-encoded object arguments

Fixes #6020

To verify

  • dotnet build dotnet\tests\Microsoft.Agents.AI.UnitTests\Microsoft.Agents.AI.UnitTests.csproj --no-restore --tl:off
  • dotnet dotnet\tests\Microsoft.Agents.AI.UnitTests\bin\Debug\net10.0\Microsoft.Agents.AI.UnitTests.dll --filter-class Microsoft.Agents.AI.UnitTests.AgentSkills.AgentInlineSkillScriptTests --timeout 2m
  • dotnet format dotnet\agent-framework-dotnet.slnx --verify-no-changes --include dotnet\src\Microsoft.Agents.AI\Skills\Programmatic\AgentInlineSkillScript.cs dotnet\tests\Microsoft.Agents.AI.UnitTests\AgentSkills\AgentInlineSkillScriptTests.cs --no-restore --verbosity minimal
  • git diff --check

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.

Copilot AI review requested due to automatic review settings May 22, 2026 21:56
@moonbox3 moonbox3 added the .NET label May 22, 2026
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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}\"");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

.NET: [Bug]: Arguments valueKind is String instead of Object when calling AgentInlineSkillScript via functionCall

3 participants