Skip to content

Commit 2a8ac16

Browse files
committed
slim find_ui_elements and add sense to prompt
1 parent 853cfaa commit 2a8ac16

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

orbit/_tools/ui.py

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ def _cached_find_elements_hwnd(
126126
)
127127

128128

129+
def _slim_element(el: dict) -> dict:
130+
"""Strip an element dict to the fields the LLM needs."""
131+
slim = {"oculos_id": el.get("oculos_id")}
132+
if el.get("element_type"):
133+
slim["element_type"] = el["element_type"]
134+
for key in ("name", "title", "label"):
135+
val = el.get(key)
136+
if val:
137+
slim[key] = val
138+
for key in ("value", "text_content"):
139+
val = el.get(key)
140+
if val:
141+
slim[key] = val
142+
for key in ("checked", "toggle_state", "is_selected"):
143+
val = el.get(key)
144+
if val is not None:
145+
slim[key] = val
146+
if el.get("is_enabled") is False:
147+
slim["is_enabled"] = False
148+
return slim
149+
150+
151+
def _slim_elements(elements: list[dict]) -> list[dict]:
152+
return [_slim_element(el) for el in elements]
153+
154+
129155
def list_active_windows() -> Dict[str, Any]:
130156
"""
131157
Retrieves a list of all currently visible desktop windows.
@@ -318,7 +344,7 @@ def find_ui_elements(
318344
eid = el.get("oculos_id")
319345
if eid:
320346
_element_meta[eid] = {"pid": pid, "query": query, "element_type": element_type}
321-
return {"status": "success", "elements": elements}
347+
return {"status": "success", "elements": _slim_elements(elements)}
322348
except Exception as e:
323349
return {"status": "error", "message": f"Failed to find elements: {str(e)}"}
324350

@@ -391,7 +417,7 @@ def find_ui_elements_hwnd(
391417
"message": "No elements found matching the criteria.",
392418
"elements": [],
393419
}
394-
return {"status": "success", "elements": elements}
420+
return {"status": "success", "elements": _slim_elements(elements)}
395421
except Exception as e:
396422
return {
397423
"status": "error",

orbit/prompts.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
SYSTEM_PROMPT = """
22
You are an expert desktop automation agent. Complete tasks with the minimum number of tool calls.
33
4+
── SENSE ────────────────────────────────────────────────────────────
5+
0. Before acting, understand the context. Read what the page is asking,
6+
use information from the task description and any referenced files,
7+
and provide thoughtful, relevant responses. Never fill a field with
8+
placeholder or meaningless values — if you don't have the information,
9+
call request_human instead of guessing.
10+
411
── WINDOW & PID MANAGEMENT ───────────────────────────────────────────
512
1. Call list_active_windows once to get PIDs. Cache every PID immediately.
613
Never repeat unless a new window has opened.

0 commit comments

Comments
 (0)