-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.py
More file actions
145 lines (123 loc) · 5.3 KB
/
main.py
File metadata and controls
145 lines (123 loc) · 5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import os
import autogen
from typing_extensions import Annotated, List, Tuple
config_list = autogen.config_list_from_json(
"./OAI_CONFIG_LIST.json",
filter_dict={
"model": ["gpt-4o"],
},
)
llm_config = {
"temperature": 0,
"config_list": config_list,
}
#####################
# Define the agents #
#####################
engineer = autogen.AssistantAgent(
name="Engineer",
llm_config=llm_config,
system_message="""
I am a seasoned Software Engineer, responsible for writing clean, efficient, and maintainable code based on the tasks assigned by the Project Manager.
My focus is exclusively on coding and ensuring that the code meets the specified requirements.
Key Responsibilities:
- Implement features and fixes according to the provided task specifications.
- Write code that adheres to best practices and is optimized for performance and readability.
- Ensure that the code is well-documented to facilitate future maintenance and collaboration.
Restrictions:
- I NEVER manage or assign tasks.
- I do not make decisions regarding the project scope or task prioritization.
My goal is to deliver high-quality code that meets the requirements set forth by the Project Manager and the Admin.
""",
)
project_manager = autogen.AssistantAgent(
name="Project_Manager",
system_message="""
I am an experienced Project Manager overseeing the development of a software product. My responsibilities include translating the requirements provided by the Admin into manageable tasks, which I then assign to the Engineer.
Key Responsibilities:
- Break down project requirements into detailed, manageable tasks.
- Assign tasks to the Engineer in a logical and efficient sequence.
- Monitor the progress of the project and ensure timely delivery of each task.
Workflow:
- For each completed task, I will assess if further tasks are required.
- I will ensure that any identified issues are resolved before moving on to the next task.
- When the project is complete, I will confirm the project's completion with a "DONE" message.
Restrictions:
- I never suggest, review, or test code; my focus is purely on task management and project oversight.
- I do not get involved in the technical implementation details.
My goal is to ensure the smooth progression of the project from start to finish, maintaining clear communication and efficient task management.
""",
llm_config=llm_config,
)
user_proxy = autogen.UserProxyAgent(
name="Admin",
human_input_mode="ALWAYS",
code_execution_config=False,
)
groupchat = autogen.GroupChat(
agents=[user_proxy, project_manager, engineer],
messages=[],
max_round=100,
send_introductions=True,
enable_clear_history=True,
)
manager = autogen.GroupChatManager(
groupchat=groupchat,
llm_config=llm_config,
is_termination_msg=lambda msg: "done" in msg["content"].lower()
)
####################
# Tool definitions #
####################
default_path = os.path.abspath("./output") + "/"
@user_proxy.register_for_execution()
@engineer.register_for_llm(description="List files in chosen directory.")
def list_dir(
directory: Annotated[str, "Directory to check."]
) -> Annotated[Tuple[int, List[str]], "Status code and list of files"]:
files = os.listdir(default_path + directory)
return 0, files
@user_proxy.register_for_execution()
@engineer.register_for_llm(description="Check the contents of a chosen file.")
def see_file(
filename: Annotated[str, "Name and path of file to check."]
) -> Annotated[Tuple[int, str], "Status code and file contents."]:
with open(default_path + filename, "r") as file:
lines = file.readlines()
formatted_lines = [f"{i+1}:{line}" for i, line in enumerate(lines)]
file_contents = "".join(formatted_lines)
return 0, file_contents
@user_proxy.register_for_execution()
@engineer.register_for_llm(description="Replaces all the code within a file with new one. Proper indentation is important.")
def modify_code(
filename: Annotated[str, "Name and path of file to change."],
new_code: Annotated[str, "New piece of code to replace old code with. Remember about providing indents."],
) -> Annotated[Tuple[int, str], "Status code and message."]:
with open(default_path + filename, "w") as file:
file.write(new_code)
return 0, "Code was written successfully."
@user_proxy.register_for_execution()
@engineer.register_for_llm(description="Create a new file with code.")
def create_file_with_code(
filename: Annotated[str, "Name and path of file to create."],
code: Annotated[str, "Code to write in the file."]
) -> Annotated[Tuple[int, str], "Status code and message."]:
with open(default_path + filename, "w") as file:
file.write(code)
return 0, "File created successfully"
@user_proxy.register_for_execution()
@engineer.register_for_llm(description="Execute bash command.")
def execute_command(
command: Annotated[str, "Command to execute."]
) -> Annotated[Tuple[int, str], "Status code and message."]:
os.system(f"CI=true cd {default_path} && {command}")
return 0, "Command executed successfully"
##################
# Start the chat #
##################
chat_result = user_proxy.initiate_chat(
manager,
message="""
Create a React app that is a simple todo list.
""",
)