Skip to content

Commit c795282

Browse files
edburnsCopilot
andauthored
Add .NET low-level tool-definition E2E test [6/6] (#1728)
* Add .NET low-level tool-definition E2E test Related to issue #1682 but does not fix #1682. Align low_level_tool_definition coverage with PR #1721 snapshot behavior by only defining tools exercised by the shared snapshot. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix .NET session lifecycle replay mismatch in PR 1728 Restore the second lifecycle prompt to 'Say world' to match the existing session_lifecycle snapshot and avoid replay cache misses in CI. Related to issue #1682 but does not fix #1682. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 07fcf35 commit c795282

1 file changed

Lines changed: 53 additions & 0 deletions

File tree

dotnet/test/E2E/ToolsE2ETests.cs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,59 @@ static string EncryptString([Description("String to encrypt")] string input)
6161
=> input.ToUpperInvariant();
6262
}
6363

64+
[Fact]
65+
public async Task Low_Level_Tool_Definition()
66+
{
67+
string currentPhase = string.Empty;
68+
69+
var session = await CreateSessionAsync(new SessionConfig
70+
{
71+
Tools =
72+
[
73+
AIFunctionFactory.Create(SetCurrentPhase, new AIFunctionFactoryOptions
74+
{
75+
Name = "set_current_phase",
76+
Description = "Sets the current phase of the agent",
77+
}),
78+
AIFunctionFactory.Create(SearchItems, new AIFunctionFactoryOptions
79+
{
80+
Name = "search_items",
81+
Description = "Search for items by keyword",
82+
}),
83+
],
84+
AvailableTools = new ToolSet().AddCustom("*").AddBuiltIn("web_fetch"),
85+
OnPermissionRequest = PermissionHandler.ApproveAll,
86+
});
87+
88+
await session.SendAsync(new MessageOptions
89+
{
90+
Prompt = "First, set the current phase to 'analyzing'. Then search for items with keyword 'copilot'. Report the phase and search results."
91+
});
92+
93+
var assistantMessage = await TestHelper.GetFinalAssistantMessageAsync(session);
94+
95+
Assert.NotNull(assistantMessage);
96+
var content = assistantMessage!.Data.Content ?? string.Empty;
97+
Assert.NotEmpty(content);
98+
Assert.Contains("analyzing", content, StringComparison.OrdinalIgnoreCase);
99+
Assert.True(content.Contains("item_alpha", StringComparison.OrdinalIgnoreCase)
100+
|| content.Contains("item_beta", StringComparison.OrdinalIgnoreCase),
101+
$"Expected content to mention item_alpha or item_beta, got: {content}");
102+
Assert.Equal("analyzing", currentPhase);
103+
104+
Task<string> SetCurrentPhase(string phase)
105+
{
106+
currentPhase = phase;
107+
return Task.FromResult($"Phase set to {phase}");
108+
}
109+
110+
Task<string> SearchItems(AIFunctionArguments args)
111+
{
112+
Assert.Equal("copilot", args["keyword"]?.ToString());
113+
return Task.FromResult("Found: item_alpha, item_beta");
114+
}
115+
}
116+
64117
[Fact]
65118
public async Task Handles_Tool_Calling_Errors()
66119
{

0 commit comments

Comments
 (0)