From ac29fcdda2073bc72de2c58d874bbf4d36b17167 Mon Sep 17 00:00:00 2001 From: Yufeng He <40085740+he-yufeng@users.noreply.github.com> Date: Fri, 22 May 2026 22:52:40 +0800 Subject: [PATCH] fix: accept stringified inline skill arguments --- .../Programmatic/AgentInlineSkillScript.cs | 17 +++++++++++++++++ .../AgentSkills/AgentInlineSkillScriptTests.cs | 16 ++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentInlineSkillScript.cs b/dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentInlineSkillScript.cs index c0abc73252..57be5580e0 100644 --- a/dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentInlineSkillScript.cs +++ b/dotnet/src/Microsoft.Agents.AI/Skills/Programmatic/AgentInlineSkillScript.cs @@ -92,6 +92,23 @@ private static AIFunctionArguments ConvertToFunctionArguments(JsonElement? argum return []; } + if (arguments.Value.ValueKind == JsonValueKind.String) + { + var text = arguments.Value.GetString(); + if (!string.IsNullOrWhiteSpace(text)) + { + try + { + using var document = JsonDocument.Parse(text); + arguments = document.RootElement.Clone(); + } + catch (JsonException) + { + arguments = arguments.Value; + } + } + } + if (arguments.Value.ValueKind != JsonValueKind.Object) { throw new InvalidOperationException( diff --git a/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentInlineSkillScriptTests.cs b/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentInlineSkillScriptTests.cs index 85521ba4a9..4729b13ec9 100644 --- a/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentInlineSkillScriptTests.cs +++ b/dotnet/tests/Microsoft.Agents.AI.UnitTests/AgentSkills/AgentInlineSkillScriptTests.cs @@ -43,6 +43,22 @@ public async Task RunAsync_WithParameters_PassesArgumentsAsync() Assert.Equal(10, int.Parse(result?.ToString()!)); } + [Fact] + public async Task RunAsync_WithJsonObjectStringArguments_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()!)); + } + [Fact] public void ParametersSchema_NoParameters_ReturnsSchema() {