-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Labels
0.2Issues which are related to the pre 0.4 codebaseIssues which are related to the pre 0.4 codebase
Description
[autogen/agentchat/contrib/capabilities/transforms.py](https://github.com/microsoft/autogen/blob/0.2/autogen/agentchat/contrib/capabilities/transforms.py)
In MessageHistoryLimiter, line 99 of the file.
It should take _keep_first_message into consider. otherwise when keep_first_message==False , the last message will be inserted in a wrong place.
# Loop through messages in reverse
for i in range(len(messages) - 1, 0, -1):
if remaining_count > 1:
truncated_messages.insert(1 if self._keep_first_message else 0, messages[i])
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])
for example, following code output is in wrong order
from autogen.agentchat.contrib.capabilities import transform_messages, transforms
limiter=transforms.MessageHistoryLimiter(max_messages=3, keep_first_message=False)
limiter.apply_transform([{'role':'user', 'name':'agent', 'content':'0'},
{'role':'user', 'name':'agent', 'content':'1'},
{'role':'user', 'name':'agent', 'content':'2'},
{'role':'user', 'name':'agent', 'content':'3'},
{'role':'user', 'name':'agent', 'content':'4'},
])
[{'role': 'user', 'name': 'agent', 'content': '3'},
{'role': 'user', 'name': 'agent', 'content': '2'},
{'role': 'user', 'name': 'agent', 'content': '4'}]
Originally posted by @milkmeat in #3178 (comment)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
0.2Issues which are related to the pre 0.4 codebaseIssues which are related to the pre 0.4 codebase