-
Notifications
You must be signed in to change notification settings - Fork 5.8k
/
Copy pathtest_nested.py
executable file
·121 lines (104 loc) · 4.31 KB
/
test_nested.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env python3 -m pytest
import pytest
import sys
import os
import autogen
sys.path.append(os.path.join(os.path.dirname(__file__), ".."))
from conftest import skip_openai # noqa: E402
@pytest.mark.skipif(skip_openai, reason="requested to skip openai tests")
def test_nested():
config_list = autogen.config_list_from_json(env_or_file="OAI_CONFIG_LIST")
llm_config = {"config_list": config_list}
tasks = [
"""What's Microsoft's Stock price today?""",
"""Make a pleasant joke about it.""",
]
inner_assistant = autogen.AssistantAgent(
"Inner-assistant",
llm_config=llm_config,
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
)
inner_code_interpreter = autogen.UserProxyAgent(
"Inner-code-interpreter",
human_input_mode="NEVER",
code_execution_config={
"work_dir": "coding",
"use_docker": False,
},
default_auto_reply="",
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
)
groupchat = autogen.GroupChat(
agents=[inner_assistant, inner_code_interpreter],
messages=[],
speaker_selection_method="round_robin", # With two agents, this is equivalent to a 1:1 conversation.
allow_repeat_speaker=False,
max_round=8,
)
manager = autogen.GroupChatManager(
groupchat=groupchat,
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
llm_config=llm_config,
code_execution_config={
"work_dir": "coding",
"use_docker": False,
},
)
assistant = autogen.AssistantAgent(
name="Assistant",
llm_config={"config_list": config_list},
# is_termination_msg=lambda x: x.get("content", "") == "",
)
user = autogen.UserProxyAgent(
name="User",
human_input_mode="NEVER",
is_termination_msg=lambda x: x.get("content", "").find("TERMINATE") >= 0,
code_execution_config={
"last_n_messages": 1,
"work_dir": "tasks",
"use_docker": False,
}, # Please set use_docker=True if docker is available to run the generated code. Using docker is safer than running the generated code directly.
)
writer = autogen.AssistantAgent(
name="Writer",
llm_config={"config_list": config_list},
system_message="""
You are a professional writer, known for
your insightful and engaging articles.
You transform complex concepts into compelling narratives.
Reply "TERMINATE" in the end when everything is done.
""",
)
reviewer = autogen.AssistantAgent(
name="Reviewer",
llm_config={"config_list": config_list},
system_message="""
You are a compliance reviewer, known for your thoroughness and commitment to standards.
Your task is to scrutinize content for any harmful elements or regulatory violations, ensuring
all materials align with required guidelines.
You must review carefully, identify potential issues, and maintain the integrity of the organization.
Your role demands fairness, a deep understanding of regulations, and a focus on protecting against
harm while upholding a culture of responsibility.
You also help make revisions to ensure the content is accurate, clear, and compliant.
Reply "TERMINATE" in the end when everything is done.
""",
)
def writing_message(recipient, messages, sender, config):
return f"Polish the content to make an engaging and nicely formatted blog post. \n\n {recipient.chat_messages_for_summary(sender)[-1]['content']}"
nested_chat_queue = [
{"recipient": manager, "summary_method": "reflection_with_llm"},
{"recipient": writer, "message": writing_message, "summary_method": "last_msg", "max_turns": 1},
{
"recipient": reviewer,
"message": "Review the content provided.",
"summary_method": "last_msg",
"max_turns": 1,
},
]
assistant.register_nested_chats(
nested_chat_queue,
trigger=user,
)
user.initiate_chats([{"recipient": assistant, "message": tasks[0]}, {"recipient": assistant, "message": tasks[1]}])
if __name__ == "__main__":
test_nested()