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: