diff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.py index ce5402d7..10420c68 100644 --- a/skyvern/forge/agent.py +++ b/skyvern/forge/agent.py @@ -1229,7 +1229,7 @@ class ForgeAgent: } results = await ActionHandler.handle_action(scraped_page, task, step, current_page, action) - await app.AGENT_FUNCTION.post_action_execution() + await app.AGENT_FUNCTION.post_action_execution(action) detailed_agent_step_output.actions_and_results[action_idx] = ( action, results, @@ -1404,7 +1404,6 @@ class ForgeAgent: complete_results = await ActionHandler.handle_action( scraped_page, task, step, working_page, complete_action ) - await app.AGENT_FUNCTION.post_action_execution() detailed_agent_step_output.actions_and_results.append((complete_action, complete_results)) await self.record_artifacts_after_action(task, step, browser_state, engine) @@ -1424,7 +1423,7 @@ class ForgeAgent: extract_results = await ActionHandler.handle_action( scraped_page, task, step, working_page, extract_action ) - await app.AGENT_FUNCTION.post_action_execution() + await app.AGENT_FUNCTION.post_action_execution(extract_action) detailed_agent_step_output.actions_and_results.append((extract_action, extract_results)) # If no action errors return the agent state and output diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.py index 9a6f62c4..ff4a7ca9 100644 --- a/skyvern/forge/agent_functions.py +++ b/skyvern/forge/agent_functions.py @@ -21,6 +21,8 @@ from skyvern.forge.sdk.schemas.tasks import Task, TaskStatus from skyvern.forge.sdk.trace import TraceManager from skyvern.forge.sdk.workflow.models.block import BlockTypeVar from skyvern.services import workflow_script_service +from skyvern.webeye.actions.action_types import POST_ACTION_EXECUTION_ACTION_TYPES +from skyvern.webeye.actions.actions import Action from skyvern.webeye.browser_factory import BrowserState from skyvern.webeye.scraper.scraper import ELEMENT_NODE_ATTRIBUTES, CleanupElementTreeFunc, json_to_html from skyvern.webeye.utils.dom import SkyvernElement @@ -617,10 +619,12 @@ class AgentFunction: if not settings.ENABLE_CODE_BLOCK: raise DisabledBlockExecutionError("CodeBlock is disabled") - async def _post_action_execution(self) -> None: + async def _post_action_execution(self, action: Action) -> None: """ If this is a workflow running environment, generate the """ + if action.action_type not in POST_ACTION_EXECUTION_ACTION_TYPES: + return context = skyvern_context.current() if ( not context @@ -652,5 +656,5 @@ class AgentFunction: workflow=workflow, ) - async def post_action_execution(self) -> None: - asyncio.create_task(self._post_action_execution()) + async def post_action_execution(self, action: Action) -> None: + asyncio.create_task(self._post_action_execution(action)) diff --git a/skyvern/webeye/actions/action_types.py b/skyvern/webeye/actions/action_types.py index cd894ec8..9666b35c 100644 --- a/skyvern/webeye/actions/action_types.py +++ b/skyvern/webeye/actions/action_types.py @@ -37,3 +37,15 @@ class ActionType(StrEnum): ActionType.SELECT_OPTION, ActionType.CHECKBOX, ] + + +POST_ACTION_EXECUTION_ACTION_TYPES = [ + ActionType.CLICK, + ActionType.INPUT_TEXT, + ActionType.UPLOAD_FILE, + ActionType.DOWNLOAD_FILE, + ActionType.SELECT_OPTION, + ActionType.WAIT, + ActionType.SOLVE_CAPTCHA, + ActionType.EXTRACT, +]