Update multi_agent.py
Browse files- 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(
|
67 |
-
initialize()
|
68 |
|
69 |
-
|
70 |
-
llm_config_black = {"model": llm_black}
|
71 |
|
72 |
-
|
73 |
-
name="
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
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 |
-
|
90 |
-
name="
|
91 |
-
system_message="
|
92 |
-
"
|
93 |
-
"
|
94 |
-
"
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
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 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
"recipient": player_black,
|
133 |
-
"summary_method": "last_msg",
|
134 |
-
"silent": False,
|
135 |
-
}
|
136 |
-
],
|
137 |
)
|
138 |
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
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 |
-
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
|
163 |
-
|
164 |
-
|
|
|
|
|
|
|
|
|
165 |
|
166 |
-
|
167 |
-
|
168 |
-
|
169 |
-
|
|
|
170 |
|
171 |
-
|
172 |
-
|
|
|
173 |
|
174 |
-
|
175 |
-
|
176 |
-
|
|
|
177 |
|
178 |
-
return
|
|
|
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
|