microsoft / semantic-kernel

Integrate cutting-edge LLM technology quickly and easily into your apps
https://aka.ms/semantic-kernel
MIT License
20.56k stars 2.97k forks source link

.Net: Bug: AgenGroupChat yields function response messages when it shouldn't #7075

Open EdenTanami opened 1 week ago

EdenTanami commented 1 week ago

Describe the bug According to the code of the AgenGroupChat's base abstract class - AgentChat, the group chat InvokeAsync should add to the History all the messages yielded by the agent and return to its caler only the assistant response (not tools related messages). In practice, calling agentGroupChat.InvokeAsync returns both the final assistance response and the messages with tool role.

I reviewed the AgentChat code and saw that the condition of the returned messages is: image The if condition might be the problem - I saw that in my function response message there are 2 items, one isn't from the mentioned types- image

To Reproduce Steps to reproduce the behavior:

  1. Create an agent (ChatCompletionAgent) with kernel that contains plugin.
  2. Add the agent to a group chat.
  3. Add to the groupChat history user message that will trigger the the plugin.
  4. call the groupChat.InvokeAsync()
  5. See the tool message that returns.

Expected behavior Only final assistant response returns from the groupChat InvokeAsync.

Screenshots image

image

Platform OS: Windows IDE: Visual Studio, Language: C# Source: SK NuGet package version 1.15.0

crickman commented 1 week ago

I believe you'll find this issue has been resolved as part of:

https://github.com/microsoft/semantic-kernel/pull/6956

We are publishing a new nuget package today. Can you please retry and verify the current result?

I do see the original root cause here:

https://github.com/microsoft/semantic-kernel/blob/main/dotnet/src/Connectors/Connectors.OpenAI/AzureSdk/ClientCore.cs#L1454

It appears this logic was introduced a few weeks ago in this PR:

https://github.com/microsoft/semantic-kernel/pull/6449

Note: I plan bring the code you've highlighted into a consistent state as part of my active work stream...even though it should be effectively mitigated.