fix input text action with no text in GET steps API (#421)

This commit is contained in:
Kerem Yilmaz
2024-06-05 13:18:35 -07:00
committed by GitHub
parent cf3fb71012
commit 3f3fbbc63d
7 changed files with 53 additions and 70 deletions

View File

@@ -18,7 +18,6 @@ from skyvern.exceptions import (
InvalidWorkflowTaskURLState,
MissingBrowserStatePage,
StepTerminationError,
StepUnableToExecuteError,
TaskNotFound,
)
from skyvern.forge import app
@@ -37,7 +36,6 @@ from skyvern.forge.sdk.workflow.models.workflow import Workflow, WorkflowRun
from skyvern.webeye.actions.actions import (
Action,
ActionType,
ActionTypeUnion,
CompleteAction,
UserDefinedError,
WebAction,
@@ -53,7 +51,7 @@ LOG = structlog.get_logger()
class ActionLinkedNode:
def __init__(self, action: ActionTypeUnion) -> None:
def __init__(self, action: Action) -> None:
self.action = action
self.next: ActionLinkedNode | None = None
@@ -330,16 +328,9 @@ class ForgeAgent:
return step, detailed_output, next_step
# TODO (kerem): Let's add other exceptions that we know about here as custom exceptions as well
except StepUnableToExecuteError:
LOG.error(
"Step cannot be executed. Task execution stopped",
task_id=task.task_id,
step_id=step.step_id,
)
raise
except StepTerminationError as e:
LOG.error(
"Step cannot be executed. Task failed.",
"Step cannot be executed. Task terminated",
task_id=task.task_id,
step_id=step.step_id,
)
@@ -841,7 +832,7 @@ class ForgeAgent:
# Get action results from the last app.SETTINGS.PROMPT_ACTION_HISTORY_WINDOW steps
steps = await app.DATABASE.get_task_steps(task_id=task.task_id, organization_id=task.organization_id)
window_steps = steps[-1 * SettingsManager.get_settings().PROMPT_ACTION_HISTORY_WINDOW :]
actions_and_results: list[tuple[ActionTypeUnion, list[ActionResult]]] = []
actions_and_results: list[tuple[Action, list[ActionResult]]] = []
for window_step in window_steps:
if window_step.output and window_step.output.actions_and_results:
actions_and_results.extend(window_step.output.actions_and_results)

View File

@@ -1,6 +1,6 @@
from playwright.async_api import Page
from skyvern.exceptions import StepUnableToExecuteError
from skyvern.exceptions import StepTerminationError
from skyvern.forge import app
from skyvern.forge.async_operations import AsyncOperation
from skyvern.forge.sdk.models import Organization, Step, StepStatus
@@ -34,7 +34,7 @@ class AgentFunction:
can_execute = has_valid_task_status and has_valid_step_status and has_no_running_steps
if not can_execute:
raise StepUnableToExecuteError(step_id=step.step_id, reason=f"Cannot execute step. Reasons: {reasons}")
raise StepTerminationError(step_id=step.step_id, reason="Cannot execute step. Reasons: {reasons}")
def generate_async_operations(
self,

View File

@@ -309,7 +309,7 @@ class AgentDB:
if status is not None:
step.status = status
if output is not None:
step.output = output.model_dump()
step.output = output.model_dump(exclude_none=True)
if is_last is not None:
step.is_last = is_last
if retry_index is not None:

View File

@@ -195,7 +195,7 @@ async def execute_agent_task_step(
)
step, _, _ = await app.agent.execute_step(current_org, task, step)
return Response(
content=step.model_dump_json() if step else "",
content=step.model_dump_json(exclude_none=True) if step else "",
status_code=200,
media_type="application/json",
)
@@ -402,7 +402,7 @@ async def get_agent_task_steps(
"""
analytics.capture("skyvern-oss-agent-task-steps-get")
steps = await app.DATABASE.get_task_steps(task_id, organization_id=current_org.organization_id)
return ORJSONResponse([step.model_dump() for step in steps])
return ORJSONResponse([step.model_dump(exclude_none=True) for step in steps])
@base_router.get(