Skip to content

Automate browser based workflows with AI

Misc loop block changes (#1494)

Shuchang Zheng74c8dd45f5b6
diff --git a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
index 915919ffc..a45ca4d7c 100644
--- a/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
+++ b/skyvern-frontend/src/routes/workflows/editor/workflowEditorUtils.ts
@@ -1574,7 +1574,7 @@ function convertBlocksToBlockYAML(
const blockYaml: ForLoopBlockYAML = {
...base,
block_type: "for_loop",
- loop_over_parameter_key: block.loop_over.key,
+ loop_over_parameter_key: block.loop_over?.key ?? "",
loop_blocks: convertBlocksToBlockYAML(block.loop_blocks),
loop_variable_reference: block.loop_variable_reference,
};
diff --git a/skyvern/forge/agent.py b/skyvern/forge/agent.py
index e1789fcd8..f70dbcf2e 100644
--- a/skyvern/forge/agent.py
+++ b/skyvern/forge/agent.py
@@ -572,7 +572,7 @@ class ForgeAgent:
failure_reason = "unexpected exception"
if isinstance(e, SkyvernException):
- failure_reason = f"unexpected SkyvernException({e.__class__.__name__})"
+ failure_reason = f"unexpected SkyvernException({e.__class__.__name__}): {str(e)}"
is_task_marked_as_failed = await self.fail_task(task, step, failure_reason)
if is_task_marked_as_failed:
diff --git a/skyvern/forge/sdk/workflow/models/block.py b/skyvern/forge/sdk/workflow/models/block.py
index c7405170d..38d694e59 100644
--- a/skyvern/forge/sdk/workflow/models/block.py
+++ b/skyvern/forge/sdk/workflow/models/block.py
@@ -263,6 +263,10 @@ class Block(BaseModel, abc.ABC):
artifact_type=ArtifactType.SCREENSHOT_LLM,
data=screenshot,
)
+
+ LOG.info(
+ "Executing block", workflow_run_id=workflow_run_id, block_label=self.label, block_type=self.block_type
+ )
return await self.execute(workflow_run_id, workflow_run_block_id, organization_id=organization_id, **kwargs)
except Exception as e:
LOG.exception(
@@ -278,7 +282,7 @@ class Block(BaseModel, abc.ABC):
failure_reason = "unexpected exception"
if isinstance(e, SkyvernException):
- failure_reason = f"unexpected SkyvernException({e.__class__.__name__})"
+ failure_reason = f"unexpected SkyvernException({e.__class__.__name__}): {str(e)}"
return await self.build_block_result(
success=False,
@@ -843,13 +847,17 @@ class ForLoopBlock(Block):
parent_workflow_run_block_id=workflow_run_block_id,
organization_id=organization_id,
)
+
+ output_value = (
+ workflow_run_context.get_value(block_output.output_parameter.key)
+ if workflow_run_context.has_value(block_output.output_parameter.key)
+ else None
+ )
each_loop_output_values.append(
{
"loop_value": loop_over_value,
"output_parameter": block_output.output_parameter,
- "output_value": workflow_run_context.get_value(block_output.output_parameter.key)
- if workflow_run_context.has_value(block_output.output_parameter.key)
- else None,
+ "output_value": output_value,
}
)
try:
@@ -886,12 +894,13 @@ class ForLoopBlock(Block):
if not block_output.success and not loop_block.continue_on_failure:
LOG.info(
- f"ForLoopBlock: Encountered an failure processing block {block_idx} during loop {loop_idx}, terminating early",
+ f"ForLoopBlock: Encountered a failure processing block {block_idx} during loop {loop_idx}, terminating early",
block_outputs=block_outputs,
loop_idx=loop_idx,
block_idx=block_idx,
loop_over_value=loop_over_value,
loop_block_continue_on_failure=loop_block.continue_on_failure,
+ failure_reason=block_output.failure_reason,
)
outputs_with_loop_values.append(each_loop_output_values)
return LoopBlockExecutedResult(
diff --git a/skyvern/forge/sdk/workflow/service.py b/skyvern/forge/sdk/workflow/service.py
index 749111253..eaa5cbc82 100644
--- a/skyvern/forge/sdk/workflow/service.py
+++ b/skyvern/forge/sdk/workflow/service.py
@@ -351,7 +351,7 @@ class WorkflowService:
exception_message = "unexpected exception"
if isinstance(e, SkyvernException):
- exception_message = f"unexpected SkyvernException({e.__class__.__name__})"
+ exception_message = f"unexpected SkyvernException({e.__class__.__name__}): {str(e)}"
failure_reason = f"Block with type {block.block_type} at index {block_idx}/{blocks_cnt -1} failed. failure reason: {exception_message}"
await self.mark_workflow_run_as_failed(
@@ -1371,7 +1371,7 @@ class WorkflowService:
loop_over_parameter = parameters[trimmed_key]
if loop_over_parameter is None and not block_yaml.loop_variable_reference:
- raise Exception("empty loop value parameter")
+ raise Exception("Loop value parameter is required for for loop block")
return ForLoopBlock(
label=block_yaml.label,