Skip to content

Commit 9aff585

Browse files
Copilotkzu
andcommitted
Preserve structured JsonElement tool arguments in GitHub Copilot agent events (#5)
* Implement raw JsonElement argument handling Co-authored-by: kzu <169707+kzu@users.noreply.github.com> Agent-Logs-Url: https://github.com/kzu/agent-framework/sessions/ca9509f7-6318-4f1a-8ba2-17e4207bc7c4 * Fix test validation and preserve structured JSON args Co-authored-by: kzu <169707+kzu@users.noreply.github.com> Agent-Logs-Url: https://github.com/kzu/agent-framework/sessions/ca9509f7-6318-4f1a-8ba2-17e4207bc7c4 --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: kzu <169707+kzu@users.noreply.github.com>
1 parent d0a9ae2 commit 9aff585

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

dotnet/src/Microsoft.Agents.AI.GitHub.Copilot/GitHubCopilotAgent.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,9 @@ internal AgentResponseUpdate ConvertToolCompleteToAgentResponseUpdate(ToolExecut
500500
JsonValueKind.Number => property.Value.TryGetInt64(out long l)
501501
? (object?)l
502502
: property.Value.GetDouble(),
503+
JsonValueKind.Object => property.Value.Clone(),
504+
JsonValueKind.Array => property.Value.Clone(),
505+
JsonValueKind.Undefined => null,
503506
_ => property.Value.GetRawText()
504507
};
505508
}

dotnet/tests/Microsoft.Agents.AI.GitHub.Copilot.UnitTests/GitHubCopilotAgentTests.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,8 @@ public void ConvertToolStartToAgentResponseUpdate_WithAllJsonValueKinds_Converts
350350
nullVal = (string?)null,
351351
intVal = 100,
352352
floatVal = 3.14,
353-
objVal = new { nested = "value" }
353+
objVal = new { nested = "value" },
354+
arrVal = new List<int> { 1, 2, 3 }
354355
})
355356
}
356357
};
@@ -367,8 +368,12 @@ public void ConvertToolStartToAgentResponseUpdate_WithAllJsonValueKinds_Converts
367368
Assert.Null(content.Arguments["nullVal"]);
368369
Assert.Equal(100L, content.Arguments["intVal"]);
369370
Assert.Equal(3.14, (double)content.Arguments["floatVal"]!, 2);
370-
// Non-primitive values fall back to raw JSON text
371-
Assert.IsType<string>(content.Arguments["objVal"]);
371+
JsonElement objValElement = Assert.IsType<JsonElement>(content.Arguments["objVal"]);
372+
Assert.Equal(JsonValueKind.Object, objValElement.ValueKind);
373+
Assert.Equal("value", objValElement.GetProperty("nested").GetString());
374+
JsonElement arrValElement = Assert.IsType<JsonElement>(content.Arguments["arrVal"]);
375+
Assert.Equal(JsonValueKind.Array, arrValElement.ValueKind);
376+
Assert.Equal(3, arrValElement.GetArrayLength());
372377
}
373378

374379
[Fact]

0 commit comments

Comments
 (0)