Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion dotnet/test/E2E/SessionLifecycleE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public async Task Should_List_Created_Sessions_After_Sending_A_Message()

// Sessions must have activity to be persisted to disk
await session1.SendAndWaitAsync(new MessageOptions { Prompt = "Say hello" });
await session2.SendAndWaitAsync(new MessageOptions { Prompt = "Say world" });
await session2.SendAndWaitAsync(new MessageOptions { Prompt = "Say hi" });
Comment thread
Copilot marked this conversation as resolved.
Outdated

IList<SessionMetadata>? sessions = null;
await TestHelper.WaitForConditionAsync(
Expand Down
53 changes: 53 additions & 0 deletions dotnet/test/E2E/ToolsE2ETests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,59 @@ static string EncryptString([Description("String to encrypt")] string input)
=> input.ToUpperInvariant();
}

[Fact]
public async Task Low_Level_Tool_Definition()
{
string currentPhase = string.Empty;

var session = await CreateSessionAsync(new SessionConfig
{
Tools =
[
AIFunctionFactory.Create(SetCurrentPhase, new AIFunctionFactoryOptions
{
Name = "set_current_phase",
Description = "Sets the current phase of the agent",
}),
AIFunctionFactory.Create(SearchItems, new AIFunctionFactoryOptions
{
Name = "search_items",
Description = "Search for items by keyword",
}),
],
AvailableTools = new ToolSet().AddCustom("*").AddBuiltIn("web_fetch"),
OnPermissionRequest = PermissionHandler.ApproveAll,
});

await session.SendAsync(new MessageOptions
{
Prompt = "First, set the current phase to 'analyzing'. Then search for items with keyword 'copilot'. Report the phase and search results."
});

var assistantMessage = await TestHelper.GetFinalAssistantMessageAsync(session);

Assert.NotNull(assistantMessage);
var content = assistantMessage!.Data.Content ?? string.Empty;
Assert.NotEmpty(content);
Assert.Contains("analyzing", content, StringComparison.OrdinalIgnoreCase);
Assert.True(content.Contains("item_alpha", StringComparison.OrdinalIgnoreCase)
|| content.Contains("item_beta", StringComparison.OrdinalIgnoreCase),
$"Expected content to mention item_alpha or item_beta, got: {content}");
Assert.Equal("analyzing", currentPhase);

Task<string> SetCurrentPhase(string phase)
{
currentPhase = phase;
return Task.FromResult($"Phase set to {phase}");
}

Task<string> SearchItems(AIFunctionArguments args)
{
Assert.Equal("copilot", args["keyword"]?.ToString());
return Task.FromResult("Found: item_alpha, item_beta");
}
}

[Fact]
public async Task Handles_Tool_Calling_Errors()
{
Expand Down
Loading