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

Closed
Hassmann opened this issue Oct 29, 2024 · 1 comment · Fixed by #9619
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.

github-merge-queue bot pushed a commit that referenced this issue Nov 8, 2024
### Motivation and Context

- Fixes #9458 
- Fixes #6153
@github-project-automation github-project-automation bot moved this from Sprint: In Review to Sprint: Done in Semantic Kernel Nov 8, 2024
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
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants