mirror of
https://github.com/microsoft/autogen.git
synced 2026-04-20 03:02:16 -04:00
Ability to add MessageTransforms to the GroupChat's Select Speaker nested chat (speaker_selection_method='auto') (#2719)
* Initial commit with ability to add transforms to GroupChat * Added tests * Tidy up * Tidy up of variable names and commented out test * Tidy up comment * Update import to relative * Added documentation topic for transform messages for speaker selection. * Added handling of non-core module, transforms, in groupchat * Adjusted parameter if module not loaded. * Updated groupchat test which failed during CI/CD --------- Co-authored-by: Li Jiang <bnujli@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@ from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST
|
||||
|
||||
import autogen
|
||||
from autogen import Agent, AssistantAgent, GroupChat, GroupChatManager
|
||||
from autogen.agentchat.contrib.capabilities import transform_messages, transforms
|
||||
from autogen.exception_utils import AgentNameConflict, UndefinedNextAgent
|
||||
|
||||
|
||||
@@ -2061,6 +2062,46 @@ def test_manager_resume_messages():
|
||||
return_agent, return_message = manager.resume(messages="Let's get this conversation started.")
|
||||
|
||||
|
||||
def test_select_speaker_transform_messages():
|
||||
"""Tests adding transform messages to a GroupChat for speaker selection when in 'auto' mode"""
|
||||
|
||||
# Test adding a TransformMessages to a group chat
|
||||
test_add_transforms = transform_messages.TransformMessages(
|
||||
transforms=[
|
||||
transforms.MessageHistoryLimiter(max_messages=10),
|
||||
transforms.MessageTokenLimiter(max_tokens=3000, max_tokens_per_message=500, min_tokens=300),
|
||||
]
|
||||
)
|
||||
|
||||
coder = AssistantAgent(name="Coder", llm_config=None)
|
||||
groupchat = GroupChat(messages=[], agents=[coder], select_speaker_transform_messages=test_add_transforms)
|
||||
|
||||
# Ensure the transform have been added to the GroupChat
|
||||
assert groupchat._speaker_selection_transforms == test_add_transforms
|
||||
|
||||
# Attempt to add a non MessageTransforms object, such as a list of transforms
|
||||
with pytest.raises(ValueError, match="select_speaker_transform_messages must be None or MessageTransforms."):
|
||||
groupchat = GroupChat(
|
||||
messages=[],
|
||||
agents=[coder],
|
||||
select_speaker_transform_messages=[transforms.MessageHistoryLimiter(max_messages=10)],
|
||||
)
|
||||
|
||||
# Ensure if we don't pass any transforms in, none are on the GroupChat
|
||||
groupchat_missing = GroupChat(messages=[], agents=[coder])
|
||||
|
||||
assert groupchat_missing._speaker_selection_transforms is None
|
||||
|
||||
# Ensure we can pass in None
|
||||
groupchat_none = GroupChat(
|
||||
messages=[],
|
||||
agents=[coder],
|
||||
select_speaker_transform_messages=None,
|
||||
)
|
||||
|
||||
assert groupchat_none._speaker_selection_transforms is None
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# test_func_call_groupchat()
|
||||
# test_broadcast()
|
||||
@@ -2089,4 +2130,5 @@ if __name__ == "__main__":
|
||||
test_manager_resume_functions()
|
||||
# test_manager_resume_returns()
|
||||
# test_manager_resume_messages()
|
||||
# test_select_speaker_transform_messages()
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user