From e90b9aa92678d7e7cc418510d3c981cbe4622241 Mon Sep 17 00:00:00 2001 From: milkmeat Date: Thu, 12 Dec 2024 09:33:57 +0800 Subject: [PATCH] fix "keep_first_message" to make sure messages are in correct order, (#4653) described in https://github.com/microsoft/autogen/pull/3178#issuecomment-2530740564 Co-authored-by: Eric Zhu --- autogen/agentchat/contrib/capabilities/transforms.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/autogen/agentchat/contrib/capabilities/transforms.py b/autogen/agentchat/contrib/capabilities/transforms.py index ad00d7380db6..c559cf5f7483 100644 --- a/autogen/agentchat/contrib/capabilities/transforms.py +++ b/autogen/agentchat/contrib/capabilities/transforms.py @@ -96,7 +96,7 @@ def apply_transform(self, messages: List[Dict]) -> List[Dict]: if remaining_count == 1: # If there's only 1 slot left and it's a 'tools' message, ignore it. if messages[i].get("role") != "tool": - truncated_messages.insert(1, messages[i]) + truncated_messages.insert(1 if self._keep_first_message else 0, messages[i]) remaining_count -= 1 if remaining_count == 0: