Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +105 to +107
}
}
}

if (arguments.Value.ValueKind != JsonValueKind.Object)
{
throw new InvalidOperationException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Comment on lines +52 to +53

// 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()
{
Expand Down