Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
add failure_reason to the TaskRunRepsonse for task v2 (#2052)
Shuchang Zheng993e3b637d4a
diff --git a/skyvern/agent/agent.py b/skyvern/agent/agent.pyindex d895a1500..a753dabc3 100644--- a/skyvern/agent/agent.py+++ b/skyvern/agent/agent.py@@ -133,7 +133,6 @@ class SkyvernAgent:status=TaskV2Status.queued,organization_id=organization.organization_id,)-assert task_v2.workflow_run_idawait app.DATABASE.update_workflow_run(workflow_run_id=task_v2.workflow_run_id,@@ -295,28 +294,23 @@ class SkyvernAgent:proxy_location=proxy_location,)- if wait_for_completion:- created_task = await app.agent.create_task(task_request, organization.organization_id)- url_hash = generate_url_hash(task_request.url)- await app.DATABASE.create_task_run(- task_run_type=RunType.task_v1,- organization_id=organization.organization_id,- run_id=created_task.task_id,- title=task_request.title,- url=task_request.url,- url_hash=url_hash,- )- try:- await self._run_task(organization, created_task)- run_obj = await self.get_run(run_id=created_task.task_id)- return cast(TaskRunResponse, run_obj)- except Exception:- # TODO: better error handling and logging- run_obj = await self.get_run(run_id=created_task.task_id)- return cast(TaskRunResponse, run_obj)- else:- create_task_resp = await self.create_task_v1(task_request)- run_obj = await self.get_run(run_id=create_task_resp.task_id)+ created_task = await app.agent.create_task(task_request, organization.organization_id)+ url_hash = generate_url_hash(task_request.url)+ await app.DATABASE.create_task_run(+ task_run_type=RunType.task_v1,+ organization_id=organization.organization_id,+ run_id=created_task.task_id,+ title=task_request.title,+ url=task_request.url,+ url_hash=url_hash,+ )+ try:+ await self._run_task(organization, created_task)+ run_obj = await self.get_run(run_id=created_task.task_id)+ return cast(TaskRunResponse, run_obj)+ except Exception:+ # TODO: better error handling and logging+ run_obj = await self.get_run(run_id=created_task.task_id)return cast(TaskRunResponse, run_obj)elif engine == RunEngine.skyvern_v2:# initialize task v2@@ -336,14 +330,9 @@ class SkyvernAgent:create_task_run=True,)- if wait_for_completion:- await self._run_task_v2(organization, task_v2)- run_obj = await self.get_run(run_id=task_v2.observer_cruise_id)- return cast(TaskRunResponse, run_obj)- else:- asyncio.create_task(self._run_task_v2(organization, task_v2))- run_obj = await self.get_run(run_id=task_v2.observer_cruise_id)- return cast(TaskRunResponse, run_obj)+ await self._run_task_v2(organization, task_v2)+ run_obj = await self.get_run(run_id=task_v2.observer_cruise_id)+ return cast(TaskRunResponse, run_obj)else:raise ValueError("Local mode is not supported for this method")diff --git a/skyvern/services/run_service.py b/skyvern/services/run_service.pyindex 9e87fee90..e8061fa5e 100644--- a/skyvern/services/run_service.py+++ b/skyvern/services/run_service.py@@ -37,13 +37,15 @@ async def get_run_response(run_id: str, organization_id: str | None = None) -> Rtask_v2 = await app.DATABASE.get_task_v2(run.run_id, organization_id=organization_id)if not task_v2:return None+ workflow_run = None+ if task_v2.workflow_run_id:+ workflow_run = await app.DATABASE.get_workflow_run(task_v2.workflow_run_id, organization_id=organization_id)return TaskRunResponse(run_id=run.run_id,run_type=run.task_run_type,status=task_v2.status,output=task_v2.output,- # TODO: add failure reason- # failure_reason=task_v2.failure_reason,+ failure_reason=workflow_run.failure_reason if workflow_run else None,created_at=task_v2.created_at,modified_at=task_v2.modified_at,run_request=TaskRunRequest(