Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-10580: expose the workflows API as /agents + accept agent_id (backwards-compatible) (#6383)
Suchintanac62f74b853b
diff --git a/skyvern/forge/api_app.py b/skyvern/forge/api_app.pyindex c3d44f8dd..59e1d99f1 100644--- a/skyvern/forge/api_app.py+++ b/skyvern/forge/api_app.py@@ -20,6 +20,7 @@ from fastapi import FastAPI, Response, statusfrom fastapi.middleware.cors import CORSMiddlewarefrom fastapi.openapi.utils import get_openapifrom fastapi.responses import JSONResponse+from fastapi.routing import APIRoutefrom starlette.requests import HTTPConnection, Requestfrom starlette_context.middleware import RawContextMiddlewarefrom starlette_context.plugins.base import Plugin@@ -99,6 +100,71 @@ def custom_openapi(app: FastAPI) -> dict:return app.openapi_schema+def register_agent_route_aliases(fastapi_app: FastAPI) -> None:+ """Expose every public ``/workflows`` route under ``/agents`` and hide the original from the schema.++ An *agent* is the product-facing name for a workflow — same entity, same ``wpid_`` identifier. To+ rebrand the public API surface to "agents" without breaking anyone, each in-schema ``/v1/...workflows...``+ route gets an identical ``/agents`` sibling (same handler, params, response models, and ``x-fern-*``+ metadata, so generated SDK method names are unchanged), and the original ``/workflows`` route is dropped+ from the OpenAPI schema via ``include_in_schema=False``. The original route keeps responding, so+ already-deployed SDKs, integrations, and the frontend continue to work unchanged.++ Idempotent: routes already authored directly as ``/agents`` (with their ``/workflows`` form already+ hidden) are skipped, as is any twin that already exists.+ """++ # Match the literal "workflows" path *segment* so substrings like "workflow_run_id" are left alone+ # and future compound paths that merely contain "workflows" aren't accidentally rewritten.+ def _to_agents_path(path: str) -> str:+ return "/".join("agents" if segment == "workflows" else segment for segment in path.split("/"))++ existing_routes = {+ (existing.path, frozenset(existing.methods or ()))+ for existing in fastapi_app.router.routes+ if isinstance(existing, APIRoute)+ }+ for route in list(fastapi_app.router.routes):+ if not isinstance(route, APIRoute) or not route.include_in_schema:+ continue+ agent_path = _to_agents_path(route.path)+ if agent_path == route.path:+ continue+ if (agent_path, frozenset(route.methods or ())) in existing_routes:+ continue+ fastapi_app.router.add_api_route(+ agent_path,+ route.endpoint,+ methods=list(route.methods or []),+ response_model=route.response_model,+ status_code=route.status_code,+ tags=route.tags,+ summary=route.summary,+ description=route.description,+ response_description=route.response_description,+ responses=route.responses,+ deprecated=route.deprecated,+ # Pin the twin to the original route's operationId (route.unique_id already resolves to the+ # explicit operation_id or FastAPI's generated one). Otherwise FastAPI would derive a fresh+ # operationId from the /agents path, renaming the operation for OpenAPI-generated clients.+ operation_id=route.operation_id or route.unique_id,+ dependencies=route.dependencies,+ response_class=route.response_class,+ # Intentionally NOT copying `name`: a duplicate route name would make url_path_for(name)+ # resolve to the hidden /workflows route. Let FastAPI auto-generate a distinct name.+ callbacks=route.callbacks,+ openapi_extra=route.openapi_extra,+ response_model_include=route.response_model_include,+ response_model_exclude=route.response_model_exclude,+ response_model_by_alias=route.response_model_by_alias,+ response_model_exclude_unset=route.response_model_exclude_unset,+ response_model_exclude_defaults=route.response_model_exclude_defaults,+ response_model_exclude_none=route.response_model_exclude_none,+ include_in_schema=True,+ )+ route.include_in_schema = False++async def _bootstrap_sqlite() -> None:"""Auto-bootstrap SQLite on first server start.@@ -292,6 +358,9 @@ def create_api_app() -> FastAPI:fastapi_app.include_router(internal_auth.router, prefix="/api/v1")fastapi_app.include_router(internal_auth.router, prefix="/api/v2")+ # Mirror the public /workflows surface to /agents (and hide the /workflows form from the schema).+ register_agent_route_aliases(fastapi_app)+fastapi_app.openapi = lambda: custom_openapi(fastapi_app)fastapi_app.add_middleware(diff --git a/skyvern/forge/sdk/routes/agent_protocol.py b/skyvern/forge/sdk/routes/agent_protocol.pyindex 0f3cbe52d..96019eed0 100644--- a/skyvern/forge/sdk/routes/agent_protocol.py+++ b/skyvern/forge/sdk/routes/agent_protocol.py@@ -180,8 +180,9 @@ class AISuggestionType(str, Enum):################# /v1 Endpoints #################@base_router.post("/run/tasks",- tags=["Agent"],+ tags=["Agents"],openapi_extra={+ "x-hidden": True,"x-fern-sdk-method-name": "run_task","x-fern-examples": [{@@ -435,8 +436,8 @@ def _workflow_run_request_to_legacy_request(workflow_run_request: WorkflowRunReq@base_router.post(- "/run/workflows",- tags=["Workflow Runs"],+ "/run/agents",+ tags=["Agents"],openapi_extra={"x-fern-sdk-method-name": "run_workflow","x-fern-examples": [@@ -448,13 +449,17 @@ def _workflow_run_request_to_legacy_request(workflow_run_request: WorkflowRunReq}],},- description="Run a workflow",- summary="Run a workflow",+ description="Run an agent",+ summary="Run an agent",responses={- 200: {"description": "Successfully run workflow"},- 400: {"description": "Invalid workflow run request"},+ 200: {"description": "Successfully ran agent"},+ 400: {"description": "Invalid agent run request"},},)+@base_router.post("/run/agents/", include_in_schema=False)+# Backwards-compatible aliases: an agent is a workflow. These keep responding but are hidden from the+# public schema in favor of /run/agents.+@base_router.post("/run/workflows", include_in_schema=False)@base_router.post("/run/workflows/", include_in_schema=False)async def run_workflow(request: Request,@@ -532,10 +537,10 @@ async def run_workflow(@base_router.get("/runs/{run_id}",- tags=["Agent", "Workflow Runs", "Workflows"],+ tags=["Agents"],response_model=RunResponse,description="Get run information (task run, workflow run)",- summary="Get a run by id",+ summary="Get run info by id",openapi_extra={"x-fern-sdk-method-name": "get_run","x-fern-examples": [@@ -574,7 +579,7 @@ async def get_run(@base_router.post("/runs/{run_id}/cancel",- tags=["Agent", "Workflow Runs"],+ tags=["Agents"],openapi_extra={"x-fern-sdk-method-name": "cancel_run","x-fern-examples": [@@ -602,7 +607,7 @@ async def cancel_run(@base_router.post("/runs/cancel",- tags=["Agent", "Workflow Runs"],+ tags=["Agents"],openapi_extra={"x-fern-sdk-method-name": "bulk_cancel_runs","x-fern-examples": [@@ -686,9 +691,9 @@ async def create_workflow_legacy(@base_router.post(- "/workflows",+ "/agents",response_model=Workflow,- tags=["Workflows"],+ tags=["Agents"],openapi_extra={"x-fern-sdk-method-name": "create_workflow","x-fern-examples": [@@ -701,18 +706,17 @@ async def create_workflow_legacy(}],},- description="Create a new workflow",- summary="Create a new workflow",+ description="Create a new agent",+ summary="Create a new agent",responses={- 200: {"description": "Successfully created workflow"},- 422: {"description": "Invalid workflow definition"},+ 200: {"description": "Successfully created agent"},+ 422: {"description": "Invalid agent definition"},},)-@base_router.post(- "/workflows/",- response_model=Workflow,- include_in_schema=False,-)+@base_router.post("/agents/", response_model=Workflow, include_in_schema=False)+# Backwards-compatible aliases: an agent is a workflow. Hidden from schema in favor of /agents.+@base_router.post("/workflows", response_model=Workflow, include_in_schema=False)+@base_router.post("/workflows/", response_model=Workflow, include_in_schema=False)async def create_workflow(data: WorkflowRequest,folder_id: str | None = Query(None, description="Optional folder ID to assign the workflow to"),@@ -1094,9 +1098,9 @@ async def update_workflow_legacy(@base_router.post(- "/workflows/{workflow_id}",+ "/agents/{workflow_id}",response_model=Workflow,- tags=["Workflows"],+ tags=["Agents"],openapi_extra={"x-fern-sdk-method-name": "update_workflow","x-fern-examples": [@@ -1109,15 +1113,15 @@ async def update_workflow_legacy(}],},- description="Update a workflow",- summary="Update a workflow",+ description="Update an agent",+ summary="Update an agent",responses={- 200: {"description": "Successfully updated workflow"},- 422: {"description": "Invalid workflow definition"},+ 200: {"description": "Successfully updated agent"},+ 422: {"description": "Invalid agent definition"},},)@base_router.post(- "/workflows/{workflow_id}/",+ "/agents/{workflow_id}/",openapi_extra={"requestBody": {"content": {"application/x-yaml": {"schema": WorkflowCreateYAMLRequest.model_json_schema()}},@@ -1127,10 +1131,13 @@ async def update_workflow_legacy(response_model=Workflow,include_in_schema=False,)+# Backwards-compatible aliases: an agent is a workflow. Hidden from schema in favor of /agents/{...}.+@base_router.post("/workflows/{workflow_id}", response_model=Workflow, include_in_schema=False)+@base_router.post("/workflows/{workflow_id}/", response_model=Workflow, include_in_schema=False)async def update_workflow(data: WorkflowRequest,workflow_id: str = Path(- ..., description="The ID of the workflow to update. Workflow ID starts with `wpid_`.", examples=["wpid_123"]+ ..., description="The ID of the agent to update. Starts with `wpid_`.", examples=["wpid_123"]),current_org: Organization = Depends(org_auth_service.get_current_org),) -> Workflow:@@ -1179,8 +1186,8 @@ async def update_workflow()@legacy_base_router.delete("/workflows/{workflow_id}/", include_in_schema=False)@base_router.post(- "/workflows/{workflow_id}/delete",- tags=["Workflows"],+ "/agents/{workflow_id}/delete",+ tags=["Agents"],openapi_extra={"x-fern-sdk-method-name": "delete_workflow","x-fern-examples": [@@ -1192,14 +1199,17 @@ async def update_workflow(}],},- description="Delete a workflow",- summary="Delete a workflow",- responses={200: {"description": "Successfully deleted workflow"}},+ description="Delete an agent",+ summary="Delete an agent",+ responses={200: {"description": "Successfully deleted agent"}},)+@base_router.post("/agents/{workflow_id}/delete/", include_in_schema=False)+# Backwards-compatible aliases: an agent is a workflow. Hidden from schema in favor of /agents/{...}/delete.+@base_router.post("/workflows/{workflow_id}/delete", include_in_schema=False)@base_router.post("/workflows/{workflow_id}/delete/", include_in_schema=False)async def delete_workflow(workflow_id: str = Path(- ..., description="The ID of the workflow to delete. Workflow ID starts with `wpid_`.", examples=["wpid_123"]+ ..., description="The ID of the agent to delete. Starts with `wpid_`.", examples=["wpid_123"]),current_org: Organization = Depends(org_auth_service.get_current_org),) -> None:@@ -1213,7 +1223,7 @@ async def delete_workflow(@base_router.post("/folders",response_model=Folder,- tags=["Workflow Folders"],+ tags=["Agent Folders"],openapi_extra={"x-fern-sdk-method-name": "create_folder",},@@ -1255,7 +1265,7 @@ async def create_folder(@base_router.get("/folders/{folder_id}",response_model=Folder,- tags=["Workflow Folders"],+ tags=["Agent Folders"],openapi_extra={"x-fern-sdk-method-name": "get_folder",},@@ -1299,7 +1309,7 @@ async def get_folder(@base_router.get("/folders",response_model=list[Folder],- tags=["Workflow Folders"],+ tags=["Agent Folders"],openapi_extra={"x-fern-sdk-method-name": "get_folders",},@@ -1356,7 +1366,7 @@ async def get_folders(@base_router.put("/folders/{folder_id}",response_model=Folder,- tags=["Workflow Folders"],+ tags=["Agent Folders"],openapi_extra={"x-fern-sdk-method-name": "update_folder",},@@ -1402,7 +1412,7 @@ async def update_folder(@legacy_base_router.delete("/folders/{folder_id}/", include_in_schema=False)@base_router.delete("/folders/{folder_id}",- tags=["Workflow Folders"],+ tags=["Agent Folders"],openapi_extra={"x-fern-sdk-method-name": "delete_folder",},@@ -1438,12 +1448,12 @@ async def delete_folder(@base_router.put("/workflows/{workflow_permanent_id}/folder",response_model=Workflow,- tags=["Workflow Folders"],+ tags=["Agent Folders"],openapi_extra={"x-fern-sdk-method-name": "update_workflow_folder",},description="Update a workflow's folder assignment for the latest version",- summary="Update workflow folder",+ summary="Update agent folder",responses={200: {"description": "Successfully updated workflow folder"},404: {"description": "Workflow not found"},@@ -1548,11 +1558,11 @@ async def _apply_tag_changes_with_retry(@base_router.post("/workflows/{workflow_permanent_id}/tags",response_model=TagsResponse,- tags=["Workflow Tags"],+ tags=["Agent Tags"],openapi_extra={"x-fern-sdk-method-name": "apply_workflow_tags"},description="Atomically apply tag changes to a workflow. Sets and deletes happen in one transaction; ""same-key collisions resolve set-wins.",- summary="Apply workflow tags",+ summary="Apply agent tags",responses={200: {"description": "Successfully applied tag changes"},404: {"description": "Workflow not found"},@@ -1598,10 +1608,10 @@ async def apply_workflow_tags(@base_router.delete("/workflows/{workflow_permanent_id}/tags/{key}",response_model=TagsResponse,- tags=["Workflow Tags"],+ tags=["Agent Tags"],openapi_extra={"x-fern-sdk-method-name": "delete_workflow_tag"},description="Soft-delete a single tag from a workflow. Writes a DELETE event row.",- summary="Delete workflow tag",+ summary="Delete agent tag",responses={200: {"description": "Successfully deleted tag (or no-op if absent)"},404: {"description": "Workflow not found"},@@ -1647,10 +1657,10 @@ async def delete_workflow_tag(@base_router.get("/workflows/{workflow_permanent_id}/tags",response_model=TagsResponse,- tags=["Workflow Tags"],+ tags=["Agent Tags"],openapi_extra={"x-fern-sdk-method-name": "get_workflow_tags"},description="Get the current tag state for a workflow.",- summary="Get workflow tags",+ summary="Get agent tags",responses={200: {"description": "Successfully retrieved tags"},404: {"description": "Workflow not found"},@@ -1694,10 +1704,10 @@ async def _build_tags_response(workflow_permanent_id: str, organization_id: str)@base_router.get("/workflows/{workflow_permanent_id}/tags/history",response_model=TagHistoryResponse,- tags=["Workflow Tags"],+ tags=["Agent Tags"],openapi_extra={"x-fern-sdk-method-name": "get_workflow_tag_history"},description="Chronological tag-event log for a workflow (newest first). Includes SET and DELETE events.",- summary="Get workflow tag history",+ summary="Get agent tag history",responses={200: {"description": "Successfully retrieved tag history"},404: {"description": "Workflow not found"},@@ -1735,7 +1745,7 @@ async def get_workflow_tag_history(@base_router.get("/tag-keys",response_model=list[TagKey],- tags=["Workflow Tags"],+ tags=["Agent Tags"],openapi_extra={"x-fern-sdk-method-name": "list_tag_keys"},description="List all tag keys registered for the organization with their descriptions.",summary="List tag keys",@@ -1754,7 +1764,7 @@ async def list_tag_keys(@base_router.patch("/tag-keys/{key}",response_model=TagKey,- tags=["Workflow Tags"],+ tags=["Agent Tags"],openapi_extra={"x-fern-sdk-method-name": "update_tag_key"},description="Update the description for a tag key.",summary="Update tag key",@@ -1839,10 +1849,10 @@ async def _resolve_active_batch_wpids(requested_wpids: list[str], organization_i@base_router.get("/workflow-tags",response_model=WorkflowTagsBatchResponse,- tags=["Workflow Tags"],- openapi_extra={"x-fern-sdk-method-name": "batch_get_workflow_tags"},+ tags=["Agent Tags"],+ openapi_extra={"x-hidden": True, "x-fern-sdk-method-name": "batch_get_workflow_tags"},description="Batch fetch current tags for many workflows. Avoids N+1 on the workflows-list page.",- summary="Batch get workflow tags",+ summary="Batch get agent tags",responses={200: {"description": "Successfully retrieved tags"},400: {"description": "Too many workflow IDs requested"},@@ -1874,10 +1884,10 @@ async def batch_get_workflow_tags(@base_router.post("/workflow-tags",response_model=WorkflowTagsBatchResponse,- tags=["Workflow Tags"],- openapi_extra={"x-fern-sdk-method-name": "batch_get_workflow_tags_post"},+ tags=["Agent Tags"],+ openapi_extra={"x-hidden": True, "x-fern-sdk-method-name": "batch_get_workflow_tags_post"},description="Batch fetch current tags for many workflows (POST variant for id lists exceeding URL length).",- summary="Batch get workflow tags (POST)",+ summary="Batch get agent tags (POST)",responses={200: {"description": "Successfully retrieved tags"},400: {"description": "Too many workflow IDs requested"},@@ -2301,7 +2311,7 @@ async def get_run_artifacts(@base_router.post("/runs/{run_id}/retry_webhook",- tags=["Agent", "Workflow Runs"],+ tags=["Agents"],openapi_extra={"x-fern-sdk-method-name": "retry_run_webhook","x-fern-examples": [@@ -2314,7 +2324,7 @@ async def get_run_artifacts(],},description="Retry sending the webhook for a run",- summary="Retry run webhook",+ summary="Replay a run webhook",response_model=RunWebhookReplayResponse,)@base_router.post("/runs/{run_id}/retry_webhook/", include_in_schema=False)@@ -2335,7 +2345,7 @@ async def retry_run_webhook(@base_router.get("/runs/{run_id}/timeline",- tags=["Agent", "Workflow Runs", "Workflows"],+ tags=["Agents"],response_model=list[WorkflowRunTimeline],openapi_extra={"x-fern-sdk-method-name": "get_run_timeline",@@ -2771,13 +2781,13 @@ def _workflow_run_request_from_workflow_request(@base_router.post("/workflows/runs/{workflow_run_id}/retry",- tags=["Workflow Runs", "Workflows"],+ tags=["Agents"],response_model=WorkflowRunResponse,openapi_extra={"x-fern-sdk-method-name": "retry_workflow_run",},description="Retry a workflow run using the original run parameters.",- summary="Retry workflow run",+ summary="Retry a run",responses={200: {"description": "Successfully retried workflow run"},400: {"description": "Workflow run is not retryable"},@@ -3108,6 +3118,7 @@ async def get_runs(tags=["agent"],response_model=list[TaskRunListItem],openapi_extra={+ "x-hidden": True,"x-fern-sdk-method-name": "get_runs_v2",},)@@ -3344,7 +3355,7 @@ async def run_workflow_legacy(@base_router.get("/workflows/runs",response_model=list[WorkflowRun],- tags=["Workflow Runs"],+ tags=["Agents"],description=("List workflow runs across all workflows for the current organization.\n\n""Results are paginated and can be filtered by **status**, **search_key**, and **error_code**. "@@ -3371,7 +3382,7 @@ async def run_workflow_legacy("- `?status=failed&error_code=LOGIN_FAILED` — failed runs **and** have a LOGIN_FAILED error\n""- `?status=failed&error_code=LOGIN_FAILED&search_key=prod_credential` — all three conditions must match"),- summary="List workflow runs",+ summary="Get all runs",openapi_extra={"x-fern-sdk-method-name": "get_workflow_runs",},@@ -3494,9 +3505,9 @@ async def _get_workflow_runs_by_id(@base_router.get("/workflows/{workflow_id}/runs",response_model=list[WorkflowRun],- tags=["Workflow Runs", "Workflows"],+ tags=["Agents"],description=_WORKFLOW_RUNS_BY_ID_DESCRIPTION,- summary="List runs for a workflow",+ summary="Get all runs by agent",openapi_extra={"x-fern-sdk-method-name": "get_workflow_runs_by_id",},@@ -3557,7 +3568,7 @@ async def get_workflow_runs_by_id(response_model=list[WorkflowRun],tags=["agent"],description=_WORKFLOW_RUNS_BY_ID_DESCRIPTION,- summary="List runs for a workflow",+ summary="Get all runs by agent",openapi_extra={"x-fern-sdk-method-name": "get_workflow_runs_by_id",},@@ -3753,7 +3764,8 @@ async def get_workflow_run(@base_router.get("/workflows",response_model=list[Workflow],- tags=["Workflows"],+ tags=["Agents"],+ summary="Get all agents",openapi_extra={"x-fern-sdk-method-name": "get_workflows","x-fern-examples": [@@ -3886,7 +3898,7 @@ async def get_workflows(@base_router.put("/workflows/{workflow_permanent_id}/template",- tags=["Workflows"],+ tags=["Agents"],include_in_schema=False,)async def set_workflow_template_status(@@ -3943,7 +3955,8 @@ async def get_workflow_templates() -> list[Workflow]:@base_router.get("/workflows/{workflow_permanent_id}",response_model=Workflow,- tags=["Workflows"],+ tags=["Agents"],+ summary="Get an agent by id",openapi_extra={"x-fern-sdk-method-name": "get_workflow",},@@ -3978,7 +3991,8 @@ async def get_workflow(@base_router.get("/workflows/{workflow_permanent_id}/versions",response_model=list[Workflow],- tags=["Workflows"],+ tags=["Agents"],+ summary="Get agent versions",openapi_extra={"x-fern-sdk-method-name": "get_workflow_versions",},@@ -4006,8 +4020,9 @@ async def get_workflow_versions(@base_router.post("/workflows/{workflow_permanent_id}/browser_session/reset_profile",status_code=http_status.HTTP_204_NO_CONTENT,- tags=["Workflows"],+ tags=["Agents"],summary="Reset persisted browser profile",+ openapi_extra={"x-hidden": True},description=("Clear the persisted browser profile for a workflow that uses `Save & Reuse Session`. ""The next run will start from a fresh browser state. Use when a saved profile is corrupted."diff --git a/skyvern/forge/sdk/routes/run_blocks.py b/skyvern/forge/sdk/routes/run_blocks.pyindex 3ad0c01e1..7ccbd2175 100644--- a/skyvern/forge/sdk/routes/run_blocks.py+++ b/skyvern/forge/sdk/routes/run_blocks.py@@ -122,9 +122,10 @@ async def _run_workflow_and_build_response(@base_router.post("/run/tasks/login",- tags=["Agent"],+ tags=["Agents"],response_model=WorkflowRunResponse,openapi_extra={+ "x-hidden": True,"x-excluded": True,"x-fern-sdk-method-name": "login","x-fern-examples": [@@ -289,9 +290,10 @@ async def login(@base_router.post("/run/tasks/download_files",- tags=["Agent"],+ tags=["Agents"],response_model=WorkflowRunResponse,openapi_extra={+ "x-hidden": True,"x-excluded": True,"x-fern-sdk-method-name": "download_files","x-fern-examples": [diff --git a/skyvern/forge/sdk/routes/workflow_schedules.py b/skyvern/forge/sdk/routes/workflow_schedules.pyindex 0e4ada266..b35d258ea 100644--- a/skyvern/forge/sdk/routes/workflow_schedules.py+++ b/skyvern/forge/sdk/routes/workflow_schedules.py@@ -229,7 +229,7 @@ async def list_organization_schedules(response_model=WorkflowScheduleResponse,tags=["Schedules"],operation_id="schedules_create",- summary="Create a schedule for a workflow",+ summary="Create a schedule for an agent",)async def create_workflow_schedule(workflow_permanent_id: str,@@ -366,7 +366,7 @@ async def create_workflow_schedule(response_model=WorkflowScheduleListResponse,tags=["Schedules"],operation_id="schedules_list",- summary="List schedules for a workflow",+ summary="List schedules for an agent",)async def list_workflow_schedules(workflow_permanent_id: str,@@ -387,7 +387,7 @@ async def list_workflow_schedules(response_model=WorkflowScheduleResponse,tags=["Schedules"],operation_id="schedules_get",- summary="Get a workflow schedule by id",+ summary="Get an agent schedule by id",)async def get_workflow_schedule(workflow_permanent_id: str,@@ -414,7 +414,7 @@ async def get_workflow_schedule(response_model=WorkflowScheduleResponse,tags=["Schedules"],operation_id="schedules_update",- summary="Update a workflow schedule",+ summary="Update an agent schedule",)async def update_workflow_schedule(workflow_permanent_id: str,@@ -542,7 +542,7 @@ async def update_workflow_schedule(response_model=WorkflowScheduleResponse,tags=["Schedules"],operation_id="schedules_enable",- summary="Enable a workflow schedule",+ summary="Enable an agent schedule",)async def enable_workflow_schedule(workflow_permanent_id: str,@@ -567,7 +567,7 @@ async def enable_workflow_schedule(response_model=WorkflowScheduleResponse,tags=["Schedules"],operation_id="schedules_disable",- summary="Disable a workflow schedule",+ summary="Disable an agent schedule",)async def disable_workflow_schedule(workflow_permanent_id: str,@@ -591,7 +591,7 @@ async def disable_workflow_schedule(response_model=DeleteScheduleResponse,tags=["Schedules"],operation_id="schedules_delete",- summary="Delete a workflow schedule",+ summary="Delete an agent schedule",)async def delete_workflow_schedule_route(workflow_permanent_id: str,diff --git a/skyvern/forge/sdk/workflow/models/workflow.py b/skyvern/forge/sdk/workflow/models/workflow.pyindex 73508beaa..a50abbc91 100644--- a/skyvern/forge/sdk/workflow/models/workflow.py+++ b/skyvern/forge/sdk/workflow/models/workflow.py@@ -2,7 +2,7 @@ from datetime import datetimefrom enum import StrEnumfrom typing import Any, List-from pydantic import BaseModel, Field, field_serializer, field_validator+from pydantic import BaseModel, Field, computed_field, field_serializer, field_validatorfrom typing_extensions import deprecatedfrom skyvern.forge.sdk.db.enums import WorkflowRunTriggerType@@ -67,6 +67,16 @@ class RunWorkflowResponse(BaseModel):workflow_id: strworkflow_run_id: str+ @computed_field(description="Alias of `workflow_id` (the agent's `wpid_` permanent ID).") # type: ignore[prop-decorator]+ @property+ def agent_id(self) -> str:+ return self.workflow_id++ @computed_field(description="Alias of `workflow_run_id`.") # type: ignore[prop-decorator]+ @property+ def agent_run_id(self) -> str:+ return self.workflow_run_id+class WorkflowDefinition(BaseModel):version: int = 1@@ -110,6 +120,14 @@ class Workflow(BaseModel):title: strworkflow_permanent_id: strversion: int++ @computed_field( # type: ignore[prop-decorator]+ description="Alias of `workflow_permanent_id` — the stable agent identifier (starts with `wpid_`)."+ )+ @property+ def agent_id(self) -> str:+ return self.workflow_permanent_id+is_saved_task: boolis_template: bool = Falsedescription: str | None = None@@ -308,6 +326,17 @@ class WorkflowRunOutputParameter(BaseModel):class WorkflowRunResponseBase(BaseModel):workflow_id: strworkflow_run_id: str++ @computed_field(description="Alias of `workflow_id` (the agent's `wpid_` permanent ID).") # type: ignore[prop-decorator]+ @property+ def agent_id(self) -> str:+ return self.workflow_id++ @computed_field(description="Alias of `workflow_run_id`.") # type: ignore[prop-decorator]+ @property+ def agent_run_id(self) -> str:+ return self.workflow_run_id+status: WorkflowRunStatusfailure_reason: str | None = Nonefailure_category: list[dict[str, Any]] | None = Nonediff --git a/skyvern/schemas/runs.py b/skyvern/schemas/runs.pyindex f9a380372..04d480538 100644--- a/skyvern/schemas/runs.py+++ b/skyvern/schemas/runs.py@@ -3,7 +3,15 @@ from __future__ import annotationsfrom datetime import datetimefrom typing import TYPE_CHECKING, Annotated, Any, Literal, TypeAlias, Union-from pydantic import BaseModel, ConfigDict, Field, field_serializer, field_validator, model_validator+from pydantic import (+ AliasChoices,+ BaseModel,+ ConfigDict,+ Field,+ field_serializer,+ field_validator,+ model_validator,+)from skyvern.forge.sdk.schemas.files import FileInfofrom skyvern.forge.sdk.workflow.models.run_limits import (@@ -208,8 +216,16 @@ class TaskRunRequest(BaseModel):class WorkflowRunRequest(BaseModel):+ # An agent *is* a workflow, so `agent_id` and `workflow_id` carry the same `wpid_` value. `agent_id`+ # is listed first so the public request schema advertises the agent-named field, while `workflow_id`+ # stays accepted for backwards compatibility. `populate_by_name` keeps internal+ # `WorkflowRunRequest(workflow_id=...)` construction working alongside the aliases.+ model_config = ConfigDict(populate_by_name=True)+workflow_id: str = Field(- description="ID of the workflow to run. Workflow ID starts with `wpid_`.", examples=["wpid_123"]+ validation_alias=AliasChoices("agent_id", "workflow_id"),+ description="ID of the agent to run. Starts with `wpid_`. `workflow_id` is accepted as an alias.",+ examples=["wpid_123"],)parameters: dict[str, Any] | None = Field(default=None, description="Parameters to pass to the workflow")title: str | None = Field(default=None, description="The title for this workflow run")@@ -462,6 +478,10 @@ class WorkflowRunResponse(BaseRunResponse):run_request: WorkflowRunRequest | None = Field(default=None, description="The original request parameters used to start this workflow run")+ # NOTE: no top-level `agent_id` here on purpose. This model has no reliable permanent-id field+ # (only `run_request.workflow_id`, which is absent on some reads and is a version id on the+ # login/download paths), so a computed alias would echo null/wrong values. The reliable agent_id+ # alias lives on WorkflowRunResponseBase / Workflow / RunWorkflowResponse instead.RunResponse = Annotated[Union[TaskRunResponse, WorkflowRunResponse], Field(discriminator="run_type")]diff --git a/tests/unit/test_agent_alias.py b/tests/unit/test_agent_alias.pynew file mode 100644index 000000000..ce0a63f29--- /dev/null+++ b/tests/unit/test_agent_alias.py@@ -0,0 +1,85 @@+"""Backwards-compatible `agent_id` alias for the workflows API.++An agent *is* a workflow, so `agent_id` is accepted anywhere `workflow_id`/`workflow_permanent_id`+is, carrying the same `wpid_` value, and is echoed back in responses alongside the original fields.+"""++from datetime import UTC, datetime++from skyvern.forge.sdk.workflow.models.workflow import (+ RunWorkflowResponse,+ Workflow,+ WorkflowDefinition,+ WorkflowRunResponseBase,+ WorkflowRunStatus,+)+from skyvern.schemas.runs import RunType, WorkflowRunRequest, WorkflowRunResponse+++def test_workflow_run_request_accepts_agent_id_and_workflow_id() -> None:+ by_alias = WorkflowRunRequest.model_validate({"agent_id": "wpid_abc"})+ by_name = WorkflowRunRequest.model_validate({"workflow_id": "wpid_abc"})+ assert by_alias.workflow_id == by_name.workflow_id == "wpid_abc"+ # constructing by python field name keeps working too+ assert WorkflowRunRequest(workflow_id="wpid_abc").workflow_id == "wpid_abc"+++def test_workflow_run_request_output_keeps_workflow_id_only() -> None:+ # agent_id is an *input* alias; the serialized request body stays on the canonical workflow_id+ # field and must not start emitting an agent_id key (which would break existing consumers).+ dumped = WorkflowRunRequest(agent_id="wpid_abc").model_dump()+ assert dumped["workflow_id"] == "wpid_abc"+ assert "agent_id" not in dumped+++def test_workflow_run_response_omits_unreliable_agent_id() -> None:+ # The v2 run response intentionally has no top-level agent_id: it has no reliable permanent-id+ # source, so a computed alias would echo null (no run_request) or a version id (login/download).+ # The reliable alias lives on WorkflowRunResponseBase / Workflow / RunWorkflowResponse instead.+ response = WorkflowRunResponse(+ run_id="wr_1",+ run_type=RunType.workflow_run,+ status="completed",+ created_at=datetime.now(UTC),+ modified_at=datetime.now(UTC),+ run_request=WorkflowRunRequest(workflow_id="wpid_abc"),+ )+ assert "agent_id" not in response.model_dump()+++def test_run_workflow_response_echoes_agent_aliases() -> None:+ dumped = RunWorkflowResponse(workflow_id="wpid_abc", workflow_run_id="wr_1").model_dump()+ assert dumped["agent_id"] == "wpid_abc"+ assert dumped["agent_run_id"] == "wr_1"+ # originals preserved for backwards compatibility+ assert dumped["workflow_id"] == "wpid_abc"+ assert dumped["workflow_run_id"] == "wr_1"+++def test_workflow_run_response_base_echoes_agent_aliases() -> None:+ dumped = WorkflowRunResponseBase(+ workflow_id="wpid_abc",+ workflow_run_id="wr_1",+ status=WorkflowRunStatus.completed,+ created_at=datetime.now(UTC),+ modified_at=datetime.now(UTC),+ parameters={},+ ).model_dump()+ assert dumped["agent_id"] == "wpid_abc"+ assert dumped["agent_run_id"] == "wr_1"+++def test_workflow_object_echoes_agent_id() -> None:+ workflow = Workflow(+ workflow_id="w_1",+ organization_id="o_1",+ title="example",+ workflow_permanent_id="wpid_abc",+ version=1,+ is_saved_task=False,+ workflow_definition=WorkflowDefinition(parameters=[], blocks=[]),+ created_at=datetime.now(UTC),+ modified_at=datetime.now(UTC),+ )+ assert workflow.agent_id == "wpid_abc"+ assert workflow.model_dump()["agent_id"] == "wpid_abc"diff --git a/tests/unit/test_agent_route_aliases.py b/tests/unit/test_agent_route_aliases.pynew file mode 100644index 000000000..6b7f3694b--- /dev/null+++ b/tests/unit/test_agent_route_aliases.py@@ -0,0 +1,80 @@+"""The public /workflows API surface is mirrored to /agents and hidden from the OpenAPI schema.++`register_agent_route_aliases` adds an /agents twin for every in-schema /workflows route (preserving+the handler, params, response models and fern SDK metadata) and drops the /workflows form from the+schema while keeping it callable for backwards compatibility.+"""++import importlib++import pytest+from fastapi import FastAPI+from fastapi.routing import APIRoute++from skyvern.forge.api_app import register_agent_route_aliases+from skyvern.forge.sdk.routes.routers import base_router++[email protected](scope="module")+def app() -> FastAPI:+ # Import the route modules so base_router is fully populated before we mirror it.+ for module in ("agent_protocol", "run_blocks", "workflow_schedules"):+ importlib.import_module(f"skyvern.forge.sdk.routes.{module}")+ fastapi_app = FastAPI()+ fastapi_app.include_router(base_router, prefix="/v1")+ register_agent_route_aliases(fastapi_app)+ return fastapi_app+++def test_no_workflow_paths_remain_in_schema(app: FastAPI) -> None:+ visible_workflow_paths = [path for path in app.openapi()["paths"] if "workflows" in path]+ assert visible_workflow_paths == []+++ "expected_path",+ [+ "/v1/run/agents",+ "/v1/agents",+ "/v1/agents/{workflow_id}",+ "/v1/agents/{workflow_id}/delete",+ "/v1/agents/{workflow_permanent_id}",+ "/v1/agents/{workflow_permanent_id}/versions",+ "/v1/agents/{workflow_permanent_id}/schedules",+ "/v1/agents/{workflow_permanent_id}/tags",+ ],+)+def test_agents_paths_present_in_schema(app: FastAPI, expected_path: str) -> None:+ assert expected_path in app.openapi()["paths"]+++def test_fern_metadata_preserved_on_twins(app: FastAPI) -> None:+ paths = app.openapi()["paths"]+ # SDK method name carried over verbatim, so generated SDK methods are unchanged+ assert paths["/v1/run/agents"]["post"]["x-fern-sdk-method-name"] == "run_workflow"+ # operation_id-based method names are preserved too+ assert paths["/v1/agents/{workflow_permanent_id}/schedules"]["post"]["operationId"] == "schedules_create"+++def test_twins_preserve_original_operation_id(app: FastAPI) -> None:+ # A mirrored route with no explicit operation_id must keep the original /workflows-derived+ # operationId (not get a fresh /agents one), so OpenAPI-generated clients don't see renamed operations.+ operation_id = app.openapi()["paths"]["/v1/agents"]["get"]["operationId"]+ assert "workflows" in operation_id and "agents" not in operation_id+++def test_workflow_routes_remain_callable_but_hidden(app: FastAPI) -> None:+ workflow_routes = [r for r in app.router.routes if isinstance(r, APIRoute) and "/workflows" in r.path]+ # the /workflows routes still exist so deployed SDKs / integrations keep working ...+ assert workflow_routes+ # ... but none of them are advertised in the public schema+ assert all(not route.include_in_schema for route in workflow_routes)+++def test_task_endpoints_hidden_from_docs_but_kept_in_sdk(app: FastAPI) -> None:+ # `x-hidden` hides these from the Mintlify docs reference, but the operations stay in the+ # OpenAPI schema (include_in_schema=True), so the Fern SDK still generates the methods+ # (e.g. client.run_task()) — docs-only hide, backwards-compatible for SDK users.+ run_task = app.openapi()["paths"]["/v1/run/tasks"]["post"]+ assert run_task["x-hidden"] is True+ assert run_task["x-fern-sdk-method-name"] == "run_task"