MCPcopy Create free account
hub / github.com/FSoft-AI4Code/HyperAgent / load_manager

Function load_manager

src/hyperagent/agents/plan_seeking.py:206–247  ·  view source on GitHub ↗
(user_proxy, planner, navigator, editor, executor, llm_config)

Source from the content-addressed store, hash-verified

204 return planner
205
206def load_manager(user_proxy, planner, navigator, editor, executor, llm_config):
207
208 def custom_speaker_selection_func(last_speaker: Agent, groupchat: GroupChat):
209 """Define a customized speaker selection function.
210 A recommended way is to define a transition for each speaker in the groupchat.
211
212 Returns:
213 Return an `Agent` class or a string from ['auto', 'manual', 'random', 'round_robin'] to select a default method to use.
214 """
215 messages = groupchat.messages
216 if llm_config["type"] == "patch":
217 if last_speaker is user_proxy:
218 return planner
219 elif "Navigator" in messages[-1]["content"] and last_speaker == planner:
220 return navigator
221 elif "Editor" in messages[-1]["content"] and last_speaker == planner:
222 return editor
223 elif "Executor" in messages[-1]["content"] and last_speaker == planner:
224 return executor
225 else:
226 return planner
227 else:
228 if last_speaker is user_proxy:
229 return planner
230 elif "Navigator" in messages[-1]["content"] and last_speaker == planner:
231 return navigator
232 elif "Executor" in messages[-1]["content"] and last_speaker == planner:
233 return executor
234 else:
235 return planner
236
237 groupchat = GroupChat(agents=[navigator, editor, executor, planner], messages=[], max_round=20, speaker_selection_method=custom_speaker_selection_func)
238
239 def stop_condition(msg):
240 if "Final Answer"in msg["content"]:
241 return True
242 elif all([agent_name not in msg["content"] for agent_name in ["Navigator", "Editor", "Executor"]]) and msg["name"] == "Planner":
243 return True
244 else:
245 return False
246 manager = GroupChatManager(name="hyperagent", groupchat=groupchat, llm_config={"config_list": llm_config["plan"]}, is_termination_msg=lambda msg: stop_condition(msg))
247 return manager

Callers 1

SetupFunction · 0.90

Calls 1

stop_conditionFunction · 0.85

Tested by

no test coverage detected