Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Build a task run response when the task has no navigation goal (#9016)
Aaron Pereze4be69cc305b
diff --git a/skyvern/services/run_service.py b/skyvern/services/run_service.pyindex 7bc6145ad..bdd50e10b 100644--- a/skyvern/services/run_service.py+++ b/skyvern/services/run_service.py@@ -138,7 +138,9 @@ async def get_run_response(downloaded_files=task_v1_response.downloaded_files,run_request=TaskRunRequest(engine=run_engine,- prompt=task_v1_response.request.navigation_goal,+ # An extraction-only task has no navigation goal, so resolve the prompt the same+ # way the agent resolves its first-turn goal instead of failing validation.+ prompt=task_v1_response.request.navigation_goal or task_v1_response.request.data_extraction_goal or "",url=task_v1_response.request.url,webhook_url=task_v1_response.request.webhook_callback_url,totp_identifier=task_v1_response.request.totp_identifier,diff --git a/tests/unit/test_run_service.py b/tests/unit/test_run_service.pyindex 96459ee62..00967bbb9 100644--- a/tests/unit/test_run_service.py+++ b/tests/unit/test_run_service.py@@ -1,5 +1,6 @@import asynciofrom datetime import UTC, datetime+from types import SimpleNamespacefrom typing import Anyfrom unittest.mock import AsyncMock@@ -10,6 +11,7 @@ from skyvern.constants import SKYVERN_UI_USER_AGENTfrom skyvern.exceptions import SkyvernHTTPException, WorkflowNotFoundForWorkflowRun, WorkflowRunNotFoundfrom skyvern.forge.sdk.routes import agent_protocolfrom skyvern.forge.sdk.schemas.organizations import Organization+from skyvern.forge.sdk.schemas.tasks import TaskBase, TaskResponse, TaskStatusfrom skyvern.forge.sdk.workflow.models.workflow import (Workflow,WorkflowDefinition,@@ -17,7 +19,7 @@ from skyvern.forge.sdk.workflow.models.workflow import (WorkflowRunStatus,WorkflowStatus,)-from skyvern.schemas.runs import RunResponse, RunStatus, RunType, WorkflowRunResponse+from skyvern.schemas.runs import RunResponse, RunStatus, RunType, TaskRunResponse, WorkflowRunResponsefrom skyvern.services import run_serviceOWNER_ORG = "o_owner"@@ -181,6 +183,52 @@ async def test_poll_after_build_finishes_but_before_cleanup_rebuilds(build: _Gatassert run_service._IN_FLIGHT == {}+ ("navigation_goal", "data_extraction_goal", "expected_prompt"),+ [+ ("book the cheapest flight", None, "book the cheapest flight"),+ (None, "extract the quote price", "extract the quote price"),+ (None, None, ""),+ ],+)+async def test_task_run_response_builds_when_the_task_has_no_navigation_goal(+ monkeypatch: pytest.MonkeyPatch,+ navigation_goal: str | None,+ data_extraction_goal: str | None,+ expected_prompt: str,+) -> None:+ """POST /api/v1/tasks accepts an extraction-only task, so every reader of that run must still build."""+ now = datetime.now(UTC)+ task_response = TaskResponse(+ request=TaskBase(+ url="https://example.test",+ navigation_goal=navigation_goal,+ data_extraction_goal=data_extraction_goal,+ ),+ task_id="tsk_1",+ status=TaskStatus.completed,+ created_at=now,+ modified_at=now,+ )+ monkeypatch.setattr(+ run_service.app,+ "DATABASE",+ SimpleNamespace(+ tasks=SimpleNamespace(+ get_run=AsyncMock(return_value=SimpleNamespace(run_id="tsk_1", task_run_type=RunType.task_v1))+ )+ ),+ )+ monkeypatch.setattr(run_service.task_v1_service, "get_task_v1_response", AsyncMock(return_value=task_response))++ run_response = await run_service.get_run_response("tsk_1", organization_id=OWNER_ORG)++ assert isinstance(run_response, TaskRunResponse)+ assert run_response.run_request is not None+ assert run_response.run_request.prompt == expected_prompt++WORKFLOW_ID = "wpid_1"WORKFLOW_RUN_ROUTES = ["with_workflow_id", "with_workflow", "legacy"]