Skip to content

.Net: Change ChatCompletionAgent to notify intermediate messages as soon as they are available. #12575

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

Merged
Merged
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
19 changes: 10 additions & 9 deletions dotnet/src/Agents/Core/ChatCompletionAgent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ private async IAsyncEnumerable<StreamingChatMessageContent> InternalInvokeStream

this.Logger.LogAgentChatServiceInvokedStreamingAgent(nameof(InvokeAsync), this.Id, agentName, serviceType);

int messageIndex = messageCount;
AuthorRole? role = null;
StringBuilder builder = new();
await foreach (StreamingChatMessageContent message in messages.ConfigureAwait(false))
Expand All @@ -401,18 +402,18 @@ private async IAsyncEnumerable<StreamingChatMessageContent> InternalInvokeStream

builder.Append(message.ToString());

yield return message;
}
// Capture mutated messages related function calling / tools
for (; messageIndex < chat.Count; messageIndex++)
{
ChatMessageContent chatMessage = chat[messageIndex];

// Capture mutated messages related function calling / tools
for (int messageIndex = messageCount; messageIndex < chat.Count; messageIndex++)
{
ChatMessageContent message = chat[messageIndex];
chatMessage.AuthorName = this.Name;

message.AuthorName = this.Name;
await onNewMessage(chatMessage).ConfigureAwait(false);
history.Add(chatMessage);
}

await onNewMessage(message).ConfigureAwait(false);
history.Add(message);
yield return message;
}

// Do not duplicate terminated function result to history
Expand Down
Loading