Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,14 @@ internal static ResponseCreationOptions CreateOptions(
if (responseTools is not null && responseTools.Any())
{
creationOptions.Tools.AddRange(responseTools);
creationOptions.ToolChoice = ResponseToolChoice.CreateAutoChoice();
creationOptions.ParallelToolCallsEnabled = true;
if (creationOptions.ToolChoice == null)
{
creationOptions.ToolChoice = ResponseToolChoice.CreateAutoChoice();
}
if (!creationOptions.ParallelToolCallsEnabled.HasValue)
{
creationOptions.ParallelToolCallsEnabled = true;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}

return creationOptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,60 @@ public void CreateOptionsWithNullAgentNameTest()
Assert.Equal("UnnamedAgent", options.EndUserId); // Null name should fallback to "UnnamedAgent"
}

/// <summary>
/// Verify response options creation with kernel plugin and default response options.
/// </summary>
[Fact]
public void CreateOptionsWithKernelPluginAndDefaultOptionsTest()
{
// Arrange
var mockAgent = CreateMockAgent("Test Agent", "You are a helpful assistant.", storeEnabled: false);
var mockThread = CreateMockAgentThread(null);
mockAgent.Kernel.Plugins.AddFromObject(new TestPlugin());

// Act
var options = ResponseCreationOptionsFactory.CreateOptions(mockAgent, mockThread.Object, null);

// Assert
Assert.NotNull(options);
Assert.Single(options.Tools);
Assert.NotNull(options.ToolChoice);
Assert.Equal(ResponseToolChoiceKind.Auto, options.ToolChoice.Kind);
Assert.True(options.ParallelToolCallsEnabled);
}

/// <summary>
/// Verify response options creation with kernel plugin and custom response options.
/// </summary>
[Fact]
public void CreateOptionsWithKernelPluginAndCustomOptionsTest()
{
// Arrange
var mockAgent = CreateMockAgent("Test Agent", "You are a helpful assistant.", storeEnabled: false);
var mockThread = CreateMockAgentThread(null);
mockAgent.Kernel.Plugins.AddFromObject(new TestPlugin());

// Custom invoke options should be respected
var invokeOptions = new OpenAIResponseAgentInvokeOptions
{
ResponseCreationOptions = new ResponseCreationOptions
{
ToolChoice = ResponseToolChoice.CreateNoneChoice(),
ParallelToolCallsEnabled = false
}
};

// Act
var options = ResponseCreationOptionsFactory.CreateOptions(mockAgent, mockThread.Object, invokeOptions);

// Assert
Assert.NotNull(options);
Assert.Single(options.Tools);
Assert.NotNull(options.ToolChoice);
Assert.Equal(ResponseToolChoiceKind.None, options.ToolChoice.Kind);
Assert.False(options.ParallelToolCallsEnabled);
}

private static OpenAIResponseAgent CreateMockAgent(string? name, string? instructions, bool storeEnabled)
{
var mockClient = new Mock<OpenAIResponseClient>();
Expand All @@ -281,4 +335,11 @@ private static Mock<AgentThread> CreateMockAgentThread(string? threadId)
mockThread.Setup(t => t.Id).Returns(threadId);
return mockThread;
}

private sealed class TestPlugin
{
[KernelFunction]
public void TestFunction()
{ }
}
}
Loading