Skip to content

Commit 73ea172

Browse files
authored
chore: apply black formatting to gui_agents (#194)
Pure formatting pass: AST-identical for every file. Brings 8 long-drifted files back into compliance with the lint workflow so main goes green again.
1 parent 231fc86 commit 73ea172

8 files changed

Lines changed: 49 additions & 99 deletions

File tree

gui_agents/s1/core/ProceduralMemory.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
class PROCEDURAL_MEMORY:
66
@staticmethod
77
def construct_worker_procedural_memory(agent_class):
8-
procedural_memory = textwrap.dedent(
9-
f"""\
8+
procedural_memory = textwrap.dedent(f"""\
109
You are an expert in graphical user interfaces and Python code. You are responsible for executing the current subtask: `SUBTASK_DESCRIPTION` of the larger goal: `TASK_DESCRIPTION`.
1110
IMPORTANT: ** The subtasks: ['DONE_TASKS'] have already been done. The future subtasks ['FUTURE_TASKS'] will be done in the future by me. You must only perform the current subtask: `SUBTASK_DESCRIPTION`. Do not try to do future subtasks. **
1211
You are working in CURRENT_OS. You must only complete the subtask provided and not the larger goal.
@@ -16,8 +15,7 @@ def construct_worker_procedural_memory(agent_class):
1615
3. The history of your previous interactions with the UI.
1716
4. Access to the following class and methods to interact with the UI:
1817
class Agent:
19-
"""
20-
)
18+
""")
2119

2220
for attr_name in dir(agent_class):
2321
attr = getattr(agent_class, attr_name)
@@ -29,8 +27,7 @@ def {attr_name}{signature}:
2927
'''{attr.__doc__}'''
3028
"""
3129

32-
procedural_memory += textwrap.dedent(
33-
"""
30+
procedural_memory += textwrap.dedent("""
3431
Your response should be formatted like this:
3532
(Previous action verification)
3633
Carefully analyze based on the screenshot and the accessibility tree if the previous action was successful. If the previous action was not successful, provide a reason for the failure.
@@ -57,8 +54,7 @@ def {attr_name}{signature}:
5754
7. Do not do anything other than the exact specified task. Return with `agent.done()` immediately after the task is completed or `agent.fail()` if it cannot be completed.
5855
8. Whenever possible use hot-keys or typing rather than mouse clicks.
5956
9. My computer's password is 'password', feel free to use it when you need sudo rights
60-
"""
61-
)
57+
""")
6258
return procedural_memory.strip()
6359

6460
# MANAGER_PROMPT = """You are a planning agent for solving GUI navigation tasks. You will be provided the initial configuration of a system including accessibility, screenshot and other information. You need to solve the following task: TASK_DESCRIPTION. You will describe in as much detail as possible the steps required to complete the task by a GUI agent. Please do not include any verification steps in your plan that is not your responsibility. IMPORTANT: Your plan should be as concize as possible and should not include any unnecessary steps. Do not fine-tune, or embellish anything or cause any side effects. Generate the plan that can be accomplished in the shortest time. Please take the current state into account when generating the plan. Please provide the plan in a step-by-step format and make sure you do not include anything that's already done in the GUI in your plan."""

gui_agents/s2/agents/worker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,13 +159,11 @@ def generate_next_action(
159159
if self.enable_reflection:
160160
# Load the initial subtask info
161161
if self.turn_count == 0:
162-
text_content = textwrap.dedent(
163-
f"""
162+
text_content = textwrap.dedent(f"""
164163
Subtask Description: {subtask}
165164
Subtask Information: {subtask_info}
166165
Current Trajectory below:
167-
"""
168-
)
166+
""")
169167
updated_sys_prompt = (
170168
self.reflection_agent.system_prompt + "\n" + text_content
171169
)

gui_agents/s2/memory/procedural_memory.py

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ class PROCEDURAL_MEMORY:
66

77
@staticmethod
88
def construct_worker_procedural_memory(agent_class, skipped_actions):
9-
procedural_memory = textwrap.dedent(
10-
f"""\
9+
procedural_memory = textwrap.dedent(f"""\
1110
You are an expert in graphical user interfaces and Python code. You are responsible for executing the current subtask: `SUBTASK_DESCRIPTION` of the larger goal: `TASK_DESCRIPTION`.
1211
IMPORTANT: ** The subtasks: ['DONE_TASKS'] have already been done. The future subtasks ['FUTURE_TASKS'] will be done in the future by me. You must only perform the current subtask: `SUBTASK_DESCRIPTION`. Do not try to do future subtasks. **
1312
You are working in CURRENT_OS. You must only complete the subtask provided and not the larger goal.
@@ -16,8 +15,7 @@ def construct_worker_procedural_memory(agent_class, skipped_actions):
1615
2. The history of your previous interactions with the UI.
1716
3. Access to the following class and methods to interact with the UI:
1817
class Agent:
19-
"""
20-
)
18+
""")
2119

2220
for attr_name in dir(agent_class):
2321
if attr_name in skipped_actions:
@@ -32,8 +30,7 @@ def {attr_name}{signature}:
3230
'''{attr.__doc__}'''
3331
"""
3432

35-
procedural_memory += textwrap.dedent(
36-
"""
33+
procedural_memory += textwrap.dedent("""
3734
Your response should be formatted like this:
3835
(Previous action verification)
3936
Carefully analyze based on the screenshot if the previous action was successful. If the previous action was not successful, provide a reason for the failure.
@@ -60,14 +57,12 @@ def {attr_name}{signature}:
6057
8. Whenever possible, your grounded action should use hot-keys with the agent.hotkey() action instead of clicking or dragging.
6158
9. My computer's password is 'password', feel free to use it when you need sudo rights.
6259
10. Do not use the "command" + "tab" hotkey on MacOS.
63-
"""
64-
)
60+
""")
6561

6662
return procedural_memory.strip()
6763

6864
# Manager prompt that generalizes to initial planning, re-planning after subtask completion, and re-planning after failure
69-
COMBINED_MANAGER_PROMPT = textwrap.dedent(
70-
"""
65+
COMBINED_MANAGER_PROMPT = textwrap.dedent("""
7166
You are an expert planning agent for solving GUI navigation tasks. You need to generate a plan for solving the following task: TASK_DESCRIPTION.
7267
7368
You are provided with:
@@ -91,8 +86,7 @@ def {attr_name}{signature}:
9186
- If you feel the trajectory and future subtasks seem correct based on the current state of the desktop, you may re-use future subtasks.
9287
- If you feel some future subtasks are not detailed enough, use your observations from the desktop screenshot to update these subtasks to be more detailed.
9388
- If you feel some future subtasks are incorrect or unnecessary, feel free to modify or even remove them.
94-
"""
95-
)
89+
""")
9690

9791
# USED IN OSWORLD EXPERIMENTS
9892
RAG_AGENT_OSWORLD = """
@@ -107,8 +101,7 @@ def {attr_name}{signature}:
107101
"""
108102

109103
# For reflection agent, post-action verification mainly for cycle detection
110-
REFLECTION_ON_TRAJECTORY = textwrap.dedent(
111-
"""
104+
REFLECTION_ON_TRAJECTORY = textwrap.dedent("""
112105
You are a reflection agent designed to assist in subtask execution by reflecting on the trajectory of a subtask and providing feedback for what the next step should be.
113106
You have access to the Subtask Description and the Current Trajectory of another computer agent. The Current Trajectory is a sequence of a desktop image, chain-of-thought reasoning, and a desktop action for each time step. The last image is the screen's display after the last action.
114107
Your task is to generate a reflection. Your generated reflection must fall under one of the two cases listed below:
@@ -120,8 +113,7 @@ def {attr_name}{signature}:
120113
- DO NOT suggest any specific future plans or actions. Your only goal is to provide a reflection, not an actual plan or action.
121114
- Any response that falls under Case 1 should explain why the trajectory is not going according to plan. You should especially lookout for cycles of actions that are continually repeated with no progress.
122115
- Any response that falls under Case 2 should be concise, since you just need to affirm the agent to continue with the current trajectory.
123-
"""
124-
)
116+
""")
125117

126118
TASK_SUMMARIZATION_PROMPT = """
127119
You are a summarization agent designed to analyze a trajectory of desktop task execution.
@@ -178,8 +170,7 @@ def {attr_name}{signature}:
178170
Analyze the given plan and provide the output in this JSON format within the <json></json> tags. Ensure the JSON is valid and properly escaped.
179171
"""
180172

181-
SUBTASK_SUMMARIZATION_PROMPT = textwrap.dedent(
182-
"""
173+
SUBTASK_SUMMARIZATION_PROMPT = textwrap.dedent("""
183174
You are a summarization agent designed to analyze a trajectory of desktop task execution.
184175
You will summarize the correct plan and grounded actions based on the whole trajectory of a subtask, ensuring the summarized plan contains only correct and necessary steps.
185176
@@ -195,8 +186,7 @@ def {attr_name}{signature}:
195186
Action: [Description of the correct action]
196187
Grounded Action: [Grounded actions with the \"element1_description\" replacement when needed]
197188
5. Exclude any other details that are not necessary for completing the task.
198-
"""
199-
)
189+
""")
200190

201191
STATE_EVALUATOR_SYSTEM_PROMPT = """
202192
You are an impartial evaluator to evaluate the completeness of the given desktop computer task, you are also an expert of accessibility tree, os environment and python programming.
@@ -242,8 +232,7 @@ def {attr_name}{signature}:
242232
Only say Yes or No in the Judgment section. Do not provide any other information in the Judgment section.
243233
"""
244234

245-
PHRASE_TO_WORD_COORDS_PROMPT = textwrap.dedent(
246-
"""
235+
PHRASE_TO_WORD_COORDS_PROMPT = textwrap.dedent("""
247236
You are an expert in graphical user interfaces. Your task is to process a phrase of text, and identify the most relevant word on the computer screen.
248237
You are provided with a phrase, a table with all the text on the screen, and a screenshot of the computer screen. You will identify the single word id that is best associated with the provided phrase.
249238
This single word must be displayed on the computer screenshot, and its location on the screen should align with the provided phrase.
@@ -254,5 +243,4 @@ def {attr_name}{signature}:
254243
2. Then, output the unique word id. Remember, the word id is the 1st number in each row of the text table.
255244
3. If there are multiple occurrences of the same word, use the surrounding context in the phrase to choose the correct one. Pay very close attention to punctuation and capitalization.
256245
257-
"""
258-
)
246+
""")

gui_agents/s2_5/agents/worker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,10 @@ def generate_next_action(
127127
if self.enable_reflection:
128128
# Load the initial message
129129
if self.turn_count == 0:
130-
text_content = textwrap.dedent(
131-
f"""
130+
text_content = textwrap.dedent(f"""
132131
Task Description: {instruction}
133132
Current Trajectory below:
134-
"""
135-
)
133+
""")
136134
updated_sys_prompt = (
137135
self.reflection_agent.system_prompt + "\n" + text_content
138136
)

gui_agents/s2_5/memory/procedural_memory.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
class PROCEDURAL_MEMORY:
66
@staticmethod
77
def construct_simple_worker_procedural_memory(agent_class, skipped_actions):
8-
procedural_memory = textwrap.dedent(
9-
f"""\
8+
procedural_memory = textwrap.dedent(f"""\
109
You are an expert in graphical user interfaces and Python code. You are responsible for executing the task: `TASK_DESCRIPTION`.
1110
You are working in CURRENT_OS.
1211
You are provided with:
1312
1. A screenshot of the current time step.
1413
2. The history of your previous interactions with the UI.
1514
3. Access to the following class and methods to interact with the UI:
1615
class Agent:
17-
"""
18-
)
16+
""")
1917

2018
for attr_name in dir(agent_class):
2119
if attr_name in skipped_actions:
@@ -30,8 +28,7 @@ def {attr_name}{signature}:
3028
'''{attr.__doc__}'''
3129
"""
3230

33-
procedural_memory += textwrap.dedent(
34-
"""
31+
procedural_memory += textwrap.dedent("""
3532
Your response should be formatted like this:
3633
(Previous action verification)
3734
Carefully analyze based on the screenshot if the previous action was successful. If the previous action was not successful, provide a reason for the failure.
@@ -58,14 +55,12 @@ def {attr_name}{signature}:
5855
8. Generate agent.fail() as your grounded action if you get exhaustively stuck on the task and believe it is impossible.
5956
9. Generate agent.done() as your grounded action when your believe the task is fully complete.
6057
10. Do not use the "command" + "tab" hotkey on MacOS.
61-
"""
62-
)
58+
""")
6359

6460
return procedural_memory.strip()
6561

6662
# For reflection agent, post-action verification mainly for cycle detection
67-
REFLECTION_ON_TRAJECTORY = textwrap.dedent(
68-
"""
63+
REFLECTION_ON_TRAJECTORY = textwrap.dedent("""
6964
You are an expert computer use agent designed to reflect on the trajectory of a task and provide feedback on what has happened so far.
7065
You have access to the Task Description and the Current Trajectory of another computer agent. The Current Trajectory is a sequence of a desktop image, chain-of-thought reasoning, and a desktop action for each time step. The last image is the screen's display after the last action.
7166
Your task is to generate a reflection. Your generated reflection must fall under one of the cases listed below:
@@ -79,11 +74,9 @@ def {attr_name}{signature}:
7974
- DO NOT suggest any specific future plans or actions. Your only goal is to provide a reflection, not an actual plan or action.
8075
- Any response that falls under Case 1 should explain why the trajectory is not going according to plan. You should especially lookout for cycles of actions that are continually repeated with no progress.
8176
- Any response that falls under Case 2 should be concise, since you just need to affirm the agent to continue with the current trajectory.
82-
"""
83-
)
77+
""")
8478

85-
PHRASE_TO_WORD_COORDS_PROMPT = textwrap.dedent(
86-
"""
79+
PHRASE_TO_WORD_COORDS_PROMPT = textwrap.dedent("""
8780
You are an expert in graphical user interfaces. Your task is to process a phrase of text, and identify the most relevant word on the computer screen.
8881
You are provided with a phrase, a table with all the text on the screen, and a screenshot of the computer screen. You will identify the single word id that is best associated with the provided phrase.
8982
This single word must be displayed on the computer screenshot, and its location on the screen should align with the provided phrase.
@@ -94,5 +87,4 @@ def {attr_name}{signature}:
9487
2. Then, output the unique word id. Remember, the word id is the 1st number in each row of the text table.
9588
3. If there are multiple occurrences of the same word, use the surrounding context in the phrase to choose the correct one. Pay very close attention to punctuation and capitalization.
9689
97-
"""
98-
)
90+
""")

gui_agents/s3/agents/worker.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,12 +142,10 @@ def _generate_reflection(self, instruction: str, obs: Dict) -> Tuple[str, str]:
142142
if self.enable_reflection:
143143
# Load the initial message
144144
if self.turn_count == 0:
145-
text_content = textwrap.dedent(
146-
f"""
145+
text_content = textwrap.dedent(f"""
147146
Task Description: {instruction}
148147
Current Trajectory below:
149-
"""
150-
)
148+
""")
151149
updated_sys_prompt = (
152150
self.reflection_agent.system_prompt + "\n" + text_content
153151
)

gui_agents/s3/bbon/behavior_narrator.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,7 @@ def place_text(label, color, x, y):
6363
offset_x = 5
6464
if y + offset_y < 0: # Out of bounds on top
6565
offset_y = 5
66-
draw.text(
67-
(x + offset_x, y + offset_y), label, fill=color, font=font
68-
)
66+
draw.text((x + offset_x, y + offset_y), label, fill=color, font=font)
6967

7068
if mouse_action.startswith("pyautogui.click"):
7169
draw.circle((width, height), radius=3, fill=(255, 0, 0))

0 commit comments

Comments
 (0)