ZHZisZZ commited on
Commit
6991897
·
1 Parent(s): 22899da

action space mapping modifified (scroll/hscroll)

Browse files
cua_lite/data/interfaces/qwen3_vl.py CHANGED
@@ -121,7 +121,7 @@ Please generate the next move according to the UI screenshot, instruction and pr
121
  Instruction: {instruction}
122
 
123
  Previous actions:
124
- {previous_actions_str}"""
125
 
126
 
127
  @dataclasses.dataclass
@@ -211,7 +211,11 @@ class Qwen3VLDataInterface(UnrolledContextDataInterface):
211
 
212
  processed_messages.append(new_anchor_user)
213
  if anchor_step["assistant"]:
214
- processed_messages.append(anchor_step["assistant"])
 
 
 
 
215
 
216
  # --- 追加剩余步骤 ---
217
  for i in range(truncate_count + 1, total_steps):
@@ -222,7 +226,11 @@ class Qwen3VLDataInterface(UnrolledContextDataInterface):
222
  processed_messages.append(u)
223
  # ================================================================
224
  if steps[i]["assistant"]:
225
- processed_messages.append(steps[i]["assistant"])
 
 
 
 
226
 
227
  return {"messages": processed_messages}
228
 
@@ -239,12 +247,10 @@ if __name__ == "__main__":
239
  dataset = load_from_disk(".data/unzipped/scalecua/ubuntu/shard-00000-of-00256")
240
  dataset.set_transform(clean_nones)
241
 
242
- qwen3vl_interface = Qwen3VLDataInterface(history_n=4)
243
  dataset_mapped = dataset.map(
244
  qwen3vl_interface.process_context_batch, batched=True, batch_size=1000
245
  )
246
 
247
- inputs = processor.apply_chat_template(
248
- dataset_mapped["messages"][0], return_dict=True
249
- )
250
  breakpoint()
 
121
  Instruction: {instruction}
122
 
123
  Previous actions:
124
+ {previous_actions}"""
125
 
126
 
127
  @dataclasses.dataclass
 
211
 
212
  processed_messages.append(new_anchor_user)
213
  if anchor_step["assistant"]:
214
+ asst_msg = copy.deepcopy(anchor_step["assistant"])
215
+ # Prepend "Action: " using a clean reference
216
+ content_node = asst_msg["content"][0]
217
+ content_node["text"] = "Action: " + content_node["text"]
218
+ processed_messages.append(asst_msg)
219
 
220
  # --- 追加剩余步骤 ---
221
  for i in range(truncate_count + 1, total_steps):
 
226
  processed_messages.append(u)
227
  # ================================================================
228
  if steps[i]["assistant"]:
229
+ asst_msg = copy.deepcopy(steps[i]["assistant"])
230
+ # Prepend "Action: " using a clean reference
231
+ content_node = asst_msg["content"][0]
232
+ content_node["text"] = "Action: " + content_node["text"]
233
+ processed_messages.append(asst_msg)
234
 
235
  return {"messages": processed_messages}
236
 
 
247
  dataset = load_from_disk(".data/unzipped/scalecua/ubuntu/shard-00000-of-00256")
248
  dataset.set_transform(clean_nones)
249
 
250
+ qwen3vl_interface = Qwen3VLDataInterface(history_n=0)
251
  dataset_mapped = dataset.map(
252
  qwen3vl_interface.process_context_batch, batched=True, batch_size=1000
253
  )
254
 
255
+ inputs = processor.apply_chat_template(dataset_mapped["messages"][1], return_dict=True)
 
 
256
  breakpoint()
