Skip to content

Commit 3b597fe

Browse files
westey-mglorious-beard
authored andcommitted
.Net: Rename OnNewMessage callback to OnIntermediateMessage (microsoft#11328)
### Motivation and Context A concern was raised bout confusion between OnNewMessage on the thread and on the invoke options, so renaming the invoke option callback to try and avoid confusion. ### Description Rename OnNewMessage callback to OnIntermediateMessage ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [ ] The code builds clean without any errors or warnings - [ ] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [ ] All unit tests pass, and I have added new tests where possible - [ ] I didn't break anyone 😄
1 parent 5f96156 commit 3b597fe

File tree

9 files changed

+22
-22
lines changed

9 files changed

+22
-22
lines changed

dotnet/samples/Concepts/Agents/AzureAIAgent_Streaming.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ Task OnNewMessage(ChatMessageContent message)
111111

112112
bool isFirst = false;
113113
bool isCode = false;
114-
await foreach (StreamingChatMessageContent response in agent.InvokeStreamingAsync(message, agentThread, new AgentInvokeOptions() { OnNewMessage = OnNewMessage }))
114+
await foreach (StreamingChatMessageContent response in agent.InvokeStreamingAsync(message, agentThread, new AgentInvokeOptions() { OnIntermediateMessage = OnNewMessage }))
115115
{
116116
if (string.IsNullOrEmpty(response.Content))
117117
{

dotnet/samples/Concepts/Agents/OpenAIAssistant_Streaming.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ Task OnNewMessage(ChatMessageContent message)
107107

108108
bool isFirst = false;
109109
bool isCode = false;
110-
await foreach (StreamingChatMessageContent response in agent.InvokeStreamingAsync(message, agentThread, new() { OnNewMessage = OnNewMessage }))
110+
await foreach (StreamingChatMessageContent response in agent.InvokeStreamingAsync(message, agentThread, new() { OnIntermediateMessage = OnNewMessage }))
111111
{
112112
if (string.IsNullOrEmpty(response.Content))
113113
{

dotnet/src/Agents/Abstractions/AgentInvokeOptions.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public AgentInvokeOptions(AgentInvokeOptions options)
2828
this.KernelArguments = options.KernelArguments;
2929
this.Kernel = options.Kernel;
3030
this.AdditionalInstructions = options.AdditionalInstructions;
31-
this.OnNewMessage = options.OnNewMessage;
31+
this.OnIntermediateMessage = options.OnIntermediateMessage;
3232
}
3333

3434
/// <summary>
@@ -56,5 +56,5 @@ public AgentInvokeOptions(AgentInvokeOptions options)
5656
/// when invoking the agent with streaming.
5757
/// </para>
5858
/// </remarks>
59-
public Func<ChatMessageContent, Task>? OnNewMessage { get; init; } = null;
59+
public Func<ChatMessageContent, Task>? OnIntermediateMessage { get; init; } = null;
6060
}

dotnet/src/Agents/AzureAI/AzureAIAgent.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ async IAsyncEnumerable<ChatMessageContent> InternalInvokeAsync()
205205
{
206206
// The thread and the caller should be notified of all messages regardless of visibility.
207207
await this.NotifyThreadOfNewMessage(azureAIAgentThread, message, cancellationToken).ConfigureAwait(false);
208-
if (options?.OnNewMessage is not null)
208+
if (options?.OnIntermediateMessage is not null)
209209
{
210-
await options.OnNewMessage(message).ConfigureAwait(false);
210+
await options.OnIntermediateMessage(message).ConfigureAwait(false);
211211
}
212212

213213
if (isVisible)
@@ -326,9 +326,9 @@ public async IAsyncEnumerable<AgentResponseItem<StreamingChatMessageContent>> In
326326
{
327327
await this.NotifyThreadOfNewMessage(azureAIAgentThread, newMessage, cancellationToken).ConfigureAwait(false);
328328

329-
if (options?.OnNewMessage is not null)
329+
if (options?.OnIntermediateMessage is not null)
330330
{
331-
await options.OnNewMessage(newMessage).ConfigureAwait(false);
331+
await options.OnIntermediateMessage(newMessage).ConfigureAwait(false);
332332
}
333333
}
334334
}

dotnet/src/Agents/Core/ChatCompletionAgent.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ public override async IAsyncEnumerable<AgentResponseItem<ChatMessageContent>> In
8686
async (m) =>
8787
{
8888
await this.NotifyThreadOfNewMessage(chatHistoryAgentThread, m, cancellationToken).ConfigureAwait(false);
89-
if (options?.OnNewMessage is not null)
89+
if (options?.OnIntermediateMessage is not null)
9090
{
91-
await options.OnNewMessage(m).ConfigureAwait(false);
91+
await options.OnIntermediateMessage(m).ConfigureAwait(false);
9292
}
9393
},
9494
options?.KernelArguments,
@@ -116,9 +116,9 @@ public override async IAsyncEnumerable<AgentResponseItem<ChatMessageContent>> In
116116
{
117117
await this.NotifyThreadOfNewMessage(chatHistoryAgentThread, result, cancellationToken).ConfigureAwait(false);
118118

119-
if (options?.OnNewMessage is not null)
119+
if (options?.OnIntermediateMessage is not null)
120120
{
121-
await options.OnNewMessage(result).ConfigureAwait(false);
121+
await options.OnIntermediateMessage(result).ConfigureAwait(false);
122122
}
123123
}
124124

@@ -170,9 +170,9 @@ public override async IAsyncEnumerable<AgentResponseItem<StreamingChatMessageCon
170170
async (m) =>
171171
{
172172
await this.NotifyThreadOfNewMessage(chatHistoryAgentThread, m, cancellationToken).ConfigureAwait(false);
173-
if (options?.OnNewMessage is not null)
173+
if (options?.OnIntermediateMessage is not null)
174174
{
175-
await options.OnNewMessage(m).ConfigureAwait(false);
175+
await options.OnIntermediateMessage(m).ConfigureAwait(false);
176176
}
177177
},
178178
options?.KernelArguments,

dotnet/src/Agents/OpenAI/OpenAIAssistantAgent.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -430,9 +430,9 @@ async IAsyncEnumerable<ChatMessageContent> InternalInvokeAsync()
430430
{
431431
// The thread and the caller should be notified of all messages regardless of visibility.
432432
await this.NotifyThreadOfNewMessage(openAIAssistantAgentThread, message, cancellationToken).ConfigureAwait(false);
433-
if (options?.OnNewMessage is not null)
433+
if (options?.OnIntermediateMessage is not null)
434434
{
435-
await options.OnNewMessage(message).ConfigureAwait(false);
435+
await options.OnIntermediateMessage(message).ConfigureAwait(false);
436436
}
437437

438438
if (isVisible)
@@ -578,9 +578,9 @@ public async IAsyncEnumerable<AgentResponseItem<StreamingChatMessageContent>> In
578578
{
579579
await this.NotifyThreadOfNewMessage(openAIAssistantAgentThread, newMessage, cancellationToken).ConfigureAwait(false);
580580

581-
if (options?.OnNewMessage is not null)
581+
if (options?.OnIntermediateMessage is not null)
582582
{
583-
await options.OnNewMessage(newMessage).ConfigureAwait(false);
583+
await options.OnIntermediateMessage(newMessage).ConfigureAwait(false);
584584
}
585585
}
586586
}

dotnet/src/IntegrationTests/Agents/CommonInterfaceConformance/InvokeConformance/ChatCompletionAgentInvokeTests.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public virtual async Task InvokeWithPluginAndManualInvokeAsync()
3535
options: new()
3636
{
3737
KernelArguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(autoInvoke: false) }),
38-
OnNewMessage = (message) =>
38+
OnIntermediateMessage = (message) =>
3939
{
4040
notifiedMessages.Add(message);
4141
return Task.CompletedTask;
@@ -63,7 +63,7 @@ public virtual async Task InvokeWithPluginAndManualInvokeAsync()
6363
options: new()
6464
{
6565
KernelArguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(autoInvoke: false) }),
66-
OnNewMessage = (message) =>
66+
OnIntermediateMessage = (message) =>
6767
{
6868
notifiedMessages.Add(message);
6969
return Task.CompletedTask;

dotnet/src/IntegrationTests/Agents/CommonInterfaceConformance/InvokeConformance/InvokeTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public virtual async Task InvokeWithPluginNotifiesForAllMessagesAsync()
170170
options: new()
171171
{
172172
KernelArguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }),
173-
OnNewMessage = (message) =>
173+
OnIntermediateMessage = (message) =>
174174
{
175175
notifiedMessages.Add(message);
176176
return Task.CompletedTask;

dotnet/src/IntegrationTests/Agents/CommonInterfaceConformance/InvokeStreamingConformance/InvokeStreamingTests.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ public virtual async Task InvokeStreamingWithPluginNotifiesForAllMessagesAsync()
175175
options: new()
176176
{
177177
KernelArguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }),
178-
OnNewMessage = (message) =>
178+
OnIntermediateMessage = (message) =>
179179
{
180180
notifiedMessages.Add(message);
181181
return Task.CompletedTask;

0 commit comments

Comments
 (0)