Update multi_agent.py
Browse files- multi_agent.py +8 -26
multi_agent.py
CHANGED
|
@@ -1,14 +1,7 @@
|
|
| 1 |
import base64, datetime, json, os
|
| 2 |
|
| 3 |
-
from autogen import ConversableAgent, AssistantAgent
|
| 4 |
from autogen.coding import LocalCommandLineCodeExecutor
|
| 5 |
-
from datetime import date
|
| 6 |
-
from typing_extensions import Annotated
|
| 7 |
-
|
| 8 |
-
###
|
| 9 |
-
def get_today() -> Annotated[str, "Get today's date"]:
|
| 10 |
-
return str(date.today())
|
| 11 |
-
###
|
| 12 |
|
| 13 |
def read_file(file_path: str) -> str:
|
| 14 |
with open(file_path, "r", encoding="utf-8") as file:
|
|
@@ -56,7 +49,7 @@ def run_multi_agent(llm, task):
|
|
| 56 |
|
| 57 |
code_executor_agent = ConversableAgent(
|
| 58 |
name="code_executor_agent",
|
| 59 |
-
llm_config=
|
| 60 |
code_execution_config={"executor": executor},
|
| 61 |
human_input_mode="NEVER",
|
| 62 |
default_auto_reply="TERMINATE",
|
|
@@ -65,35 +58,24 @@ def run_multi_agent(llm, task):
|
|
| 65 |
code_writer_agent = AssistantAgent(
|
| 66 |
name="code_writer_agent",
|
| 67 |
llm_config=llm_config,
|
| 68 |
-
system_message="You are a Sr. Python Programmer, an expert in writing Pylint-compliant code.
|
| 69 |
-
"If needed, call get_today() to get today's date.",
|
| 70 |
code_execution_config=False,
|
| 71 |
human_input_mode="NEVER",
|
| 72 |
)
|
| 73 |
-
|
| 74 |
-
###
|
| 75 |
-
register_function(
|
| 76 |
-
get_today,
|
| 77 |
-
caller=code_executor_agent,
|
| 78 |
-
executor=code_writer_agent,
|
| 79 |
-
name="get_today",
|
| 80 |
-
description="Call this tool to get today's date.",
|
| 81 |
-
)
|
| 82 |
-
###
|
| 83 |
|
| 84 |
chat_result = code_executor_agent.initiate_chat(
|
| 85 |
code_writer_agent,
|
| 86 |
message=task,
|
| 87 |
-
max_turns=
|
| 88 |
)
|
| 89 |
|
| 90 |
chat = ""
|
| 91 |
-
|
| 92 |
|
| 93 |
for message in chat_result.chat_history:
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
|
| 98 |
file_name_png = get_latest_file("coding", ".png")
|
| 99 |
|
|
|
|
| 1 |
import base64, datetime, json, os
|
| 2 |
|
| 3 |
+
from autogen import ConversableAgent, AssistantAgent
|
| 4 |
from autogen.coding import LocalCommandLineCodeExecutor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def read_file(file_path: str) -> str:
|
| 7 |
with open(file_path, "r", encoding="utf-8") as file:
|
|
|
|
| 49 |
|
| 50 |
code_executor_agent = ConversableAgent(
|
| 51 |
name="code_executor_agent",
|
| 52 |
+
llm_config=False,
|
| 53 |
code_execution_config={"executor": executor},
|
| 54 |
human_input_mode="NEVER",
|
| 55 |
default_auto_reply="TERMINATE",
|
|
|
|
| 58 |
code_writer_agent = AssistantAgent(
|
| 59 |
name="code_writer_agent",
|
| 60 |
llm_config=llm_config,
|
| 61 |
+
system_message="You are a Sr. Python Programmer, an expert in writing Pylint-compliant code.",
|
|
|
|
| 62 |
code_execution_config=False,
|
| 63 |
human_input_mode="NEVER",
|
| 64 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
chat_result = code_executor_agent.initiate_chat(
|
| 67 |
code_writer_agent,
|
| 68 |
message=task,
|
| 69 |
+
max_turns=10
|
| 70 |
)
|
| 71 |
|
| 72 |
chat = ""
|
| 73 |
+
first_message = True
|
| 74 |
|
| 75 |
for message in chat_result.chat_history:
|
| 76 |
+
if not first_message:
|
| 77 |
+
chat += f"**{message['role'].replace('assistant', 'Code Executor').replace('user', 'Code Writer')}**\n{message['content']}\n\n"
|
| 78 |
+
first_message = False
|
| 79 |
|
| 80 |
file_name_png = get_latest_file("coding", ".png")
|
| 81 |
|