(
llm_config,
jupyter_executor,
sys_prompt,
summarizer
)
| 10 | return summarizer |
| 11 | |
| 12 | def load_agent_navigator( |
| 13 | llm_config, |
| 14 | jupyter_executor, |
| 15 | sys_prompt, |
| 16 | summarizer |
| 17 | ): |
| 18 | terminate_condition = lambda x: x.get("content", "").find("Final Answer:") > 0 or "_run" not in x.get("content", "") |
| 19 | def response_preparer(self, messages): |
| 20 | plain_messages = [message["content"] for message in messages] |
| 21 | query = plain_messages[0].split("Query: ")[-1].strip() |
| 22 | analysis = summarizer(f"Contexts: {' '.join(plain_messages[1:-1])}. Selectively choose the right context and answer the following `{query}`. You should remain the key code snippets.") |
| 23 | analysis += plain_messages[-1].replace("Final Answer:", "") |
| 24 | return analysis |
| 25 | |
| 26 | navigator_assistant = AssistantAgent( |
| 27 | "Inner-Navigator-Assistant", |
| 28 | system_message=sys_prompt, |
| 29 | llm_config={"config_list": llm_config}, |
| 30 | human_input_mode="NEVER", |
| 31 | ) |
| 32 | |
| 33 | navigator_interpreter = UserProxyAgent( |
| 34 | name="Navigator Interpreter", |
| 35 | is_termination_msg=terminate_condition, |
| 36 | llm_config=False, |
| 37 | code_execution_config={ |
| 38 | "executor": jupyter_executor, |
| 39 | }, |
| 40 | human_input_mode="NEVER", |
| 41 | default_auto_reply="", |
| 42 | ) |
| 43 | |
| 44 | groupchat_nav = GroupChat( |
| 45 | agents=[navigator_assistant, navigator_interpreter], |
| 46 | messages=[], |
| 47 | speaker_selection_method="round_robin", |
| 48 | allow_repeat_speaker=False, |
| 49 | max_round=15, |
| 50 | ) |
| 51 | |
| 52 | manager_nav = GroupChatManager( |
| 53 | groupchat=groupchat_nav, |
| 54 | name="Navigator Manager", |
| 55 | llm_config={"config_list": llm_config}, |
| 56 | max_consecutive_auto_reply=0 |
| 57 | ) |
| 58 | |
| 59 | navigator = SocietyOfMindAgent( |
| 60 | "Navigator", |
| 61 | chat_manager=manager_nav, |
| 62 | llm_config={"config_list": llm_config}, |
| 63 | response_preparer=response_preparer |
| 64 | ) |
| 65 | |
| 66 | navigator.register_hook( |
| 67 | "process_last_received_message", |
| 68 | lambda content: react_prompt_message(content), |
| 69 | ) |
no test coverage detected