-
Notifications
You must be signed in to change notification settings - Fork 4.2k
.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
.Net: Change ChatCompletionAgent to notify intermediate messages as soon as they are available. #12575
Conversation
… they are available.
Suggest adding a UT ensuring this behavior |
Sure, will look at this separately. |
@westey-m I still have this issue with the current version 1.60.0-preview of Microsoft.SemanticKernel.Agents.AzureAI public async IAsyncEnumerable<AgentStreamingContent> Prompt(
string prompt)
{
AzureAIAgent agent = await CreateAzureAIAgentWithTools().ConfigureAwait(false);
Channel<AgentStreamingContent> channel = Channel.CreateUnbounded<AgentStreamingContent>();
AzureAIAgentThread agentThread = new(agent.Client);
AgentInvokeOptions agentInvokeOptions = new()
{
AdditionalInstructions = toolOptionsText,
OnIntermediateMessage = (message) =>
{
foreach (KernelContent content in message.Items)
{
if (content is Microsoft.SemanticKernel.FunctionCallContent functionCallContent)
{
Console.WriteLine($"FunctionCallContent Plugin {functionCallContent.PluginName}, Function {functionCallContent.FunctionName}");
}
else if (content is Microsoft.SemanticKernel.FunctionResultContent functionResultContent)
{
Console.WriteLine($"FunctionCallContent Plugin {functionResultContent.PluginName}, Function {functionResultContent.FunctionName}");
}
else
{
// Handle other content types if necessary
}
}
return Task.CompletedTask;
}
};
async Task InvokeStreaming()
{
Microsoft.SemanticKernel.ChatMessageContent message = new(AuthorRole.User, prompt);
await foreach (StreamingChatMessageContent response in agent.InvokeStreamingAsync(message, agentThread, options: agentInvokeOptions).ConfigureAwait(false))
{
if (!string.IsNullOrEmpty(response.Content))
{
Console.WriteLine($"StreamingChatMessageContent {response.Content}");
}
}
}
Console.WriteLine($"Invoking streaming");
Task.Run(async () => await InvokeStreaming());
} |
@GrillPhil, this fix was on the ChatCompletionAgent, but it looks like you are using an AzureAIAgent here right? |
Yes exactly. The events come in the right order on AzureAIAgent when I user InvokeAsync but at the end when using the streaming API. |
Thanks @GrillPhil, I've opened a new bug to address this across all agent types. |
Motivation and Context
Addresses #12521
Contribution Checklist