Skip to content

Automate browser based workflows with AI

Route script-assist LLM calls through the per-prompt model config flag (#8015)

Cindy Liac96c71257e4
diff --git a/docs/plans/2026-08-03-sky-13291-vendor-live-view-metadata.md b/docs/plans/2026-08-03-sky-13291-vendor-live-view-metadata.md
new file mode 100644
index 000000000..0fd5200ef
--- /dev/null
+++ b/docs/plans/2026-08-03-sky-13291-vendor-live-view-metadata.md
@@ -0,0 +1,72 @@
+# SKY-13291 vendor live-view metadata persistence
+
+## Scope
+
+This PR is the persistence prerequisite for vendor live view. It captures the credential-bearing
+live-view URL and a provider-neutral protocol value at the provider response, carries them only in
+the vendor provisioning activity, and stores them only in `browser_session_infra`.
+
+It does not add a viewer, router relay, API field, CSP rule, or frontend code. Those paths remain
+blocked on a documented raw RFB endpoint for headful Anchor sessions and a Browser Use strategy
+that does not send vendor HTML or JavaScript to customers.
+
+## Implementation
+
+1. Add nullable `live_view_url` and `live_view_protocol` columns to
+ `browser_session_infra` with one additive Alembic migration.
+2. Extend the cloud-only infrastructure repository to atomically attach the provider session id
+ and live-view metadata after provisioning. Keep both sensitive fields out of dataclass reprs.
+3. Capture Anchor's live-view URL from both supported provisioning transports. Classify current
+ headful sessions as `rfb` and future explicitly headless sessions as `cdp_screencast`.
+4. Capture Browser Use's `live_url` and classify it as `hosted_html`.
+5. Carry the metadata in the activity-local `VendorBrowser` only. Do not add it to
+ `VendorProvisionResult`, `PersistentBrowserSession`, or any API schema.
+
+## Acceptance criteria
+
+- A successful provider provision stores its live-view URL and generic protocol in
+ `browser_session_infra` together with the provider session id.
+- Missing live-view metadata remains nullable and does not make an otherwise usable browser fail.
+- The credential does not appear in object repr/string output, structured logs, Temporal activity
+ payloads, persistent browser-session models, OpenAPI schemas, or client code.
+- Existing provider-identity non-disclosure tests remain green.
+- The migration graph has exactly one head.
+
+## Verification
+
+```bash
+uv run pytest tests/cloud/test_anchor_session_provisioner.py \
+ tests/cloud/test_browser_session_infra.py \
+ tests/cloud/test_pbs_vendor_session_lifecycle.py \
+ tests/cloud/test_vendor_identity_nondisclosure.py \
+ tests/unit/webeye/test_browser_session_response.py -q
+uv run pytest tests/cloud/test_migration_chain.py -q
+uv run alembic heads
+uv run python -m py_compile <each modified Python file>
+uv run ruff check <modified Python files>
+uv run pre-commit run --files <modified files>
+```
+
+Each security assertion is mutation-checked by temporarily removing its production guard, running
+the focused test to observe failure, restoring the guard, and rerunning the test to green.
+
+## Escalation: Size Limits
+
+**What I tried**: Implemented the human-approved persistence-only slice with the six requested
+mutation-proven confinement checks, then fixed three credential-safety findings from independent
+review: SQL bound-parameter redaction, provider traceback-local scrubbing, and cancellation-safe
+credential cleanup.
+
+**What blocked me**: The resulting code diff is 617 changed lines excluding this plan and the new
+migration: 584 additions and 33 deletions across five production and four test files. The
+repository stop limit is 500 changed lines. The split is 197 production lines and 420 test lines;
+the requested security and mutation coverage accounts for most of the excess. The change remains
+within the file-count and subsystem limits.
+
+**Decision needed**: A human must either approve a size-limit exception for this security-focused
+slice or direct a specific reduction/split. No commit, push, or PR will be created without that
+decision.
+
+**My recommendation**: Approve the exception for this slice. Splitting the confinement tests from
+the credential persistence they protect would make either PR independently unsafe, and deleting
+tests would weaken the explicit mutation-proof requirement.
diff --git a/skyvern/core/script_generations/real_skyvern_page_ai.py b/skyvern/core/script_generations/real_skyvern_page_ai.py
index ae051e8f3..d6d875a8b 100644
--- a/skyvern/core/script_generations/real_skyvern_page_ai.py
+++ b/skyvern/core/script_generations/real_skyvern_page_ai.py
@@ -17,6 +17,7 @@ from skyvern.exceptions import NoTOTPSecretFound, SkyvernActionFailed, WorkflowR
from skyvern.forge import app
from skyvern.forge.prompts import prompt_engine
from skyvern.forge.sdk.api.files import validate_download_url
+from skyvern.forge.sdk.api.llm.api_handler import LLMAPIHandler
from skyvern.forge.sdk.api.llm.api_handler_factory import (
get_org_aware_primary_llm_api_handler,
get_org_aware_secondary_llm_api_handler,
@@ -24,6 +25,7 @@ from skyvern.forge.sdk.api.llm.api_handler_factory import (
from skyvern.forge.sdk.api.llm.schema_validator import validate_and_fill_extraction_result
from skyvern.forge.sdk.cache import extraction_cache
from skyvern.forge.sdk.core import skyvern_context
+from skyvern.forge.sdk.experimentation.llm_prompt_config import resolve_prompt_type_handler
from skyvern.forge.sdk.schemas.totp_codes import OTPType
from skyvern.forge.sdk.services.credentials import is_unresolved_totp_value
from skyvern.schemas.workflows import BlockStatus
@@ -72,6 +74,16 @@ UPLOAD_GOAL = """- The intention to upload a file: {intention}.
- The overall goal that the user wants to achieve: {prompt}."""
+async def _resolve_assist_llm_handler(prompt_type: str, default: LLMAPIHandler) -> LLMAPIHandler:
+ """LLM_CONFIG_BY_PROMPT_TYPE payload wins; else the org-aware secondary handler, matching prior behavior."""
+ org_aware_default = get_org_aware_secondary_llm_api_handler(default=default)
+ context = skyvern_context.current()
+ distinct_id = (context.workflow_run_id or context.task_id) if context else None
+ if not context or not distinct_id:
+ return org_aware_default
+ return await resolve_prompt_type_handler(prompt_type, distinct_id, context.organization_id, org_aware_default)
+
+
async def _get_element_id_by_selector(selector: str, page: Page) -> str | None:
try:
locator = page.locator(selector)
@@ -241,9 +253,10 @@ class RealSkyvernPageAi(SkyvernPageAi):
local_datetime=datetime.now(context.tz_info or datetime.now().astimezone().tzinfo).isoformat(),
user_context=context.prompt,
)
- json_response = await get_org_aware_secondary_llm_api_handler(
- default=app.SINGLE_CLICK_AGENT_LLM_API_HANDLER
- )(
+ llm_handler = await _resolve_assist_llm_handler(
+ "single-click-action", app.SINGLE_CLICK_AGENT_LLM_API_HANDLER
+ )
+ json_response = await llm_handler(
prompt=single_click_prompt,
prompt_name="single-click-action",
step=step,
@@ -404,9 +417,10 @@ class RealSkyvernPageAi(SkyvernPageAi):
goal=prompt,
data=data,
)
- json_response = await get_org_aware_secondary_llm_api_handler(
- default=app.SINGLE_INPUT_AGENT_LLM_API_HANDLER
- )(
+ llm_handler = await _resolve_assist_llm_handler(
+ "script-generation-input-text-generatiion", app.SINGLE_INPUT_AGENT_LLM_API_HANDLER
+ )
+ json_response = await llm_handler(
prompt=script_generation_input_text_prompt,
prompt_name="script-generation-input-text-generatiion",
step=step,
@@ -442,9 +456,10 @@ class RealSkyvernPageAi(SkyvernPageAi):
elements=element_tree,
local_datetime=datetime.now(context.tz_info or datetime.now().astimezone().tzinfo).isoformat(),
)
- json_response = await get_org_aware_secondary_llm_api_handler(
- default=app.SINGLE_INPUT_AGENT_LLM_API_HANDLER
- )(
+ llm_handler = await _resolve_assist_llm_handler(
+ "single-input-action", app.SINGLE_INPUT_AGENT_LLM_API_HANDLER
+ )
+ json_response = await llm_handler(
prompt=single_input_prompt,
prompt_name="single-input-action",
step=step,
@@ -523,9 +538,10 @@ class RealSkyvernPageAi(SkyvernPageAi):
data=data,
goal=prompt,
)
- json_response = await get_org_aware_secondary_llm_api_handler(
- default=app.SINGLE_INPUT_AGENT_LLM_API_HANDLER
- )(
+ llm_handler = await _resolve_assist_llm_handler(
+ "script-generation-file-url-generation", app.SINGLE_INPUT_AGENT_LLM_API_HANDLER
+ )
+ json_response = await llm_handler(
prompt=script_generation_file_url_prompt,
prompt_name="script-generation-file-url-generation",
step=step,
@@ -559,9 +575,10 @@ class RealSkyvernPageAi(SkyvernPageAi):
elements=element_tree,
local_datetime=datetime.now(context.tz_info or datetime.now().astimezone().tzinfo).isoformat(),
)
- json_response = await get_org_aware_secondary_llm_api_handler(
- default=app.SINGLE_INPUT_AGENT_LLM_API_HANDLER
- )(
+ llm_handler = await _resolve_assist_llm_handler(
+ "single-upload-action", app.SINGLE_INPUT_AGENT_LLM_API_HANDLER
+ )
+ json_response = await llm_handler(
prompt=single_upload_prompt,
prompt_name="single-upload-action",
step=step,
@@ -632,9 +649,10 @@ class RealSkyvernPageAi(SkyvernPageAi):
elements=element_tree,
local_datetime=datetime.now(context.tz_info or datetime.now().astimezone().tzinfo).isoformat(),
)
- json_response = await get_org_aware_secondary_llm_api_handler(
- default=app.SELECT_AGENT_LLM_API_HANDLER
- )(
+ llm_handler = await _resolve_assist_llm_handler(
+ "single-select-action", app.SELECT_AGENT_LLM_API_HANDLER
+ )
+ json_response = await llm_handler(
prompt=single_select_prompt,
prompt_name="single-select-action",
step=step,
@@ -1643,7 +1661,10 @@ class RealSkyvernPageAi(SkyvernPageAi):
navigation_goal=prompt,
)
- json_response = await get_org_aware_secondary_llm_api_handler(default=app.SINGLE_INPUT_AGENT_LLM_API_HANDLER)(
+ infer_llm_handler = await _resolve_assist_llm_handler(
+ "infer-action-type", app.SINGLE_INPUT_AGENT_LLM_API_HANDLER
+ )
+ json_response = await infer_llm_handler(
prompt=infer_action_type_prompt,
prompt_name="infer-action-type",
step=step,
@@ -1699,7 +1720,7 @@ class RealSkyvernPageAi(SkyvernPageAi):
else:
LOG.warning("ai_act: unknown action type", action_type=action_type, prompt=prompt)
return
- llm_handler = get_org_aware_secondary_llm_api_handler(default=llm_handler)
+ llm_handler = await _resolve_assist_llm_handler(template, llm_handler)
local_datetime = datetime.now(context.tz_info or datetime.now().astimezone().tzinfo).isoformat()
single_action_prompt = prompt_engine.load_prompt(
diff --git a/tests/unit/test_llm_prompt_config.py b/tests/unit/test_llm_prompt_config.py
index 40f790ad0..2a3b8a50c 100644
--- a/tests/unit/test_llm_prompt_config.py
+++ b/tests/unit/test_llm_prompt_config.py
@@ -298,3 +298,65 @@ async def test_org_primary_override_skips_check_user_goal_config_lookup(monkeypa
assert result is None
provider.get_value_cached.assert_not_awaited()
+
+
+# ---------------------------------------------------------------------------
+# _resolve_assist_llm_handler: script-assist call sites honor the payload
+# ---------------------------------------------------------------------------
+
+
+async def test_assist_handler_delegates_to_prompt_type_resolution(monkeypatch: pytest.MonkeyPatch) -> None:
+ from skyvern.core.script_generations import real_skyvern_page_ai as page_ai
+
+ default_handler = AsyncMock(name="default")
+ org_aware_handler = AsyncMock(name="org_aware")
+ payload_handler = AsyncMock(name="payload")
+ monkeypatch.setattr(page_ai, "get_org_aware_secondary_llm_api_handler", lambda default: org_aware_handler)
+ resolve = AsyncMock(return_value=payload_handler)
+ monkeypatch.setattr(page_ai, "resolve_prompt_type_handler", resolve)
+ monkeypatch.setattr(
+ page_ai.skyvern_context,
+ "current",
+ lambda: SkyvernContext(workflow_run_id="wr_123", task_id="tsk_456", organization_id="org_1"),
+ )
+
+ result = await page_ai._resolve_assist_llm_handler("single-input-action", default_handler)
+
+ assert result is payload_handler
+ resolve.assert_awaited_once_with("single-input-action", "wr_123", "org_1", org_aware_handler)
+
+
+async def test_assist_handler_uses_task_id_when_no_workflow_run(monkeypatch: pytest.MonkeyPatch) -> None:
+ from skyvern.core.script_generations import real_skyvern_page_ai as page_ai
+
+ org_aware_handler = AsyncMock(name="org_aware")
+ monkeypatch.setattr(page_ai, "get_org_aware_secondary_llm_api_handler", lambda default: org_aware_handler)
+ resolve = AsyncMock(return_value=org_aware_handler)
+ monkeypatch.setattr(page_ai, "resolve_prompt_type_handler", resolve)
+ monkeypatch.setattr(
+ page_ai.skyvern_context,
+ "current",
+ lambda: SkyvernContext(task_id="tsk_456", organization_id="org_1"),
+ )
+
+ await page_ai._resolve_assist_llm_handler("single-click-action", AsyncMock())
+
+ resolve.assert_awaited_once_with("single-click-action", "tsk_456", "org_1", org_aware_handler)
+
+
+async def test_assist_handler_falls_back_without_context(monkeypatch: pytest.MonkeyPatch) -> None:
+ from skyvern.core.script_generations import real_skyvern_page_ai as page_ai
+
+ org_aware_handler = AsyncMock(name="org_aware")
+ monkeypatch.setattr(page_ai, "get_org_aware_secondary_llm_api_handler", lambda default: org_aware_handler)
+ resolve = AsyncMock(side_effect=AssertionError("must not consult the payload without a distinct id"))
+ monkeypatch.setattr(page_ai, "resolve_prompt_type_handler", resolve)
+ monkeypatch.setattr(page_ai.skyvern_context, "current", lambda: None)
+
+ result = await page_ai._resolve_assist_llm_handler("single-input-action", AsyncMock())
+
+ assert result is org_aware_handler
+ resolve.assert_not_awaited()