Skip to content

Commit 0c8bc3e

Browse files
stephentoubRussKie
andauthored
Flip default on FunctionInvokingChatClient.ConcurrentInvocation (#5485)
* Flip default on FunctionInvokingChatClient.ConcurrentInvocation For better reliability, default ConcurrentInvocation to false, so that it doesn't introduce concurrency / parallelism where there wasn't any. * Update src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs Co-authored-by: Igor Velikorossov <[email protected]> --------- Co-authored-by: Igor Velikorossov <[email protected]>
1 parent 331ddb5 commit 0c8bc3e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/Libraries/Microsoft.Extensions.AI/ChatCompletion/FunctionInvokingChatClient.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,14 @@ public FunctionInvokingChatClient(IChatClient innerClient)
8282
/// <remarks>
8383
/// <para>
8484
/// An individual response from the inner client may contain multiple function call requests.
85-
/// By default, such function calls may be issued to execute concurrently with each other. Set
86-
/// <see cref="ConcurrentInvocation"/> to false to disable such concurrent invocation and force
87-
/// the functions to be invoked serially.
85+
/// By default, such function calls are processed serially. Set <see cref="ConcurrentInvocation"/> to
86+
/// <see langword="true"/> to enable concurrent invocation such that multiple function calls may execute in parallel.
8887
/// </para>
8988
/// <para>
90-
/// The default value is <see langword="true"/>.
89+
/// The default value is <see langword="false"/>.
9190
/// </para>
9291
/// </remarks>
93-
public bool ConcurrentInvocation { get; set; } = true;
92+
public bool ConcurrentInvocation { get; set; }
9493

9594
/// <summary>
9695
/// Gets or sets a value indicating whether to keep intermediate messages in the chat history.

test/Libraries/Microsoft.Extensions.AI.Tests/ChatCompletion/FunctionInvokingChatClientTests.cs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@ namespace Microsoft.Extensions.AI;
1212

1313
public class FunctionInvokingChatClientTests
1414
{
15+
[Fact]
16+
public void Ctor_HasExpectedDefaults()
17+
{
18+
using TestChatClient innerClient = new();
19+
using FunctionInvokingChatClient client = new(innerClient);
20+
21+
Assert.False(client.ConcurrentInvocation);
22+
Assert.False(client.DetailedErrors);
23+
Assert.True(client.KeepFunctionCallingMessages);
24+
Assert.Null(client.MaximumIterationsPerRequest);
25+
Assert.False(client.RetryOnError);
26+
}
27+
1528
[Fact]
1629
public async Task SupportsSingleFunctionCallPerRequestAsync()
1730
{
@@ -71,7 +84,7 @@ await InvokeAndAssertAsync(options, [
7184
}
7285

7386
[Fact]
74-
public async Task ParallelFunctionCallsInvokedConcurrentlyByDefaultAsync()
87+
public async Task ParallelFunctionCallsMayBeInvokedConcurrentlyAsync()
7588
{
7689
using var barrier = new Barrier(2);
7790

@@ -97,11 +110,11 @@ await InvokeAndAssertAsync(options, [
97110
new FunctionResultContent("callId2", "Func", result: "worldworld"),
98111
]),
99112
new ChatMessage(ChatRole.Assistant, "done"),
100-
]);
113+
], configurePipeline: b => b.Use(s => new FunctionInvokingChatClient(s) { ConcurrentInvocation = true }));
101114
}
102115

103116
[Fact]
104-
public async Task ConcurrentInvocationOfParallelCallsCanBeDisabledAsync()
117+
public async Task ConcurrentInvocationOfParallelCallsDisabledByDefaultAsync()
105118
{
106119
int activeCount = 0;
107120

@@ -130,7 +143,7 @@ await InvokeAndAssertAsync(options, [
130143
new FunctionResultContent("callId2", "Func", result: "worldworld"),
131144
]),
132145
new ChatMessage(ChatRole.Assistant, "done"),
133-
], configurePipeline: b => b.Use(s => new FunctionInvokingChatClient(s) { ConcurrentInvocation = false }));
146+
]);
134147
}
135148

136149
[Theory]

0 commit comments

Comments
 (0)