|
5 | 5 | import json
|
6 | 6 | import logging
|
7 | 7 | from typing import Any, Dict, List, Optional
|
8 |
| -from unittest import mock |
| 8 | +from unittest import TestCase, mock |
9 | 9 |
|
10 | 10 | import pytest
|
| 11 | +from test_assistant_agent import KEY_LOC, OAI_CONFIG_LIST |
11 | 12 |
|
12 | 13 | import autogen
|
13 | 14 | from autogen import Agent, AssistantAgent, GroupChat, GroupChatManager
|
@@ -1446,6 +1447,46 @@ def test_speaker_selection_agent_name_match():
|
1446 | 1447 | assert result == {}
|
1447 | 1448 |
|
1448 | 1449 |
|
| 1450 | +def test_role_for_reflection_summary(): |
| 1451 | + llm_config = {"config_list": [{"model": "mock", "api_key": "mock"}]} |
| 1452 | + agent1 = autogen.ConversableAgent( |
| 1453 | + "alice", |
| 1454 | + max_consecutive_auto_reply=10, |
| 1455 | + human_input_mode="NEVER", |
| 1456 | + llm_config=False, |
| 1457 | + default_auto_reply="This is alice speaking.", |
| 1458 | + ) |
| 1459 | + agent2 = autogen.ConversableAgent( |
| 1460 | + "bob", |
| 1461 | + max_consecutive_auto_reply=10, |
| 1462 | + human_input_mode="NEVER", |
| 1463 | + llm_config=False, |
| 1464 | + default_auto_reply="This is bob speaking.", |
| 1465 | + ) |
| 1466 | + groupchat = autogen.GroupChat( |
| 1467 | + agents=[agent1, agent2], messages=[], max_round=3, speaker_selection_method="round_robin" |
| 1468 | + ) |
| 1469 | + group_chat_manager = autogen.GroupChatManager(groupchat=groupchat, llm_config=llm_config) |
| 1470 | + |
| 1471 | + role_name = "user" |
| 1472 | + with mock.patch.object( |
| 1473 | + autogen.ConversableAgent, "_generate_oai_reply_from_client" |
| 1474 | + ) as mock_generate_oai_reply_from_client: |
| 1475 | + mock_generate_oai_reply_from_client.return_value = "Mocked summary" |
| 1476 | + |
| 1477 | + agent1.initiate_chat( |
| 1478 | + group_chat_manager, |
| 1479 | + max_turns=2, |
| 1480 | + message="hello", |
| 1481 | + summary_method="reflection_with_llm", |
| 1482 | + summary_args={"summary_role": role_name}, |
| 1483 | + ) |
| 1484 | + |
| 1485 | + mock_generate_oai_reply_from_client.assert_called_once() |
| 1486 | + args, kwargs = mock_generate_oai_reply_from_client.call_args |
| 1487 | + assert kwargs["messages"][-1]["role"] == role_name |
| 1488 | + |
| 1489 | + |
1449 | 1490 | def test_speaker_selection_auto_process_result():
|
1450 | 1491 | """
|
1451 | 1492 | Tests the return result of the 2-agent chat used for speaker selection for the auto method.
|
@@ -1984,12 +2025,16 @@ def test_manager_resume_messages():
|
1984 | 2025 | # test_role_for_select_speaker_messages()
|
1985 | 2026 | # test_select_speaker_message_and_prompt_templates()
|
1986 | 2027 | # test_speaker_selection_agent_name_match()
|
| 2028 | + # test_role_for_reflection_summary() |
| 2029 | + # test_speaker_selection_auto_process_result() |
| 2030 | + # test_speaker_selection_validate_speaker_name() |
| 2031 | + # test_select_speaker_auto_messages() |
1987 | 2032 | # test_speaker_selection_auto_process_result()
|
1988 | 2033 | # test_speaker_selection_validate_speaker_name()
|
1989 | 2034 | # test_select_speaker_auto_messages()
|
1990 |
| - test_manager_messages_to_string() |
1991 |
| - test_manager_messages_from_string() |
1992 |
| - test_manager_resume_functions() |
1993 |
| - test_manager_resume_returns() |
1994 |
| - test_manager_resume_messages() |
1995 |
| - # pass |
| 2035 | + # test_manager_messages_to_string() |
| 2036 | + # test_manager_messages_from_string() |
| 2037 | + # test_manager_resume_functions() |
| 2038 | + # test_manager_resume_returns() |
| 2039 | + # test_manager_resume_messages() |
| 2040 | + pass |
0 commit comments