Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.Net: Rename OnNewMessage callback to OnIntermediateMessage #11328

Merged
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
2 changes: 1 addition & 1 deletion dotnet/samples/Concepts/Agents/AzureAIAgent_Streaming.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ Task OnNewMessage(ChatMessageContent message)

bool isFirst = false;
bool isCode = false;
await foreach (StreamingChatMessageContent response in agent.InvokeStreamingAsync(message, agentThread, new AgentInvokeOptions() { OnNewMessage = OnNewMessage }))
await foreach (StreamingChatMessageContent response in agent.InvokeStreamingAsync(message, agentThread, new AgentInvokeOptions() { OnIntermediateMessage = OnNewMessage }))
{
if (string.IsNullOrEmpty(response.Content))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Task OnNewMessage(ChatMessageContent message)

bool isFirst = false;
bool isCode = false;
await foreach (StreamingChatMessageContent response in agent.InvokeStreamingAsync(message, agentThread, new() { OnNewMessage = OnNewMessage }))
await foreach (StreamingChatMessageContent response in agent.InvokeStreamingAsync(message, agentThread, new() { OnIntermediateMessage = OnNewMessage }))
{
if (string.IsNullOrEmpty(response.Content))
{
Expand Down
4 changes: 2 additions & 2 deletions dotnet/src/Agents/Abstractions/AgentInvokeOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public AgentInvokeOptions(AgentInvokeOptions options)
this.KernelArguments = options.KernelArguments;
this.Kernel = options.Kernel;
this.AdditionalInstructions = options.AdditionalInstructions;
this.OnNewMessage = options.OnNewMessage;
this.OnIntermediateMessage = options.OnIntermediateMessage;
}

/// <summary>
Expand Down Expand Up @@ -56,5 +56,5 @@ public AgentInvokeOptions(AgentInvokeOptions options)
/// when invoking the agent with streaming.
/// </para>
/// </remarks>
public Func<ChatMessageContent, Task>? OnNewMessage { get; init; } = null;
public Func<ChatMessageContent, Task>? OnIntermediateMessage { get; init; } = null;
}
8 changes: 4 additions & 4 deletions dotnet/src/Agents/AzureAI/AzureAIAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,9 @@ async IAsyncEnumerable<ChatMessageContent> InternalInvokeAsync()
{
// The thread and the caller should be notified of all messages regardless of visibility.
await this.NotifyThreadOfNewMessage(azureAIAgentThread, message, cancellationToken).ConfigureAwait(false);
if (options?.OnNewMessage is not null)
if (options?.OnIntermediateMessage is not null)
{
await options.OnNewMessage(message).ConfigureAwait(false);
await options.OnIntermediateMessage(message).ConfigureAwait(false);
}

if (isVisible)
Expand Down Expand Up @@ -328,9 +328,9 @@ public async IAsyncEnumerable<AgentResponseItem<StreamingChatMessageContent>> In
{
await this.NotifyThreadOfNewMessage(azureAIAgentThread, newMessage, cancellationToken).ConfigureAwait(false);

if (options?.OnNewMessage is not null)
if (options?.OnIntermediateMessage is not null)
{
await options.OnNewMessage(newMessage).ConfigureAwait(false);
await options.OnIntermediateMessage(newMessage).ConfigureAwait(false);
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions dotnet/src/Agents/Core/ChatCompletionAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,9 @@ public override async IAsyncEnumerable<AgentResponseItem<ChatMessageContent>> In
async (m) =>
{
await this.NotifyThreadOfNewMessage(chatHistoryAgentThread, m, cancellationToken).ConfigureAwait(false);
if (options?.OnNewMessage is not null)
if (options?.OnIntermediateMessage is not null)
{
await options.OnNewMessage(m).ConfigureAwait(false);
await options.OnIntermediateMessage(m).ConfigureAwait(false);
}
},
options?.KernelArguments,
Expand Down Expand Up @@ -115,9 +115,9 @@ public override async IAsyncEnumerable<AgentResponseItem<ChatMessageContent>> In
{
await this.NotifyThreadOfNewMessage(chatHistoryAgentThread, result, cancellationToken).ConfigureAwait(false);

if (options?.OnNewMessage is not null)
if (options?.OnIntermediateMessage is not null)
{
await options.OnNewMessage(result).ConfigureAwait(false);
await options.OnIntermediateMessage(result).ConfigureAwait(false);
}
}

Expand Down Expand Up @@ -169,9 +169,9 @@ public override async IAsyncEnumerable<AgentResponseItem<StreamingChatMessageCon
async (m) =>
{
await this.NotifyThreadOfNewMessage(chatHistoryAgentThread, m, cancellationToken).ConfigureAwait(false);
if (options?.OnNewMessage is not null)
if (options?.OnIntermediateMessage is not null)
{
await options.OnNewMessage(m).ConfigureAwait(false);
await options.OnIntermediateMessage(m).ConfigureAwait(false);
}
},
options?.KernelArguments,
Expand Down
8 changes: 4 additions & 4 deletions dotnet/src/Agents/OpenAI/OpenAIAssistantAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,9 +430,9 @@ async IAsyncEnumerable<ChatMessageContent> InternalInvokeAsync()
{
// The thread and the caller should be notified of all messages regardless of visibility.
await this.NotifyThreadOfNewMessage(openAIAssistantAgentThread, message, cancellationToken).ConfigureAwait(false);
if (options?.OnNewMessage is not null)
if (options?.OnIntermediateMessage is not null)
{
await options.OnNewMessage(message).ConfigureAwait(false);
await options.OnIntermediateMessage(message).ConfigureAwait(false);
}

if (isVisible)
Expand Down Expand Up @@ -580,9 +580,9 @@ public async IAsyncEnumerable<AgentResponseItem<StreamingChatMessageContent>> In
{
await this.NotifyThreadOfNewMessage(openAIAssistantAgentThread, newMessage, cancellationToken).ConfigureAwait(false);

if (options?.OnNewMessage is not null)
if (options?.OnIntermediateMessage is not null)
{
await options.OnNewMessage(newMessage).ConfigureAwait(false);
await options.OnIntermediateMessage(newMessage).ConfigureAwait(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public virtual async Task InvokeWithPluginAndManualInvokeAsync()
options: new()
{
KernelArguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(autoInvoke: false) }),
OnNewMessage = (message) =>
OnIntermediateMessage = (message) =>
{
notifiedMessages.Add(message);
return Task.CompletedTask;
Expand Down Expand Up @@ -63,7 +63,7 @@ public virtual async Task InvokeWithPluginAndManualInvokeAsync()
options: new()
{
KernelArguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto(autoInvoke: false) }),
OnNewMessage = (message) =>
OnIntermediateMessage = (message) =>
{
notifiedMessages.Add(message);
return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ public virtual async Task InvokeWithPluginNotifiesForAllMessagesAsync()
options: new()
{
KernelArguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }),
OnNewMessage = (message) =>
OnIntermediateMessage = (message) =>
{
notifiedMessages.Add(message);
return Task.CompletedTask;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public virtual async Task InvokeStreamingWithPluginNotifiesForAllMessagesAsync()
options: new()
{
KernelArguments = new KernelArguments(new PromptExecutionSettings() { FunctionChoiceBehavior = FunctionChoiceBehavior.Auto() }),
OnNewMessage = (message) =>
OnIntermediateMessage = (message) =>
{
notifiedMessages.Add(message);
return Task.CompletedTask;
Expand Down
Loading