Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Simplify system prompt
Browse files- e2bqwen.py +35 -144
- eval.py +2 -2
e2bqwen.py
CHANGED
@@ -12,28 +12,27 @@ from PIL import Image
|
|
12 |
from smolagents import CodeAgent, tool, HfApiModel
|
13 |
from smolagents.memory import ActionStep, TaskStep
|
14 |
from smolagents.models import ChatMessage, Model
|
15 |
-
from smolagents.agents import populate_template
|
16 |
from smolagents.monitoring import LogLevel
|
17 |
from smolagents.agent_types import AgentImage
|
18 |
from PIL import ImageDraw
|
19 |
from datetime import datetime
|
20 |
|
21 |
-
E2B_SYSTEM_PROMPT_TEMPLATE = """You are a desktop automation assistant that can control a remote desktop environment.
|
22 |
-
|
23 |
<action process>
|
24 |
You will be given a task to solve in several steps. At each step you will perform an action.
|
25 |
After each action, you'll receive an updated screenshot.
|
26 |
Then you will proceed as follows, with these sections: don't skip any!
|
27 |
|
28 |
Short term goal: ...
|
29 |
-
Where I am: ...
|
30 |
What I see: ...
|
31 |
Reflection: ...
|
32 |
-
Action:
|
33 |
-
Code:
|
34 |
```python
|
35 |
click(254, 308)
|
36 |
```<end_code>
|
|
|
|
|
37 |
</action_process>
|
38 |
|
39 |
<tools>
|
@@ -43,98 +42,75 @@ On top of performing computations in the Python code snippets that you create, y
|
|
43 |
Takes inputs: {{tool.inputs}}
|
44 |
Returns an output of type: {{tool.output_type}}
|
45 |
{%- endfor %}
|
46 |
-
|
47 |
-
The desktop has a resolution of <<resolution_x>>x<<resolution_y>> pixels, take it into account to decide clicking coordinates.
|
48 |
-
If you clicked somewhere in the previous action, a green crosshair will appear at the exact location of the previous click.
|
49 |
-
The image might have change since then but the cross stays at the previous click. If your click seems to have changed nothing, check that this location is exactly where you intended to click. Otherwise correct the click coordinates.
|
50 |
</tools>
|
51 |
|
52 |
-
<
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
click
|
57 |
-
|
58 |
-
|
|
|
59 |
|
60 |
<task_resolution_example>
|
61 |
For a task like "Open a text editor and type 'Hello World'":
|
62 |
Step 1:
|
63 |
Short term goal: I want to open a text editor.
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
Action: I'll click it, carefully clicking in the middle of the text 'Applications'/
|
68 |
-
Code:
|
69 |
```python
|
70 |
click(51, 8)
|
71 |
```<end_code>
|
72 |
|
73 |
Step 2:
|
74 |
Short term goal: I want to open a text editor.
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
Action:
|
79 |
-
Code:
|
80 |
```python
|
81 |
click(76, 195)
|
82 |
```<end_code>
|
83 |
|
84 |
Step 3:
|
85 |
Short term goal: I want to open a text editor.
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
Action: I will now click on it being very precise, clicking in the middle of the text 'Text Editor'.
|
90 |
-
Code:
|
91 |
```python
|
92 |
click(251, 441)
|
93 |
```<end_code>
|
94 |
|
95 |
Step 4:
|
96 |
Short term goal: I want to open a text editor.
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
Action: I will click the correct place, right in the middle of the element.
|
101 |
-
Code:
|
102 |
```python
|
103 |
click(241, 441)
|
104 |
```<end_code>
|
105 |
|
106 |
Step 5:
|
107 |
Short term goal: I want to type 'Hello World'.
|
108 |
-
|
109 |
-
What I see: The Notepad app is open on an empty page
|
110 |
Reflection: Now Notepad is open as intended, time to type text.
|
111 |
-
Action:
|
112 |
-
Code:
|
113 |
```python
|
114 |
type_text("Hello World")
|
115 |
```<end_code>
|
116 |
|
117 |
Step 6:
|
118 |
Short term goal: I want to type 'Hello World'.
|
119 |
-
Where I am: I have opened a Notepad.
|
120 |
What I see: The Notepad app displays 'Hello World'
|
121 |
-
Reflection: Now that I've 1. Opened the notepad and 2. typed 'Hello World', and 3. the result seems correct, I think the Task is completed.
|
122 |
-
Action:
|
123 |
-
Code:
|
124 |
```python
|
125 |
final_answer("Done")
|
126 |
```<end_code>
|
127 |
</task_resolution_example>
|
128 |
|
129 |
-
<click_guidelines>
|
130 |
-
Look at elements on the screen to determine what to click or interact with.
|
131 |
-
Use precise coordinates based on the current screenshot for mouse movements and clicks.
|
132 |
-
Whenever you click, MAKE SURE to click in the middle of the button, text, link or any other clickable element. Not under, not on the side. IN THE MIDDLE, else you risk to miss it.
|
133 |
-
In menus it is always better to click in the middle of the text rather than in the tiny icon. Calculate extremelly well the coordinates. A mistake here can make the full task fail.
|
134 |
-
The desktop has a resolution of <<resolution_x>>x<<resolution_y>> pixels: NEVER USE HYPOTHETIC OR ASSUMED COORDINATES, USE TRUE COORDINATES that you can see from the screenshot.
|
135 |
-
Sometimes you may have missed a click, so never assume that you're on the right page, always make sure that your previous action worked. In the screenshot you can see if the mouse is out of the clickable area. Pay special attention to this.
|
136 |
-
</click_guidelines>
|
137 |
-
|
138 |
<general_guidelines>
|
139 |
Always analyze the latest screenshot carefully before performing actions.
|
140 |
You can wait for appropriate loading times using the wait() tool. But don't wait forever, sometimes you've just misclicked and the process didn't launch.
|
@@ -144,7 +120,7 @@ Use click to move through menus on the desktop and scroll for web and specific a
|
|
144 |
Always analyze the latest screenshot carefully before performing actions.
|
145 |
Desktop menus usually expand with more options, the tiny triangle next to some text in a menu means that menu expands. For example in Office in the Applications menu expands showing presentation or writing applications.
|
146 |
NEVER CLICK THE WEB BROWSER ICON TO OPEN THE WEB BROWSER: use open_url directly.
|
147 |
-
In browser, ignore any sign
|
148 |
</general_guidelines>
|
149 |
""".replace("<<current_date>>", datetime.now().strftime("%A, %d-%B-%Y"))
|
150 |
|
@@ -228,91 +204,6 @@ class E2BVisionAgent(CodeAgent):
|
|
228 |
self._setup_desktop_tools()
|
229 |
self.step_callbacks.append(self.take_screenshot_callback)
|
230 |
|
231 |
-
def initialize_system_prompt(self) -> str:
|
232 |
-
if False:
|
233 |
-
return """You are a desktop automation assistant that can control a remote desktop environment.
|
234 |
-
You only have access to the following tools to interact with the desktop, no additional ones:
|
235 |
-
- click(x, y): Performs a left-click at the specified coordinates
|
236 |
-
- right_click(x, y): Performs a right-click at the specified coordinates
|
237 |
-
- double_click(x, y): Performs a double-click at the specified coordinates
|
238 |
-
- move_mouse(x, y): Moves the mouse cursor to the specified coordinates
|
239 |
-
- type_text(text): Types the specified text at the current cursor position
|
240 |
-
- press_key(key): Presses a keyboard key (e.g., "Return", "tab", "ctrl+c")
|
241 |
-
- scroll(x, y, direction, amount): Scrolls a website in a browser or a document (direction can be "up" or "down", a common amount is 1 or 2 scroll("down",1) ). DO NOT use scroll to move through linux desktop menus. x, y, is the mouse position to scroll on.
|
242 |
-
- wait(seconds): Waits for the specified number of seconds. Very useful in case the prior order is still executing (for example starting very heavy applications like browsers or office apps)
|
243 |
-
- open_url(url): Directly opens a browser with the specified url, saves time compared to clicking in a browser and going through the initial setup wizard.
|
244 |
-
- drag_and_drop(x1, y1, x2, y2): Clicks [x1, y1], drags mouse to [x2, y2], then releases click.
|
245 |
-
- find_on_page_ctrl_f(search_string): Scroll the viewport to the first occurrence of the search string. This is equivalent to Ctrl+F.
|
246 |
-
- final_answer("YOUR FINAL ANSWER TEXT"): Announces that the task requested is completed and provides a final text
|
247 |
-
The desktop has a resolution of {resolution_x}x{resolution_y}.
|
248 |
-
IMPORTANT:
|
249 |
-
- Remember the tools that you have as those can save you time, for example open_url to enter a website rather than searching for the browser in the OS.
|
250 |
-
- Whenever you click, MAKE SURE to click in the middle of the button, text, link or any other clickable element. Not under, not on the side. IN THE MIDDLE. In menus it is always better to click in the middle of the text rather than in the tiny icon. Calculate extremelly well the coordinates. A mistake here can make the full task fail.
|
251 |
-
- To navigate the desktop you should open menus and click. Menus usually expand with more options, the tiny triangle next to some text in a menu means that menu expands. For example in Office in the Applications menu expands showing presentation or writing applications.
|
252 |
-
- Always analyze the latest screenshot carefully before performing actions. If you clicked somewhere in the previous action and in the screenshot nothing happened, make sure the mouse is where it should be. Otherwise you can see that the coordinates were wrong.
|
253 |
-
You must proceed step by step:
|
254 |
-
1. Understand the task thoroughly
|
255 |
-
2. Break down the task into logical steps
|
256 |
-
3. For each step:
|
257 |
-
a. Analyze the current screenshot to identify UI elements
|
258 |
-
b. Plan the appropriate action with precise coordinates
|
259 |
-
c. Execute ONE action at a time using the proper tool
|
260 |
-
d. Wait for the action to complete before proceeding
|
261 |
-
After each action, you'll receive an updated screenshot. Review it carefully before your next action.
|
262 |
-
COMMAND FORMAT:
|
263 |
-
Always format your actions as Python code blocks. For example:
|
264 |
-
```python
|
265 |
-
click(250, 304)
|
266 |
-
```<end_code>
|
267 |
-
TASK EXAMPLE:
|
268 |
-
For a task like "Open a text editor and type 'Hello World'":
|
269 |
-
1- First, analyze the screenshot to find the Applications menu and click on it being very precise, clicking in the middle of the text 'Applications':
|
270 |
-
```python
|
271 |
-
click(52, 10)
|
272 |
-
```<end_code>
|
273 |
-
2- Remembering that menus are navigated through clicking, after analyzing the screenshot with the applications menu open we see that a notes application probably fits in the Accessories section (we see it is a section in the menu thanks to the tiny white triangle after the text accessories). We look for Accessories and click on it being very precise, clicking in the middle of the text 'Accessories'. DO NOT try to move through the menus with scroll, it won't work:
|
274 |
-
```python
|
275 |
-
click(76, 195)
|
276 |
-
```<end_code>
|
277 |
-
3- Remembering that menus are navigated through clicking, after analyzing the screenshot with the submenu Accessories open, look for 'Text Editor' and click on it being very precise, clicking in the middle of the text 'Text Editor':
|
278 |
-
```python
|
279 |
-
click(241, 441)
|
280 |
-
```<end_code>
|
281 |
-
4- Once Notepad is open, type the requested text:
|
282 |
-
```python
|
283 |
-
type_text("Hello World")
|
284 |
-
```<end_code>
|
285 |
-
5- Task is completed:
|
286 |
-
```python
|
287 |
-
final_answer("Done")
|
288 |
-
```<end_code>
|
289 |
-
Remember to:
|
290 |
-
Always wait for appropriate loading times
|
291 |
-
Use precise coordinates based on the current screenshot
|
292 |
-
Execute one action at a time
|
293 |
-
Verify the result before proceeding to the next step
|
294 |
-
Use click to move through menus on the desktop and scroll for web and specific applications.
|
295 |
-
REMEMBER TO ALWAYS CLICK IN THE MIDDLE OF THE TEXT, NOT ON THE SIDE, NOT UNDER.
|
296 |
-
""".format(resolution_x=self.width, resolution_y=self.height)
|
297 |
-
else:
|
298 |
-
print("USING v2 prompt")
|
299 |
-
system_prompt = populate_template(
|
300 |
-
self.prompt_templates["system_prompt"],
|
301 |
-
variables={
|
302 |
-
"tools": self.tools,
|
303 |
-
"managed_agents": self.managed_agents,
|
304 |
-
"authorized_imports": (
|
305 |
-
"You can import from any package you want."
|
306 |
-
if "*" in self.authorized_imports
|
307 |
-
else str(self.authorized_imports)
|
308 |
-
),
|
309 |
-
},
|
310 |
-
)
|
311 |
-
assert system_prompt != self.prompt_templates["system_prompt"], (
|
312 |
-
"Populating prompt template failed"
|
313 |
-
)
|
314 |
-
return system_prompt
|
315 |
-
|
316 |
def _setup_desktop_tools(self):
|
317 |
"""Register all desktop tools"""
|
318 |
|
@@ -508,7 +399,7 @@ REMEMBER TO ALWAYS CLICK IN THE MIDDLE OF THE TEXT, NOT ON THE SIDE, NOT UNDER.
|
|
508 |
|
509 |
current_step = memory_step.step_number
|
510 |
|
511 |
-
time.sleep(
|
512 |
screenshot_bytes = self.desktop.screenshot(format="bytes")
|
513 |
image = Image.open(BytesIO(screenshot_bytes))
|
514 |
|
@@ -518,9 +409,9 @@ REMEMBER TO ALWAYS CLICK IN THE MIDDLE OF THE TEXT, NOT ON THE SIDE, NOT UNDER.
|
|
518 |
|
519 |
image_copy = image.copy()
|
520 |
|
521 |
-
if getattr(self, "click_coordinates", None):
|
522 |
-
|
523 |
-
|
524 |
|
525 |
self.last_marked_screenshot = AgentImage(screenshot_path)
|
526 |
print(f"Saved screenshot for step {current_step} to {screenshot_path}")
|
|
|
12 |
from smolagents import CodeAgent, tool, HfApiModel
|
13 |
from smolagents.memory import ActionStep, TaskStep
|
14 |
from smolagents.models import ChatMessage, Model
|
|
|
15 |
from smolagents.monitoring import LogLevel
|
16 |
from smolagents.agent_types import AgentImage
|
17 |
from PIL import ImageDraw
|
18 |
from datetime import datetime
|
19 |
|
20 |
+
E2B_SYSTEM_PROMPT_TEMPLATE = """You are a desktop automation assistant that can control a remote desktop environment. The current date is <<current_date>>.
|
21 |
+
|
22 |
<action process>
|
23 |
You will be given a task to solve in several steps. At each step you will perform an action.
|
24 |
After each action, you'll receive an updated screenshot.
|
25 |
Then you will proceed as follows, with these sections: don't skip any!
|
26 |
|
27 |
Short term goal: ...
|
|
|
28 |
What I see: ...
|
29 |
Reflection: ...
|
30 |
+
Action:
|
|
|
31 |
```python
|
32 |
click(254, 308)
|
33 |
```<end_code>
|
34 |
+
|
35 |
+
Akways format your action ('Action:' part) as Python code blocks as shown above.
|
36 |
</action_process>
|
37 |
|
38 |
<tools>
|
|
|
42 |
Takes inputs: {{tool.inputs}}
|
43 |
Returns an output of type: {{tool.output_type}}
|
44 |
{%- endfor %}
|
|
|
|
|
|
|
|
|
45 |
</tools>
|
46 |
|
47 |
+
<click_guidelines>
|
48 |
+
Look at elements on the screen to determine what to click or interact with.
|
49 |
+
The desktop has a resolution of <<resolution_x>>x<<resolution_y>> pixels, take it into account to decide clicking coordinates. NEVER USE HYPOTHETIC OR ASSUMED COORDINATES, USE TRUE COORDINATES that you can see from the screenshot.
|
50 |
+
Use precise coordinates based on the current screenshot for mouse movements and clicks.
|
51 |
+
Whenever you click, MAKE SURE to click in the middle of the button, text, link or any other clickable element. Not under, not on the side. IN THE MIDDLE, else you risk to miss it.
|
52 |
+
In menus it is always better to click in the middle of the text rather than in the tiny icon. Calculate extremelly well the coordinates. A mistake here can make the full task fail.
|
53 |
+
Sometimes you may have missed a click, so never assume that you're on the right page, always make sure that your previous action worked. In the screenshot you can see if the mouse pointer is off of the targeted element, pay special attention to it.
|
54 |
+
</click_guidelines>
|
55 |
|
56 |
<task_resolution_example>
|
57 |
For a task like "Open a text editor and type 'Hello World'":
|
58 |
Step 1:
|
59 |
Short term goal: I want to open a text editor.
|
60 |
+
What I see: I am on the homepage of my desktop. I see the applications
|
61 |
+
Reflection: I think that a notes application would fit in the Applications menu, let's open it. I'll carefully click in the middle of the text 'Applications'/
|
62 |
+
Action:
|
|
|
|
|
63 |
```python
|
64 |
click(51, 8)
|
65 |
```<end_code>
|
66 |
|
67 |
Step 2:
|
68 |
Short term goal: I want to open a text editor.
|
69 |
+
What I see: I am on the homepage of my desktop, with the applications menu open. I see an Accessories section, I see it is a section in the menu thanks to the tiny white triangle after the text accessories.
|
70 |
+
Reflection: I think that a notes application would fit the Accessories section. I SHOULD NOT try to move through the menus with scroll, it won't work:
|
71 |
+
I'll look for Accessories and click on it being very precise, clicking in the middle of the text 'Accessories'.
|
72 |
+
Action:
|
|
|
73 |
```python
|
74 |
click(76, 195)
|
75 |
```<end_code>
|
76 |
|
77 |
Step 3:
|
78 |
Short term goal: I want to open a text editor.
|
79 |
+
What I see: I am under the Accessories menu. Under the open submenu Accessories, I've found 'Text Editor'.
|
80 |
+
Reflection: This must be my notes app. I remember that menus are navigated through clicking. I will now click on it being very precise, clicking in the middle of the text 'Text Editor'.
|
81 |
+
Action:
|
|
|
|
|
82 |
```python
|
83 |
click(251, 441)
|
84 |
```<end_code>
|
85 |
|
86 |
Step 4:
|
87 |
Short term goal: I want to open a text editor.
|
88 |
+
What I see: I am still under the Accessories menu. Nothing has changed compared to previous screenshot. Under the open submenu Accessories, I still see 'Text Editor'. The green cross is off from the element.
|
89 |
+
Reflection: My last click must have been off. Let's correct this. I will click the correct place, right in the middle of the element.
|
90 |
+
Action:
|
|
|
|
|
91 |
```python
|
92 |
click(241, 441)
|
93 |
```<end_code>
|
94 |
|
95 |
Step 5:
|
96 |
Short term goal: I want to type 'Hello World'.
|
97 |
+
What I see: I have opened a Notepad. The Notepad app is open on an empty page
|
|
|
98 |
Reflection: Now Notepad is open as intended, time to type text.
|
99 |
+
Action:
|
|
|
100 |
```python
|
101 |
type_text("Hello World")
|
102 |
```<end_code>
|
103 |
|
104 |
Step 6:
|
105 |
Short term goal: I want to type 'Hello World'.
|
|
|
106 |
What I see: The Notepad app displays 'Hello World'
|
107 |
+
Reflection: Now that I've 1. Opened the notepad and 2. typed 'Hello World', and 3. the result seems correct, I think the Task is completed. I will return a confirmation that the task is completed.
|
108 |
+
Action:
|
|
|
109 |
```python
|
110 |
final_answer("Done")
|
111 |
```<end_code>
|
112 |
</task_resolution_example>
|
113 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
114 |
<general_guidelines>
|
115 |
Always analyze the latest screenshot carefully before performing actions.
|
116 |
You can wait for appropriate loading times using the wait() tool. But don't wait forever, sometimes you've just misclicked and the process didn't launch.
|
|
|
120 |
Always analyze the latest screenshot carefully before performing actions.
|
121 |
Desktop menus usually expand with more options, the tiny triangle next to some text in a menu means that menu expands. For example in Office in the Applications menu expands showing presentation or writing applications.
|
122 |
NEVER CLICK THE WEB BROWSER ICON TO OPEN THE WEB BROWSER: use open_url directly.
|
123 |
+
In browser, ignore any sign-in popups while they don't interfere with the elements you want to interact with.
|
124 |
</general_guidelines>
|
125 |
""".replace("<<current_date>>", datetime.now().strftime("%A, %d-%B-%Y"))
|
126 |
|
|
|
204 |
self._setup_desktop_tools()
|
205 |
self.step_callbacks.append(self.take_screenshot_callback)
|
206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
def _setup_desktop_tools(self):
|
208 |
"""Register all desktop tools"""
|
209 |
|
|
|
399 |
|
400 |
current_step = memory_step.step_number
|
401 |
|
402 |
+
time.sleep(2.5) # Let things happen on the desktop
|
403 |
screenshot_bytes = self.desktop.screenshot(format="bytes")
|
404 |
image = Image.open(BytesIO(screenshot_bytes))
|
405 |
|
|
|
409 |
|
410 |
image_copy = image.copy()
|
411 |
|
412 |
+
# if getattr(self, "click_coordinates", None):
|
413 |
+
# print("DRAWING MARKER")
|
414 |
+
# image_copy = draw_marker_on_image(image_copy, self.click_coordinates)
|
415 |
|
416 |
self.last_marked_screenshot = AgentImage(screenshot_path)
|
417 |
print(f"Saved screenshot for step {current_step} to {screenshot_path}")
|
eval.py
CHANGED
@@ -74,7 +74,7 @@ def create_agent(data_dir, desktop, max_steps: int):
|
|
74 |
desktop=desktop,
|
75 |
max_steps=max_steps,
|
76 |
verbosity_level=2,
|
77 |
-
planning_interval=10,
|
78 |
)
|
79 |
|
80 |
|
@@ -346,7 +346,7 @@ def main():
|
|
346 |
"gmaps": "Use Google Maps to find the Hugging Face HQ in Paris",
|
347 |
"wiki": "Go to Wikipedia and find what happend on April 4th",
|
348 |
"hello": "Write 'Hello World' in a text editor",
|
349 |
-
"commute": "Find out
|
350 |
"hf_space": "Go to Hugging Face Spaces and then find the Space flux.1 schnell. Use the space to generate an image of a GPU",
|
351 |
}
|
352 |
|
|
|
74 |
desktop=desktop,
|
75 |
max_steps=max_steps,
|
76 |
verbosity_level=2,
|
77 |
+
# planning_interval=10,
|
78 |
)
|
79 |
|
80 |
|
|
|
346 |
"gmaps": "Use Google Maps to find the Hugging Face HQ in Paris",
|
347 |
"wiki": "Go to Wikipedia and find what happend on April 4th",
|
348 |
"hello": "Write 'Hello World' in a text editor",
|
349 |
+
"commute": "Find out the travel time by train from Bern to Basel on Google Maps",
|
350 |
"hf_space": "Go to Hugging Face Spaces and then find the Space flux.1 schnell. Use the space to generate an image of a GPU",
|
351 |
}
|
352 |
|