Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/narada-core/src/narada_core/actions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,15 +187,19 @@ class AgenticSelectorRequest(BaseModel):
action: AgenticSelectorAction
selectors: AgenticSelectors
fallback_operator_query: str
pre_cond: str | None = None

@override
def model_dump(self) -> dict[str, Any]:
return {
result = {
"name": self.name,
"action": _dump_agentic_selector_action(self.action),
"selectors": _dump_agentic_selectors(self.selectors),
"fallback_operator_query": self.fallback_operator_query,
}
if self.pre_cond is not None:
result["pre_cond"] = self.pre_cond
return result


class AgenticSelectorResponse(BaseModel):
Expand Down
5 changes: 5 additions & 0 deletions packages/narada-pyodide/src/narada/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -795,12 +795,16 @@ async def agentic_selector(
action: AgenticSelectorAction,
selectors: AgenticSelectors,
fallback_operator_query: str,
pre_cond: str | None = None,
# Larger default timeout because Operator can take a bit to run.
timeout: int | None = 300,
) -> AgenticSelectorResponse:
"""Performs an action on an element specified by the given selectors, falling back to using
the Operator agent if the selectors fail to match a unique element.

If ``pre_cond`` is provided, it is checked only after selector failure and before the
Operator fallback runs. A failed precondition raises ``NaradaError`` and prevents fallback.

Returns AgenticSelectorResponse with the value for 'get_text' and 'get_property' actions,
otherwise returns None.
"""
Expand All @@ -815,6 +819,7 @@ async def agentic_selector(
action=action,
selectors=selectors,
fallback_operator_query=fallback_operator_query,
pre_cond=pre_cond,
),
response_model,
timeout=timeout,
Expand Down
5 changes: 5 additions & 0 deletions packages/narada/src/narada/window.py
Original file line number Diff line number Diff line change
Expand Up @@ -730,11 +730,15 @@ async def agentic_selector(
action: AgenticSelectorAction,
selectors: AgenticSelectors,
fallback_operator_query: str,
pre_cond: str | None = None,
# Larger default timeout because Operator can take a bit to run.
timeout: int | None = 300,
) -> AgenticSelectorResponse:
"""Performs an action on an element specified by the given selectors, falling back to using
the Operator agent if the selectors fail to match a unique element.

If ``pre_cond`` is provided, it is checked only after selector failure and before the
Operator fallback runs. A failed precondition raises ``NaradaError`` and prevents fallback.
"""
response_model = (
AgenticSelectorResponse
Expand All @@ -746,6 +750,7 @@ async def agentic_selector(
action=action,
selectors=selectors,
fallback_operator_query=fallback_operator_query,
pre_cond=pre_cond,
),
response_model=response_model,
timeout=timeout,
Expand Down
Loading