Skip to content

Commit 13d2f5f

Browse files
MorabbinCopilot
andcommitted
Fix Python ruff formatting and .NET JSON serialization
- Python: run ruff format on test_tool_results.py - .NET: add JsonSerializerContext with ToolResultAIContent and pass serializerOptions to AIFunctionFactory.Create, matching the pattern used in ToolsTests for complex types. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 100aeb7 commit 13d2f5f

2 files changed

Lines changed: 17 additions & 10 deletions

File tree

dotnet/test/ToolResultsTests.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,27 @@
55
using GitHub.Copilot.SDK.Test.Harness;
66
using Microsoft.Extensions.AI;
77
using System.ComponentModel;
8+
using System.Text.Json;
9+
using System.Text.Json.Serialization;
810
using Xunit;
911
using Xunit.Abstractions;
1012

1113
namespace GitHub.Copilot.SDK.Test;
1214

1315
public class ToolResultsTests(E2ETestFixture fixture, ITestOutputHelper output) : E2ETestBase(fixture, "tool_results", output)
1416
{
17+
[JsonSourceGenerationOptions(JsonSerializerDefaults.Web)]
18+
[JsonSerializable(typeof(ToolResultAIContent))]
19+
[JsonSerializable(typeof(ToolResultObject))]
20+
[JsonSerializable(typeof(JsonElement))]
21+
private partial class ToolResultsJsonContext : JsonSerializerContext;
22+
1523
[Fact]
1624
public async Task Should_Handle_Structured_ToolResultObject_From_Custom_Tool()
1725
{
1826
var session = await CreateSessionAsync(new SessionConfig
1927
{
20-
Tools = [AIFunctionFactory.Create(GetWeather, "get_weather")],
28+
Tools = [AIFunctionFactory.Create(GetWeather, "get_weather", serializerOptions: ToolResultsJsonContext.Default.Options)],
2129
OnPermissionRequest = PermissionHandler.ApproveAll,
2230
});
2331

@@ -44,7 +52,7 @@ public async Task Should_Handle_Tool_Result_With_Failure_ResultType()
4452
{
4553
var session = await CreateSessionAsync(new SessionConfig
4654
{
47-
Tools = [AIFunctionFactory.Create(CheckStatus, "check_status")],
55+
Tools = [AIFunctionFactory.Create(CheckStatus, "check_status", serializerOptions: ToolResultsJsonContext.Default.Options)],
4856
OnPermissionRequest = PermissionHandler.ApproveAll,
4957
});
5058

@@ -72,7 +80,7 @@ public async Task Should_Preserve_ToolTelemetry_And_Not_Stringify_Structured_Res
7280
{
7381
var session = await CreateSessionAsync(new SessionConfig
7482
{
75-
Tools = [AIFunctionFactory.Create(AnalyzeCode, "analyze_code")],
83+
Tools = [AIFunctionFactory.Create(AnalyzeCode, "analyze_code", serializerOptions: ToolResultsJsonContext.Default.Options)],
7684
OnPermissionRequest = PermissionHandler.ApproveAll,
7785
});
7886

python/e2e/test_tool_results.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ def get_weather(params: WeatherParams, invocation: ToolInvocation) -> ToolResult
3232

3333
await session.send("What's the weather in Paris?")
3434
assistant_message = await get_final_assistant_message(session)
35-
assert "sunny" in assistant_message.data.content.lower() or "72" in assistant_message.data.content
35+
assert (
36+
"sunny" in assistant_message.data.content.lower()
37+
or "72" in assistant_message.data.content
38+
)
3639

37-
async def test_should_handle_tool_result_with_failure_resulttype(
38-
self, ctx: E2ETestContext
39-
):
40+
async def test_should_handle_tool_result_with_failure_resulttype(self, ctx: E2ETestContext):
4041
@define_tool("check_status", description="Checks the status of a service")
4142
def check_status(invocation: ToolInvocation) -> ToolResult:
4243
return ToolResult(
@@ -83,9 +84,7 @@ def analyze_code(params: AnalyzeParams, invocation: ToolInvocation) -> ToolResul
8384
# Verify the LLM received just textResultForLlm, not stringified JSON
8485
traffic = await ctx.get_exchanges()
8586
last_conversation = traffic[-1]
86-
tool_results = [
87-
m for m in last_conversation["request"]["messages"] if m["role"] == "tool"
88-
]
87+
tool_results = [m for m in last_conversation["request"]["messages"] if m["role"] == "tool"]
8988
assert len(tool_results) == 1
9089
assert "toolTelemetry" not in tool_results[0]["content"]
9190
assert "resultType" not in tool_results[0]["content"]

0 commit comments

Comments
 (0)