bstraehle commited on
Commit
722929d
1 Parent(s): d2c49bb

Update multi_agent.py

Browse files
Files changed (1) hide show
  1. multi_agent.py +67 -102
multi_agent.py CHANGED
@@ -63,116 +63,81 @@ def initialize():
63
  board_svgs = []
64
  made_move = False
65
 
66
- def run_multi_agent(llm_white, llm_black, num_moves):
67
- initialize()
68
 
69
- llm_config_white = {"model": llm_white}
70
- llm_config_black = {"model": llm_black}
71
 
72
- board_proxy = ConversableAgent(
73
- name="Board Proxy",
74
- llm_config=False,
75
- is_termination_msg=check_made_move,
76
- default_auto_reply="Please make a move.",
77
- human_input_mode="NEVER",
78
- )
79
-
80
- player_white = ConversableAgent(
81
- name="Player White",
82
- system_message="You are a chess Grandmaster and you play as white. "
83
- "First call get_legal_moves(), to get a list of legal moves. "
84
- "Then call make_move(move) to make a legal move. "
85
- "Analyze the move in 3 bullet points. Respond in format **Analysis:** move in UCI format, unordered list.",
86
- llm_config=llm_config_white,
87
  )
88
-
89
- player_black = ConversableAgent(
90
- name="Player Black",
91
- system_message="You are a chess Grandmaster and you play as black. "
92
- "First call get_legal_moves(), to get a list of legal moves. "
93
- "Then call make_move(move) to make a legal move. "
94
- "Analyze the move in 3 bullet points. Respond in format **Analysis:** move in UCI format, unordered list.",
95
- llm_config=llm_config_black,
96
- )
97
-
98
- for caller in [player_white, player_black]:
99
- register_function(
100
- get_legal_moves,
101
- caller=caller,
102
- executor=board_proxy,
103
- name="get_legal_moves",
104
- description="Call this tool to get legal moves.",
105
- )
106
-
107
- register_function(
108
- make_move,
109
- caller=caller,
110
- executor=board_proxy,
111
- name="make_move",
112
- description="Call this tool to make a move.",
113
- )
114
-
115
- player_white.register_nested_chats(
116
- trigger=player_black,
117
- chat_queue=[
118
- {
119
- "sender": board_proxy,
120
- "recipient": player_white,
121
- "summary_method": "last_msg",
122
- "silent": False,
123
- }
124
- ],
125
  )
126
-
127
- player_black.register_nested_chats(
128
- trigger=player_white,
129
- chat_queue=[
130
- {
131
- "sender": board_proxy,
132
- "recipient": player_black,
133
- "summary_method": "last_msg",
134
- "silent": False,
135
- }
136
- ],
137
  )
138
 
139
- chat_result = None
140
- chat_history = []
141
-
142
- try:
143
- chat_result = player_black.initiate_chat(
144
- player_white,
145
- message="Let's play chess!",
146
- max_turns=get_num_turns(num_moves),
147
- verbose=True
148
- )
149
- except Exception as e:
150
- print(f"Error: {e}")
151
- finally:
152
- if chat_result != None:
153
- chat_history = chat_result.chat_history
154
-
155
- result = ""
156
- num_move = 0
157
 
158
- for chat in chat_history:
159
- player = ""
160
-
161
- if num_move % 2 == 0:
162
- player = "Player Black"
163
- else:
164
- player = "Player White"
 
 
 
 
165
 
166
- if num_move > 0:
167
- result += f"**{player}, Move {num_move}**<br>{chat.get('content')}<br>{board_svgs[num_move - 1]}<br><br>"
168
-
169
- num_move += 1
 
170
 
171
- if num_moves % 2 == 0 and num_move == num_moves + 1:
172
- break
 
173
 
174
- #print("===")
175
- #print(result)
176
- #print("===")
 
177
 
178
- return result
 
63
  board_svgs = []
64
  made_move = False
65
 
66
+ def run_multi_agent(llm, task):
67
+ #initialize()
68
 
69
+ llm_config = {"model": llm}
 
70
 
71
+ user_proxy = autogen.ConversableAgent(
72
+ name="Admin",
73
+ system_message="Give the task, and send "
74
+ "instructions to writer to refine the blog post.",
75
+ code_execution_config=False,
76
+ llm_config=llm_config,
77
+ human_input_mode="ALWAYS",
 
 
 
 
 
 
 
 
78
  )
79
+
80
+ planner = autogen.ConversableAgent(
81
+ name="Planner",
82
+ system_message="Given a task, please determine "
83
+ "what information is needed to complete the task. "
84
+ "Please note that the information will all be retrieved using"
85
+ " Python code. Please only suggest information that can be "
86
+ "retrieved using Python code. "
87
+ "After each step is done by others, check the progress and "
88
+ "instruct the remaining steps. If a step fails, try to "
89
+ "workaround",
90
+ description="Planner. Given a task, determine what "
91
+ "information is needed to complete the task. "
92
+ "After each step is done by others, check the progress and "
93
+ "instruct the remaining steps",
94
+ llm_config=llm_config,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  )
96
+
97
+ engineer = autogen.AssistantAgent(
98
+ name="Engineer",
99
+ llm_config=llm_config,
100
+ description="An engineer that writes code based on the plan "
101
+ "provided by the planner.",
 
 
 
 
 
102
  )
103
 
104
+ executor = autogen.ConversableAgent(
105
+ name="Executor",
106
+ system_message="Execute the code written by the "
107
+ "engineer and report the result.",
108
+ human_input_mode="NEVER",
109
+ code_execution_config={
110
+ "last_n_messages": 3,
111
+ "work_dir": "coding",
112
+ "use_docker": False,
113
+ },
114
+ )
 
 
 
 
 
 
 
115
 
116
+ writer = autogen.ConversableAgent(
117
+ name="Writer",
118
+ llm_config=llm_config,
119
+ system_message="Writer."
120
+ "Please write blogs in markdown format (with relevant titles)"
121
+ " and put the content in pseudo ```md``` code block. "
122
+ "You take feedback from the admin and refine your blog.",
123
+ description="Writer."
124
+ "Write blogs based on the code execution results and take "
125
+ "feedback from the admin to refine the blog."
126
+ )
127
 
128
+ groupchat = autogen.GroupChat(
129
+ agents=[user_proxy, engineer, writer, executor, planner],
130
+ messages=[],
131
+ max_round=10,
132
+ )
133
 
134
+ manager = autogen.GroupChatManager(
135
+ groupchat=groupchat, llm_config=llm_config
136
+ )
137
 
138
+ groupchat_result = user_proxy.initiate_chat(
139
+ manager,
140
+ message=task,
141
+ )
142
 
143
+ return groupchat_result