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: Repeated ChatHistory.AddStreamingMessageAsync(GetStreamingChatMessageContentsAsync) throws ClientResultException #9458

Open
Hassmann opened this issue Oct 29, 2024 · 1 comment
Assignees
Labels
ai connector Anything related to AI connectors bug Something isn't working .NET Issue or Pull requests regarding .NET code

Comments

@Hassmann
Copy link

Describe the bug

When using the streaming API with automatic tool calls like this:

// Create Kernel
var kernel = Kernel.CreateBuilder()
	.AddAzureOpenAIChatCompletion(deployment, client)
	.Build();

kernel.ImportPluginFromObject(new Functions());

// Prepare Chat
var chatService = kernel.GetRequiredService<IChatCompletionService>();

OpenAIPromptExecutionSettings settings = new()
{
	FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};

ChatHistory chatHistory = new("You are to test the system");

for (int i = 0; i < 2; i++)
{
	try
	{
		chatHistory.AddUserMessage("Please test the system");

		var results = chatHistory.AddStreamingMessageAsync(chatService
			.GetStreamingChatMessageContentsAsync(chatHistory, settings, kernel)
			.Cast<OpenAIStreamingChatMessageContent>()
		);

		await foreach (var result in results)
		{
			Console.Write(result.ToString());
		}

		Console.WriteLine($"Call #{i} OK");
	}
	catch (Exception e)
	{
		// On 2nd call...
		Console.WriteLine("ERROR: " + e.Message);
	}
}

a second call after the assistant has actually invoked a function will throw a ClientResultException with:

HTTP 400 (invalid_request_error: )
Parameter: messages.[5].role

An assistant message with 'tool_calls' must be followed by tool messages responding to each 'tool_call_id'. The following tool_call_ids did not have response messages: call_MnrWYfXsn1cz6RgiUi44acoy

To Reproduce
I have attached a small Console app that reproduces the issue.
ToolCallBug.zip

Platform

  • OS: Windows, Azure OpenAI (GPT4o)
  • IDE: Visual Studio
  • Language: C#
  • Source: Microsoft.SemanticKernel 1.25.0
@Hassmann Hassmann added the bug Something isn't working label Oct 29, 2024
@markwallace-microsoft markwallace-microsoft added .NET Issue or Pull requests regarding .NET code triage labels Oct 29, 2024
@github-actions github-actions bot changed the title .NET: Repeated ChatHistory.AddStreamingMessageAsync(GetStreamingChatMessageContentsAsync) throws ClientResultException .Net: Repeated ChatHistory.AddStreamingMessageAsync(GetStreamingChatMessageContentsAsync) throws ClientResultException Oct 29, 2024
@RogerBarreto RogerBarreto self-assigned this Oct 31, 2024
@RogerBarreto RogerBarreto added ai connector Anything related to AI connectors and removed triage labels Oct 31, 2024
@evchaki
Copy link
Contributor

evchaki commented Oct 31, 2024

@Hassmann - thanks for reporting this, we will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai connector Anything related to AI connectors bug Something isn't working .NET Issue or Pull requests regarding .NET code
Projects
Status: Bug
Development

No branches or pull requests

4 participants