forked from modelscope/agentscope
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdistributed_debate.py
129 lines (110 loc) · 4.48 KB
/
distributed_debate.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
122
123
124
125
126
127
128
129
# -*- coding: utf-8 -*-
""" An example of distributed debate """
import argparse
from user_proxy_agent import UserProxyAgent
from loguru import logger
import agentscope
from agentscope.agents import DialogAgent
from agentscope.msghub import msghub
from agentscope.server import RpcAgentServerLauncher
from agentscope.message import Msg
FIRST_ROUND = """
Welcome to the debate on whether Artificial General Intelligence (AGI) can be achieved using the GPT model framework. This debate will consist of three rounds. In each round, the affirmative side will present their argument first, followed by the negative side. After both sides have presented, the adjudicator will summarize the key points and analyze the strengths of the arguments.
The rules are as follows:
Each side must present clear, concise arguments backed by evidence and logical reasoning.
No side may interrupt the other while they are presenting their case.
After both sides have presented, the adjudicator will have time to deliberate and will then provide a summary, highlighting the most persuasive points from both sides.
The adjudicator's summary will not declare a winner for the individual rounds but will focus on the quality and persuasiveness of the arguments.
At the conclusion of the three rounds, the adjudicator will declare the overall winner based on which side won two out of the three rounds, considering the consistency and strength of the arguments throughout the debate.
Let us begin the first round. The affirmative side: please present your argument for why AGI can be achieved using the GPT model framework.
""" # noqa
SECOND_ROUND = """
Let us begin the second round. It's your turn, the affirmative side.
"""
THIRD_ROUND = """
Next is the final round.
"""
END = """
Judge, please declare the overall winner now.
"""
def parse_args() -> argparse.Namespace:
"""Parse arguments"""
parser = argparse.ArgumentParser()
parser.add_argument(
"--role",
choices=["pro", "con", "main"],
default="main",
)
parser.add_argument("--is-human", action="store_true")
parser.add_argument("--pro-host", type=str, default="localhost")
parser.add_argument(
"--pro-port",
type=int,
default=12011,
)
parser.add_argument("--con-host", type=str, default="localhost")
parser.add_argument(
"--con-port",
type=int,
default=12012,
)
parser.add_argument("--judge-host", type=str, default="localhost")
parser.add_argument(
"--judge-port",
type=int,
default=12013,
)
return parser.parse_args()
def setup_server(parsed_args: argparse.Namespace) -> None:
"""Setup rpc server for participant agent"""
agentscope.init(
model_configs="configs/model_configs.json",
project="Distributed Conversation",
)
host = getattr(parsed_args, f"{parsed_args.role}_host")
port = getattr(parsed_args, f"{parsed_args.role}_port")
server_launcher = RpcAgentServerLauncher(
host=host,
port=port,
custom_agent_classes=[UserProxyAgent, DialogAgent],
)
server_launcher.launch(in_subprocess=False)
server_launcher.wait_until_terminate()
def run_main_process(parsed_args: argparse.Namespace) -> None:
"""Setup the main debate competition process"""
pro_agent, con_agent, judge_agent = agentscope.init(
model_configs="configs/model_configs.json",
agent_configs="configs/debate_agent_configs.json",
project="Distributed Conversation",
)
pro_agent = pro_agent.to_dist(
host=parsed_args.pro_host,
port=parsed_args.pro_port,
)
con_agent = con_agent.to_dist(
host=parsed_args.con_host,
port=parsed_args.con_port,
)
participants = [pro_agent, con_agent, judge_agent]
announcements = [
Msg(name="system", content=FIRST_ROUND, role="system"),
Msg(name="system", content=SECOND_ROUND, role="system"),
Msg(name="system", content=THIRD_ROUND, role="system"),
]
end = Msg(name="system", content=END, role="system")
with msghub(participants=participants) as hub:
for i in range(3):
hub.broadcast(announcements[i])
pro_resp = pro_agent()
logger.chat(pro_resp)
con_resp = con_agent()
logger.chat(con_resp)
judge_agent()
hub.broadcast(end)
judge_agent()
if __name__ == "__main__":
args = parse_args()
if args.role == "main":
run_main_process(args)
else:
setup_server(args)