cua_lite/data/interfaces/qwen3_vl/interfaces.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import dataclasses
2
+ import json
3
+ import copy
4
+ from typing import Callable, Any
5
+
6
+ from cua_lite.data.interfaces.base import UnrolledContextDataInterface
7
+ from cua_lite.data.interfaces.qwen3_vl.prompts import (
8
+ INSTRUCTION_PROMPT, DESKTOP_SYSTEM_PROMPT_V0, DESKTOP_SYSTEM_PROMPT_V1, MOBILE_SYSTEM_PROMPT
9
+ )
10
+
11
+
12
+
13
+ @dataclasses.dataclass
14
+ class Qwen3VLDataInterface(UnrolledContextDataInterface):
15
+
16
+ history_n: int = 4
17
+ add_system_prompt: bool = True
18
+
19
+ def process_context(self, row: dict[str, Any]) -> dict[str, Any]:
20
+ # 1. 基础拆分
21
+ messages = row["messages"]
22
+
23
+ # 2. 按 Step 分组 (User + Assistant)
24
+ steps = []
25
+ for i in range(0, len(messages), 2):
26
+ step = {
27
+ "user": messages[i],
28
+ "assistant": messages[i + 1] if i + 1 < len(messages) else None,
29
+ }
30
+ steps.append(step)
31
+
32
+ total_steps = len(steps)
33
+
34
+ # 3. 计算保留逻辑
35
+ steps_to_keep = self.history_n + 1
36
+
37
+ # ======== FIX 1: 不要在这里 return ========
38
+ # 如果总步数不够截断,就令 truncate_count=0(anchor=Step1),但仍然重写 INSTR_PROMPT
39
+ truncate_count = max(0, total_steps - steps_to_keep)
40
+ # =========================================
41
+
42
+ # 4. 提取 Step 1 的指令
43
+ step1_content = steps[0]["user"]["content"]
44
+ instruction_text = next(
45
+ item["text"] for item in step1_content if item.get("type") == "text"
46
+ )
47
+
48
+ # if "Previous actions" in instruction_text:
49
+ # instruction_text = instruction_text.split("Previous actions")[0].strip()
50
+
51
+ # # 规范成 “纯 instruction 内容”
52
+ # if instruction_text.startswith("Instruction:"):
53
+ # instruction_text = instruction_text[len("Instruction:"):].strip()
54
+
55
+ # 5. 生成历史摘要(被截断掉的那些步)
56
+ summary_lines = []
57
+ for i in range(truncate_count):
58
+ action = (
59
+ steps[i]["assistant"]["content"]
60
+ if isinstance(steps[i]["assistant"]["content"], str)
61
+ else steps[i]["assistant"]["content"][0]["text"]
62
+ )
63
+ summary_lines.append(f"Step {i+1}: {action}")
64
+
65
+ summary_block = "\n".join(summary_lines) if summary_lines else "None"
66
+
67
+ # 生成与 QwenAgent 一致的 INSTR_PROMPT
68
+ # full_text_prompt = (
69
+ # "\nPlease generate the next move according to the UI screenshot, instruction and previous actions.\n\n"
70
+ # f"Instruction: {instruction_text}\n\n"
71
+ # "Previous actions:\n"
72
+ # f"{summary_block}"
73
+ # )
74
+ full_text_prompt = INSTRUCTION_PROMPT.format(
75
+ instruction=instruction_text,
76
+ previous_actions=summary_block,
77
+ )
78
+
79
+ # 6. 构建新消息列表
80
+ processed_messages = []
81
+ if self.add_system_prompt:
82
+ processed_messages.append(
83
+ {"role": "system", "content": [{"type": "text", "text": SYSTEM_PROMPT}]}
84
+ )
85
+
86
+ # --- Anchor Step (新起点) ---
87
+ anchor_step = steps[truncate_count]
88
+ new_anchor_user = copy.deepcopy(anchor_step["user"])
89
+
90
+ # 找到 User 消息里的 text 字段并修改,或者追加
91
+ text_item = next(
92
+ (item for item in new_anchor_user["content"] if item.get("type") == "text"),
93
+ None,
94
+ )
95
+ if text_item:
96
+ text_item["text"] = full_text_prompt
97
+ else:
98
+ new_anchor_user["content"].append(
99
+ {"type": "text", "text": full_text_prompt}
100
+ )
101
+
102
+ processed_messages.append(new_anchor_user)
103
+ if anchor_step["assistant"]:
104
+ asst_msg = copy.deepcopy(anchor_step["assistant"])
105
+ # Prepend "Action: " using a clean reference
106
+ content_node = asst_msg["content"][0]
107
+ content_node["text"] = "Action: " + content_node["text"]
108
+ processed_messages.append(asst_msg)
109
+
110
+ # --- 追加剩余步骤 ---
111
+ for i in range(truncate_count + 1, total_steps):
112
+ # ======== FIX 2: 对齐 QwenAgent:非 anchor 的 user 只保留 image 部分 ========
113
+ u = copy.deepcopy(steps[i]["user"])
114
+ if isinstance(u.get("content"), list):
115
+ u["content"] = [it for it in u["content"] if it.get("type") != "text"]
116
+ processed_messages.append(u)
117
+ # ================================================================
118
+ if steps[i]["assistant"]:
119
+ asst_msg = copy.deepcopy(steps[i]["assistant"])
120
+ # Prepend "Action: " using a clean reference
121
+ content_node = asst_msg["content"][0]
122
+ content_node["text"] = "Action: " + content_node["text"]
123
+ processed_messages.append(asst_msg)
124
+
125
+ return {"messages": processed_messages}
126
+
127
+
128
+ if __name__ == "__main__":
129
+ from datasets import load_from_disk
130
+ from transformers import AutoProcessor
131
+ from cua_lite.data.utils import clean_nones
132
+
133
+ processor = AutoProcessor.from_pretrained(
134
+ "/mnt/lustrenew/mllm_aligned/shared/models/huggingface/Qwen/Qwen3-VL-2B-Thinking"
135
+ )
136
+
137
+ dataset = load_from_disk(".data/unzipped/scalecua/ubuntu/shard-00000-of-00256")
138
+ dataset.set_transform(clean_nones)
139
+
140
+ qwen3vl_interface = Qwen3VLDataInterface(history_n=0)
141
+ dataset_mapped = dataset.map(
142
+ qwen3vl_interface.process_context_batch, batched=True, batch_size=1000
143
+ )
144
+
145
+ inputs = processor.apply_chat_template(dataset_mapped["messages"][1], return_dict=True)
146
+ breakpoint()
cua_lite/data/interfaces/qwen3_vl/prompts/__init__.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from .common import SYSTEM_PROMPT, INSTRUCTION_PROMPT
2
+ from .desktop import (
3
+ DESKTOP_SYSTEM_PROMPT_V0,
4
+ DESKTOP_TOOLS_DEF_V0,
5
+ DESKTOP_SYSTEM_PROMPT_V1,
6
+ DESKTOP_TOOLS_DEF_V1,
7
+ )
8
+ from .mobile import MOBILE_SYSTEM_PROMPT, MOBILE_TOOLS_DEF
cua_lite/data/interfaces/qwen3_vl/prompts/common.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ SYSTEM_PROMPT = (
2
+ """# Tools
3
+
4
+ You may call one or more functions to assist with the user query.
5
+
6
+ You are provided with function signatures within <tools></tools> XML tags:
7
+ <tools>
8
+ """
9
+ + "{tools_def}"
10
+ + """
11
+ </tools>
12
+
13
+ For each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:
14
+ <tool_call>
15
+ {"name": <function-name>, "arguments": <args-json-object>}
16
+ </tool_call>
17
+
18
+ # Response format
19
+
20
+ Response format for every step:
21
+ 1) Action: a short imperative describing what to do in the UI.
22
+ 2) A single <tool_call>...</tool_call> block containing only the JSON: {"name": <function-name>, "arguments": <args-json-object>}.
23
+
24
+ Rules:
25
+ - Output exactly in the order: Action, <tool_call>.
26
+ - Be brief: one sentence for Action.
27
+ - Do not output anything else outside those parts.
28
+ - If finishing, use action=terminate in the tool call."""
29
+ )
30
+
31
+
32
+ INSTRUCTION_PROMPT = """
33
+ Please generate the next move according to the UI screenshot, instruction and previous actions.
34
+
35
+ Instruction: {instruction}
36
+
37
+ Previous actions:
38
+ {previous_actions}"""
cua_lite/data/interfaces/qwen3_vl/prompts/desktop.py ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ from .common import SYSTEM_PROMPT
4
+
5
+
6
+ DESKTOP_DESCRIPTION_PROMPT = """Use a mouse and keyboard to interact with a computer, and take screenshots.
7
+ * This is an interface to a desktop GUI. You do not have access to a terminal or applications menu. You must click on desktop icons to start applications.
8
+ * Some applications may take time to start or process actions, so you may need to wait and take successive screenshots to see the results of your actions. For example, if you click on Firefox and a window does not open, try waiting and then taking another screenshot.
9
+ * The screen resolution is 1000x1000.
10
+ * Whenever you intend to move the cursor to click on an element such as an icon, consult a screenshot first to determine the element’s coordinates before moving the cursor.
11
+ * If you tried clicking on a program or link but it failed to load even after waiting, adjust your cursor position so that the tip of the cursor visually falls on the element you want to click.
12
+ * Make sure to click any buttons, links, icons, or other elements with the cursor tip in the center of the element. Do not click on edges unless explicitly instructed.\
13
+ """
14
+
15
+ # v0 (https://github.com/xlang-ai/OSWorld/blob/main/mm_agents/qwen3vl_agent.py)
16
+ DESKTOP_ACTION_DESCRIPTION_PROMPT_V0 = """\
17
+ * `key`: Performs key down presses on the arguments passed in order, then performs key releases in reverse order.
18
+ * `type`: Type a string of text on the keyboard.
19
+ * `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on the screen.
20
+ * `left_click`: Click the left mouse button at a specified (x, y) pixel coordinate on the screen.
21
+ * `left_click_drag`: Click and drag the cursor to a specified (x, y) pixel coordinate on the screen.
22
+ * `right_click`: Click the right mouse button at a specified (x, y) pixel coordinate on the screen.
23
+ * `middle_click`: Click the middle mouse button at a specified (x, y) pixel coordinate on the screen.
24
+ * `double_click`: Double-click the left mouse button at a specified (x, y) pixel coordinate on the screen.
25
+ * `triple_click`: Triple-click the left mouse button at a specified (x, y) pixel coordinate on the screen (simulated as double-click since it's the closest action).
26
+ * `scroll`: Performs a scroll of the mouse scroll wheel.
27
+ * `hscroll`: Performs a horizontal scroll (mapped to regular scroll).
28
+ * `wait`: Wait specified seconds for the change to happen.
29
+ * `terminate`: Terminate the current task and report its completion status.
30
+ * `answer`: Answer a question.\
31
+ """
32
+
33
+ DESKTOP_TOOLS_DEF_V0 = {
34
+ "type": "function",
35
+ "function": {
36
+ "name_for_human": "desktop_use",
37
+ "name": "desktop_use",
38
+ "description": DESKTOP_DESCRIPTION_PROMPT,
39
+ "parameters": {
40
+ "properties": {
41
+ "action": {
42
+ "description": DESKTOP_ACTION_DESCRIPTION_PROMPT_V0,
43
+ "enum": [
44
+ "key",
45
+ "type",
46
+ "mouse_move",
47
+ "left_click",
48
+ "left_click_drag",
49
+ "right_click",
50
+ "middle_click",
51
+ "double_click",
52
+ "scroll",
53
+ "wait",
54
+ "terminate",
55
+ ],
56
+ "type": "string",
57
+ },
58
+ "keys": {
59
+ "description": "Required only by `action=key`.",
60
+ "type": "array",
61
+ },
62
+ "text": {
63
+ "description": "Required only by `action=type`.",
64
+ "type": "string",
65
+ },
66
+ "coordinate": {
67
+ "description": "The x,y coordinates for mouse actions.",
68
+ "type": "array",
69
+ },
70
+ "pixels": {"description": "The amount of scrolling.", "type": "number"},
71
+ "time": {"description": "The seconds to wait.", "type": "number"},
72
+ "status": {
73
+ "description": "The status of the task.",
74
+ "type": "string",
75
+ "enum": ["success", "failure"],
76
+ },
77
+ },
78
+ "required": ["action"],
79
+ "type": "object",
80
+ },
81
+ "args_format": "Format the arguments as a JSON object.",
82
+ },
83
+ }
84
+
85
+ DESKTOP_SYSTEM_PROMPT_V0 = SYSTEM_PROMPT.format(tools_def=json.dumps(DESKTOP_TOOLS_DEF_V0))
86
+
87
+
88
+ # v1
89
+ DESKTOP_ACTION_DESCRIPTION_PROMPT_V1 = """\
90
+ * `key(keys=["key1", "key2"])`: Press the keys in order (key down), then release them in reverse order (key up).
91
+ * `type(text="string")`: Type the given text.
92
+ * `mouse_move(coordinate=[x, y])`: Move the cursor to (x, y).
93
+ * `left_click(coordinate=[x, y][, keys=["key"]])`: Left click at (x, y). If `keys` is provided, hold those keys while clicking.
94
+ * `left_click_drag(coordinate=[x, y][, keys=["key"]])`: Drag to (x, y) with the left mouse button. If `keys` is provided, hold those keys while dragging.
95
+ * `right_click(coordinate=[x, y][, keys=["key"]])`: Right click at (x, y). If `keys` is provided, hold those keys while clicking.
96
+ * `middle_click(coordinate=[x, y][, keys=["key"]])`: Middle click at (x, y). If `keys` is provided, hold those keys while clicking.
97
+ * `double_click(coordinate=[x, y][, keys=["key"]])`: Double left click at (x, y). If `keys` is provided, hold those keys while double-clicking.
98
+ * `triple_click(coordinate=[x, y][, keys=["key"]])`: Triple left click at (x, y). If `keys` is provided, hold those keys while double-clicking.
99
+ * `scroll(pixels=number[, keys=["key"]])`: Scroll vertically. `pixels > 0` scrolls up, `pixels < 0` scrolls down. If `keys` is provided, hold those keys while scrolling.
100
+ * `hscroll(pixels=number[, keys=["key"]])`: Scroll horizontally. `pixels > 0` scrolls right, `pixels < 0` scrolls left. If `keys` is provided, hold those keys while scrolling.
101
+ * `wait(time=seconds)`: Wait for the given number of seconds.
102
+ * `terminate(status="success"|"failure")`: End the task and report the status.
103
+ * `answer(text="answer")`: Return a final answer in text.\
104
+ """
105
+
106
+ DESKTOP_TOOLS_DEF_V1 = {
107
+ "type": "function",
108
+ "function": {
109
+ "name_for_human": "desktop_use",
110
+ "name": "desktop_use",
111
+ "description": DESKTOP_DESCRIPTION_PROMPT,
112
+ "parameters": {
113
+ "properties": {
114
+ "action": {
115
+ "description": DESKTOP_ACTION_DESCRIPTION_PROMPT_V1,
116
+ "enum": [
117
+ "key",
118
+ "type",
119
+ "mouse_move",
120
+ "left_click",
121
+ "left_click_drag",
122
+ "right_click",
123
+ "middle_click",
124
+ "double_click",
125
+ "triple_click",
126
+ "scroll",
127
+ "hscroll",
128
+ "wait",
129
+ "terminate",
130
+ "answer"
131
+ ],
132
+ "type": "string",
133
+ },
134
+ "keys": {
135
+ "description": (
136
+ "Keys to press/hold.\n"
137
+ "Required only for action: `key` (press in order, release in reverse).\n"
138
+ "Optional only for actions: `left_click`, `left_click_drag`, `right_click`, `middle_click`, `double_click`, `double_click`, `scroll`, `hscroll` (hold these keys while performing the action).\n"
139
+ ),
140
+ "type": "array",
141
+ },
142
+ "text": {
143
+ "description": "The text content to type or the answer to return. Required only for actions: `type`, `answer`.",
144
+ "type": "string",
145
+ },
146
+ "coordinate": {
147
+ "description": "The (x, y) pixel coordinate on the screen. Required only for actions: `mouse_move`, `left_click`, `left_click_drag`, `right_click`, `middle_click`, `double_click`, `triple_click`.",
148
+ "type": "array",
149
+ },
150
+ "pixels": {
151
+ "description": "The amount of scrolling to perform. Required only fors actions: `scroll`, `hscroll`.",
152
+ "type": "number"
153
+ },
154
+ "time": {
155
+ "description": "The duration to wait in seconds. Required only for action: `wait`.",
156
+ "type": "number"
157
+ },
158
+ "status": {
159
+ "description": "The completion status of the task. Required only for action: `terminate`.",
160
+ "type": "string",
161
+ "enum": ["success", "failure"],
162
+ },
163
+ },
164
+ "required": ["action"],
165
+ "type": "object",
166
+ },
167
+ "args_format": "Format the arguments as a JSON object.",
168
+ },
169
+ }
170
+
171
+ DESKTOP_SYSTEM_PROMPT_V1 = SYSTEM_PROMPT.format(tools_def=json.dumps(DESKTOP_TOOLS_DEF_V1))
cua_lite/data/interfaces/qwen3_vl/prompts/mobile.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+
3
+ from .common import SYSTEM_PROMPT
4
+
5
+
6
+ MOBILE_DESCRIPTION_PROMPT = """Use touch gestures to interact with a mobile device, and take screenshots.
7
+ * This is an interface to a mobile GUI. You do not have access to physical buttons directly unless emulated. You must tap on screen icons to start applications.
8
+ * Some applications may take time to start or process actions, so you may need to wait and take successive screenshots to see the results of your actions.
9
+ * The screen resolution is 1000x1000.
10
+ * If you tried tapping on a button or link but it failed to load even after waiting, adjust your tap position so that it falls on the center of the element.
11
+ * Make sure to tap any buttons, links, icons, or other elements with the coordinate in the center of the element.
12
+ """
13
+
14
+ MOBILE_ACTION_DESCRIPTION_PROMPT = """\
15
+ * `tap`: Tap at a specific (x, y) pixel coordinate on the screen. Used for buttons, icons, list items, etc.
16
+ * `swipe`: Swipe the screen in a specific direction. Used for scrolling pages, lists, galleries, etc.
17
+ * `type`: Input a text string into the currently focused text field. Used for search bars, messages, form filling.
18
+ * `back`: Perform the system-level back action (Android back navigation).
19
+ * `home`: Return to the home screen (cross-app transitions).
20
+ * `wait`: Wait specified seconds for the change to happen.
21
+ * `terminate`: Terminate the current task and report its completion status.
22
+ * `answer`: Answer a question.\
23
+ """
24
+
25
+ MOBILE_TOOLS_DEF = {
26
+ "type": "function",
27
+ "function": {
28
+ "name_for_human": "mobile_use",
29
+ "name": "mobile_use",
30
+ "description": MOBILE_DESCRIPTION_PROMPT,
31
+ "parameters": {
32
+ "properties": {
33
+ "action": {
34
+ "description": MOBILE_ACTION_DESCRIPTION_PROMPT,
35
+ "enum": [
36
+ "tap",
37
+ "swipe",
38
+ "type",
39
+ "back",
40
+ "home",
41
+ "wait",
42
+ "terminate",
43
+ ],
44
+ "type": "string",
45
+ },
46
+ "text": {
47
+ "description": "Required only by `action=type`.",
48
+ "type": "string",
49
+ },
50
+ "coordinate": {
51
+ "description": "The x,y coordinates for `tap` action.",
52
+ "type": "array",
53
+ },
54
+ "direction": {
55
+ "description": "Required only by `action=swipe`. The direction to swipe.",
56
+ "type": "string",
57
+ "enum": ["up", "down", "left", "right"]
58
+ },
59
+ "time": {"description": "The seconds to wait.", "type": "number"},
60
+ "status": {
61
+ "description": "The status of the task.",
62
+ "type": "string",
63
+ "enum": ["success", "failure"],
64
+ },
65
+ },
66
+ "required": ["action"],
67
+ "type": "object",
68
+ },
69
+ "args_format": "Format the arguments as a JSON object.",
70
+ },
71
+ }
72
+
73
+ MOBILE_SYSTEM_PROMPT = SYSTEM_PROMPT.format(tools_def=json.dumps(MOBILE_TOOLS_DEF))
cua_lite/data/preproc/opencua/opencua.py CHANGED
@@ -214,7 +214,7 @@ def agentnet_code_to_qwen_tool_calls(code: str) -> List[Dict[str, Any]]:
214
  x, y = _extract_xy(call)
