Skip to content

Commit

Permalink
introduce a way to reload the page (#1597)
Browse files Browse the repository at this point in the history
  • Loading branch information
wintonzheng authored Jan 20, 2025
1 parent 0c02bde commit 39bb455
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
33 changes: 32 additions & 1 deletion skyvern/forge/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,20 @@
from skyvern.forge.sdk.workflow.models.workflow import Workflow, WorkflowRun, WorkflowRunStatus
from skyvern.webeye.actions.actions import (
Action,
ActionStatus,
ActionType,
CompleteAction,
CompleteVerifyResult,
DecisiveAction,
ReloadPageAction,
UserDefinedError,
WebAction,
)
from skyvern.webeye.actions.caching import retrieve_action_plan
from skyvern.webeye.actions.handler import ActionHandler, poll_verification_code
from skyvern.webeye.actions.models import AgentStepOutput, DetailedAgentStepOutput
from skyvern.webeye.actions.parse_actions import parse_actions
from skyvern.webeye.actions.responses import ActionResult
from skyvern.webeye.actions.responses import ActionResult, ActionSuccess
from skyvern.webeye.browser_factory import BrowserState
from skyvern.webeye.scraper.scraper import ElementTreeFormat, ScrapedPage, scrape_website
from skyvern.webeye.utils.page import SkyvernFrame
Expand Down Expand Up @@ -800,6 +802,35 @@ async def agent_step(

element_id_to_last_action: dict[str, int] = dict()
for action_idx, action_node in enumerate(action_linked_list):
context = skyvern_context.ensure_context()
if context.refresh_working_page:
LOG.warning(
"Detected the signal to reload the page, going to reload and skip the rest of the actions",
task_id=task.task_id,
step_id=step.step_id,
step_order=step.order,
)
await browser_state.reload_page()
context.refresh_working_page = False
action_result = ActionSuccess()
action_result.step_order = step.order
action_result.step_retry_number = step.retry_index
detailed_agent_step_output.actions_and_results[action_idx] = (
ReloadPageAction(
reasoning="Something wrong with the current page, reload to continue",
status=ActionStatus.completed,
organization_id=task.organization_id,
workflow_run_id=task.workflow_run_id,
task_id=task.task_id,
step_id=step.step_id,
step_order=step.order,
action_order=action_idx,
),
[action_result],
)
await self.record_artifacts_after_action(task, step, browser_state)
break

action = action_node.action
if isinstance(action, WebAction):
previous_action_idx = element_id_to_last_action.get(action.element_id)
Expand Down
1 change: 1 addition & 0 deletions skyvern/forge/sdk/core/skyvern_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class SkyvernContext:
totp_codes: dict[str, str | None] = field(default_factory=dict)
log: list[dict] = field(default_factory=list)
hashed_href_map: dict[str, str] = field(default_factory=dict)
refresh_working_page: bool = False

def __repr__(self) -> str:
return f"SkyvernContext(request_id={self.request_id}, organization_id={self.organization_id}, task_id={self.task_id}, workflow_id={self.workflow_id}, workflow_run_id={self.workflow_run_id}, max_steps_override={self.max_steps_override})"
Expand Down
6 changes: 6 additions & 0 deletions skyvern/webeye/actions/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class ActionType(StrEnum):
SOLVE_CAPTCHA = "solve_captcha"
TERMINATE = "terminate"
COMPLETE = "complete"
RELOAD_PAGE = "reload_page"

def is_web_action(self) -> bool:
return self in [
Expand Down Expand Up @@ -161,6 +162,11 @@ class DecisiveAction(Action):
errors: list[UserDefinedError] = []


# TODO: consider to implement this as a WebAction in the future
class ReloadPageAction(Action):
action_type: ActionType = ActionType.RELOAD_PAGE


class ClickAction(WebAction):
action_type: ActionType = ActionType.CLICK
file_url: str | None = None
Expand Down

0 comments on commit 39bb455

Please sign in to comment.