Add EndSessionTool (no params, returns ok; relay closes on this tool name)

This commit is contained in:
2026-06-11 21:21:13 +00:00
parent 9325d21f9e
commit ebbe23c639
2 changed files with 55 additions and 0 deletions
+35
View File
@@ -0,0 +1,35 @@
using System.Text.Json;
using backend.Tools;
using FluentAssertions;
using Xunit;
namespace backend.tests;
public class EndSessionToolTests
{
[Fact]
public async Task Returns_ok_true()
{
var tool = new EndSessionTool();
var ctx = new DeviceContext(Guid.NewGuid(), Guid.NewGuid(), new NoopChannel());
var res = await tool.ExecuteAsync(
new ToolInvocation("call_1", JsonDocument.Parse("{}").RootElement), ctx, default);
res.Output.GetProperty("ok").GetBoolean().Should().BeTrue();
}
[Fact]
public void Name_and_runs_during_response_match_spec()
{
var tool = new EndSessionTool();
tool.Name.Should().Be("end_session");
tool.RunsDuringResponse.Should().BeFalse();
}
private class NoopChannel : IDeviceChannel
{
public Task<JsonElement> CallPiToolAsync(string n, JsonElement a, CancellationToken ct)
=> throw new NotSupportedException();
}
}
+20
View File
@@ -0,0 +1,20 @@
using System.Text.Json;
namespace backend.Tools;
public class EndSessionTool : ITool
{
public string Name => "end_session";
public string Description =>
"Call this when the user has said goodbye or otherwise indicates the conversation is over.";
public bool RunsDuringResponse => false;
public JsonElement ParameterSchema { get; } =
JsonDocument.Parse("""{"type":"object","properties":{},"required":[]}""").RootElement;
public Task<ToolResult> ExecuteAsync(ToolInvocation invocation, DeviceContext device, CancellationToken ct)
{
var output = JsonDocument.Parse("""{"ok":true}""").RootElement;
return Task.FromResult(new ToolResult(output));
}
}