215
  tool_calls.append(
216
  _make_computer_use_tool_call(
217
- {"action": "double_click", "coordinate": _norm01_to_0_1000(x, y)}
218
  )
219
  )
220
  continue
@@ -251,9 +251,14 @@ def agentnet_code_to_qwen_tool_calls(code: str) -> List[Dict[str, Any]]:
251
  f"scroll/hscroll requires a pixels argument.\ncode=\n{code}"
252
  )
253
  pixels = int(_literal_eval(call.args[0]))
254
- tool_calls.append(
255
- _make_computer_use_tool_call({"action": "scroll", "pixels": pixels})
256
- )
 
 
 
 
 
257
  continue
258
 
259
  # ---- Keyboard ----
@@ -751,36 +756,33 @@ messages = [
751
  ]
752
 
753
  # Qwen3-VL action space
754
- description_prompt = "
755
- * `key`: Performs key down presses on the arguments passed in order, then performs key releases in reverse order.
756
- * `type`: Type a string of text on the keyboard.
757
- * `mouse_move`: Move the cursor to a specified (x, y) pixel coordinate on the screen.
758
- * `left_click`: Click the left mouse button at a specified (x, y) pixel coordinate on the screen.
759
- * `left_click_drag`: Click and drag the cursor to a specified (x, y) pixel coordinate on the screen.
760
- * `right_click`: Click the right mouse button at a specified (x, y) pixel coordinate on the screen.
761
- * `middle_click`: Click the middle mouse button at a specified (x, y) pixel coordinate on the screen.
762
- * `double_click`: Double-click the left mouse button at a specified (x, y) pixel coordinate on the screen.
763
- * `triple_click`: Triple-click the left mouse button at a specified (x, y) pixel coordinate on the screen (simulated as double-click since it's the closest action).
764
- * `scroll`: Performs a scroll of the mouse scroll wheel.
765
- * `hscroll`: Performs a horizontal scroll (mapped to regular scroll).
766
- * `wait`: Wait specified seconds for the change to happen.
767
- * `terminate`: Terminate the current task and report its completion status.
768
- * `answer`: Answer a question.
769
- ** Note: all coordinates should be normalized to the range 0-1000."
770
 
771
  tools_def = {
772
  "type": "function",
773
  "function": {
774
- "name_for_human": "computer_use",
775
- "name": "computer_use",
776
- "description": description_prompt,
777
  "parameters": {
778
- "type": "object",
779
- "required": ["action"],
780
  "properties": {
781
  "action": {
782
- "type": "string",
783
- "description": description_prompt,
784
  "enum": [
785
  "key",
786
  "type",
@@ -790,25 +792,50 @@ tools_def = {
790
  "right_click",
791
  "middle_click",
792
  "double_click",
 
793
  "scroll",
 
794
  "wait",
795
- "terminate"
796
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
797
  },
798
- "keys": {"type": "array", "description": "Required only by `action=key`."},
799
- "text": {"type": "string", "description": "Required only by `action=type`."},
800
- "coordinate": {"type": "array", "description": "The x,y coordinates for mouse actions."},
801
- "pixels": {"type": "number", "description": "The amount of scrolling."},
802
- "time": {"type": "number", "description": "The seconds to wait."},
803
  "status": {
 
804
  "type": "string",
805
- "description": "The status of the task.",
806
- "enum": ["success", "failure"]
807
- }
808
- }
 
809
  },
810
- "args_format": "Format the arguments as a JSON object."
811
- }
812
  }
813
 
814
  # AgentNet → Qwen3-VL Action Mapping
@@ -879,7 +906,7 @@ pyautogui.doubleClick(x=0.153, y=0.283)
879
  }
880
  ```
881
 
882
- ## (D) tripleClick → double_click (approx)
883
  ```python
884
  computer.tripleClick(x=0.226, y=0.311)
885
  ```
@@ -890,7 +917,7 @@ computer.tripleClick(x=0.226, y=0.311)
890
  "function": {
891
  "name": "computer_use",
892
  "arguments": {
893
- "action": "double_click",
894
  "coordinate": [226, 311]
895
  }
896
  }
 
214
  x, y = _extract_xy(call)
215
  tool_calls.append(
216
  _make_computer_use_tool_call(
217
+ {"action": "triple_click", "coordinate": _norm01_to_0_1000(x, y)}
218
  )
219
  )
220
  continue
 
251
  f"scroll/hscroll requires a pixels argument.\ncode=\n{code}"
252
  )
253
  pixels = int(_literal_eval(call.args[0]))
254
+ if fname == "pyautogui.scroll":
255
+ tool_calls.append(
256
+ _make_computer_use_tool_call({"action": "scroll", "pixels": pixels})
257
+ )
258
+ else:
259
+ tool_calls.append(
260
+ _make_computer_use_tool_call({"action": "hscroll", "pixels": pixels})
261
+ )
262
  continue
263
 
264
  # ---- Keyboard ----
 
756
  ]
757
 
758
  # Qwen3-VL action space
759
+ action_description_prompt = "\
760
+ * `key(keys=["key1", "key2"])`: Press the keys in order (key down), then release them in reverse order (key up).
761
+ * `type(text="string")`: Type the given text.
762
+ * `mouse_move(coordinate=[x, y])`: Move the cursor to (x, y).
763
+ * `left_click(coordinate=[x, y][, keys=["key"]])`: Left click at (x, y). If `keys` is provided, hold those keys while clicking.
764
+ * `left_click_drag(coordinate=[x, y][, keys=["key"]])`: Drag to (x, y) with the left mouse button. If `keys` is provided, hold those keys while dragging.
765
+ * `right_click(coordinate=[x, y][, keys=["key"]])`: Right click at (x, y). If `keys` is provided, hold those keys while clicking.
766
+ * `middle_click(coordinate=[x, y][, keys=["key"]])`: Middle click at (x, y). If `keys` is provided, hold those keys while clicking.
767
+ * `double_click(coordinate=[x, y][, keys=["key"]])`: Double left click at (x, y). If `keys` is provided, hold those keys while double-clicking.
768
+ * `triple_click(coordinate=[x, y][, keys=["key"]])`: Triple left click at (x, y). If `keys` is provided, hold those keys while double-clicking.
769
+ * `scroll(pixels=number[, keys=["key"]])`: Scroll vertically. `pixels > 0` scrolls up, `pixels < 0` scrolls down. If `keys` is provided, hold those keys while scrolling.
770
+ * `hscroll(pixels=number[, keys=["key"]])`: Scroll horizontally. `pixels > 0` scrolls right, `pixels < 0` scrolls left. If `keys` is provided, hold those keys while scrolling.
771
+ * `wait(time=seconds)`: Wait for the given number of seconds.
772
+ * `terminate(status="success"|"failure")`: End the task and report the status.
773
+ * `answer(text="answer")`: Return a final answer in text.\
774
+ "
775
 
776
  tools_def = {
777
  "type": "function",
778
  "function": {
779
+ "name_for_human": "desktop_use",
780
+ "name": "desktop_use",
781
+ "description": "...",
782
  "parameters": {
 
 
783
  "properties": {
784
  "action": {
785
+ "description": action_description_prompt,
 
786
  "enum": [
787
  "key",
788
  "type",
 
792
  "right_click",
793
  "middle_click",
794
  "double_click",
795
+ "triple_click",
796
  "scroll",
797
+ "hscroll",
798
  "wait",
799
+ "terminate",
800
+ "answer"
801
+ ],
802
+ "type": "string",
803
+ },
804
+ "keys": {
805
+ "description": (
806
+ "Keys to press/hold.\n"
807
+ "Required only for action: `key` (press in order, release in reverse).\n"
808
+ "Optional only for actions: `left_click`, `left_click_drag`, `right_click`, `middle_click`, `double_click`, `double_click`, `scroll`, `hscroll` (hold these keys while performing the action).\n"
809
+ ),
810
+ "type": "array",
811
+ },
812
+ "text": {
813
+ "description": "The text content to type or the answer to return. Required only for actions: `type`, `answer`.",
814
+ "type": "string",
815
+ },
816
+ "coordinate": {
817
+ "description": "The (x, y) pixel coordinate on the screen. Required only for actions: `mouse_move`, `left_click`, `left_click_drag`, `right_click`, `middle_click`, `double_click`, `triple_click`.",
818
+ "type": "array",
819
+ },
820
+ "pixels": {
821
+ "description": "The amount of scrolling to perform. Required only fors actions: `scroll`, `hscroll`.",
822
+ "type": "number"
823
+ },
824
+ "time": {
825
+ "description": "The duration to wait in seconds. Required only for action: `wait`.",
826
+ "type": "number"
827
  },
 
 
 
 
 
828
  "status": {
829
+ "description": "The completion status of the task. Required only for action: `terminate`.",
830
  "type": "string",
831
+ "enum": ["success", "failure"],
832
+ },
833
+ },
834
+ "required": ["action"],
835
+ "type": "object",
836
  },
837
+ "args_format": "Format the arguments as a JSON object.",
838
+ },
839
  }
840
 
841
  # AgentNet → Qwen3-VL Action Mapping
 
906
  }
907
  ```
908
 
909
+ ## (D) tripleClick → triple_click
910
  ```python
911
  computer.tripleClick(x=0.226, y=0.311)
912
  ```
 
917
  "function": {
918
  "name": "computer_use",
919
  "arguments": {
920
+ "action": "triple_click",
921
  "coordinate": [226, 311]
922
  }
923
  }