Skip to content

Automate browser based workflows with AI

Stamp a read-only auto-bind credential signal on the copilot narrative stream (#8064)

Celal Zamanoğlu38d2d8a922c6
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.py
index 92cf0780e..9efa23d35 100644
--- a/skyvern/forge/sdk/copilot/agent.py
+++ b/skyvern/forge/sdk/copilot/agent.py
@@ -2016,6 +2016,14 @@ def _make_agent_result(
reason = credential_prompt_reason(policy, kwargs.get("user_response"))
if reason:
payload_updates["credentialPrompt"] = {"reason": reason}
+ if ctx is not None and "credentialAutoBound" not in narrative_payload:
+ auto_bound = ctx.request_policy.auto_bound_credentials if ctx.request_policy is not None else []
+ if auto_bound:
+ bound = auto_bound[-1]
+ payload_updates["credentialAutoBound"] = {
+ "credentialId": bound.credential_id,
+ "name": bound.name,
+ }
if ctx is not None and "credentialPause" not in narrative_payload:
pause_outcome = ctx.credential_pause_outcome
if pause_outcome:
diff --git a/skyvern/forge/sdk/copilot/context.py b/skyvern/forge/sdk/copilot/context.py
index 6a6b231b8..8727a18b4 100644
--- a/skyvern/forge/sdk/copilot/context.py
+++ b/skyvern/forge/sdk/copilot/context.py
@@ -108,6 +108,9 @@ class TurnNarrativePayload(TypedDict):
# {"outcome": "connected"|"skipped"|"timeout", "credentialId": ...}, set when a mid-build
# credential pause (credential_pause.py) resolved during this turn.
credentialPause: NotRequired[dict[str, str]]
+ # {"credentialId": ..., "name": ...}, set when a credential was bound this turn without an ask
+ # (deterministic auto-bind); the FE renders it as a receipt with a Change affordance.
+ credentialAutoBound: NotRequired[dict[str, str]]
designStarted: bool
designEnded: bool
draft: NarrativeDraft | None
diff --git a/skyvern/forge/sdk/copilot/request_policy.py b/skyvern/forge/sdk/copilot/request_policy.py
index b07bdc92f..d10a88ecc 100644
--- a/skyvern/forge/sdk/copilot/request_policy.py
+++ b/skyvern/forge/sdk/copilot/request_policy.py
@@ -608,6 +608,9 @@ class RequestPolicy:
completion_contract: str | None = None
completion_criteria: list[CompletionCriterion] = field(default_factory=list)
resolved_credentials: list[Credential] = field(default_factory=list)
+ # Credentials bound this turn without a user ask (deterministic URL/urlless resolution + live-page
+ # sole-match); read-only telemetry for the auto-bind receipt, never a run-authority source.
+ auto_bound_credentials: list[Credential] = field(default_factory=list)
# credential_id -> the login page URL that granted it, so each later fill can confirm the
# browser has not left that site and a redirect cannot inherit the grant.
live_page_admitted_urls: dict[str, str] = field(default_factory=dict)
@@ -5126,6 +5129,7 @@ async def _resolve_credentials(
)
if resolution.verdict == "resolved":
policy.resolved_credentials = list(resolution.candidates)
+ policy.auto_bound_credentials = list(resolution.candidates)
return
if resolution.verdict == "ambiguous":
# Found-but-unbound keeps the unresolved-login override from
@@ -5283,6 +5287,7 @@ def _record_live_page_admission(policy: RequestPolicy, candidates: Sequence[Cred
for candidate in candidates:
if candidate.credential_id not in already_resolved:
policy.live_page_admitted_urls[candidate.credential_id] = page_url
+ policy.auto_bound_credentials.append(candidate)
async def resolve_credential_for_live_page(
diff --git a/tests/unit/test_copilot_make_agent_result_backfill.py b/tests/unit/test_copilot_make_agent_result_backfill.py
index 4e2c14eac..d19830c1c 100644
--- a/tests/unit/test_copilot_make_agent_result_backfill.py
+++ b/tests/unit/test_copilot_make_agent_result_backfill.py
@@ -4,6 +4,7 @@ narrative payload: ``responseKind`` from ``TurnOutcome.response_kind`` and
from __future__ import annotations
+from datetime import datetime
from types import SimpleNamespace
import pytest
@@ -18,6 +19,7 @@ from skyvern.forge.sdk.copilot.context import (
)
from skyvern.forge.sdk.copilot.request_policy import RequestPolicy
from skyvern.forge.sdk.schemas.copilot_turn_outcome import ResponseKind, TurnOutcome
+from skyvern.forge.sdk.schemas.workflow_copilot import WorkflowCopilotChatMessage, WorkflowCopilotChatSender
from tests.unit.copilot_test_helpers import failed_second_factor_run
from tests.unit.copilot_test_helpers import make_copilot_ctx as _ctx
from tests.unit.copilot_test_helpers import make_verified_goal_contract, passing_run, two_page_login_yaml
@@ -164,6 +166,60 @@ def test_backfill_adds_credential_prompt_from_text_marker_when_no_policy_signal(
assert result.narrative_payload["credentialPrompt"] == {"reason": "assistant_directed"}
+def test_backfill_emits_credential_auto_bound_receipt() -> None:
+ ctx = _ctx(
+ request_policy=RequestPolicy(
+ auto_bound_credentials=[SimpleNamespace(credential_id="cred_work", name="Work login")]
+ )
+ )
+ result = _result(ctx, turn_outcome=_outcome(ResponseKind.BUILD), narrative_payload=_payload())
+ assert result.narrative_payload is not None
+ assert result.narrative_payload["credentialAutoBound"] == {"credentialId": "cred_work", "name": "Work login"}
+
+
+def test_backfill_omits_credential_auto_bound_when_nothing_bound() -> None:
+ result = _result(
+ _ctx(request_policy=RequestPolicy()),
+ turn_outcome=_outcome(ResponseKind.BUILD),
+ narrative_payload=_payload(),
+ )
+ assert result.narrative_payload is not None
+ assert "credentialAutoBound" not in result.narrative_payload
+
+
+def test_backfill_credential_auto_bound_names_the_most_recent_bind() -> None:
+ # Turn-start bound one credential and a later live page bound another; the receipt names the most
+ # recent — the credential the run is actually signing in with now.
+ ctx = _ctx(
+ request_policy=RequestPolicy(
+ auto_bound_credentials=[
+ SimpleNamespace(credential_id="cred_turn_start", name="First"),
+ SimpleNamespace(credential_id="cred_live_page", name="Second"),
+ ]
+ )
+ )
+ result = _result(ctx, turn_outcome=_outcome(ResponseKind.BUILD), narrative_payload=_payload())
+ assert result.narrative_payload is not None
+ assert result.narrative_payload["credentialAutoBound"] == {"credentialId": "cred_live_page", "name": "Second"}
+
+
+def test_credential_auto_bound_survives_narrative_payload_serialization() -> None:
+ # The persisted/streamed wire model validates narrative_payload against the TurnNarrativePayload
+ # TypedDict and drops any key it does not declare, so the credentialAutoBound line is load-bearing:
+ # without it the field silently vanishes from model_dump and the FE loses the receipt on reload.
+ message = WorkflowCopilotChatMessage(
+ workflow_copilot_chat_message_id="m1",
+ workflow_copilot_chat_id="c1",
+ sender=WorkflowCopilotChatSender.AI,
+ content="done",
+ created_at=datetime(2026, 1, 1),
+ modified_at=datetime(2026, 1, 1),
+ narrative_payload=_payload(credentialAutoBound={"credentialId": "cred_x", "name": "Work login"}),
+ )
+ dumped = message.model_dump()["narrative_payload"]
+ assert dumped["credentialAutoBound"] == {"credentialId": "cred_x", "name": "Work login"}
+
+
def test_backfill_omits_credential_prompt_when_no_signal_present() -> None:
result = _result(_ctx(), user_response="Done, the workflow is ready.", narrative_payload=_payload())
assert result.narrative_payload is not None
diff --git a/tests/unit/test_copilot_request_policy_workflow_credentials.py b/tests/unit/test_copilot_request_policy_workflow_credentials.py
index 94170e927..4a8502f21 100644
--- a/tests/unit/test_copilot_request_policy_workflow_credentials.py
+++ b/tests/unit/test_copilot_request_policy_workflow_credentials.py
@@ -517,6 +517,8 @@ async def test_success_empty_refs_resolves_named_credential(kind: str) -> None:
assert policy.classifier_status == "success"
assert policy.credential_input_kind == kind
assert [c.credential_id for c in policy.resolved_credentials] == ["cred_login"]
+ # The user named the credential — not a silent auto-bind, so no receipt.
+ assert policy.auto_bound_credentials == []
assert policy.clarification_reason != "credential_name_unresolved"
@@ -1770,6 +1772,8 @@ async def test_login_intent_none_kind_one_message_url_with_single_match_resolves
assert policy.credential_input_kind == "none"
assert [c.credential_id for c in policy.resolved_credentials] == ["cred_url"]
+ # A deterministic URL-tier bind fired with no ask — the auto-bind receipt is stamped.
+ assert [c.credential_id for c in policy.auto_bound_credentials] == ["cred_url"]
assert policy.requires_user_clarification is False
assert policy.clarification_question is None
@@ -3076,8 +3080,23 @@ class TestLivePageCredentialObservation:
assert record.tier == "url_path"
assert [c.credential_id for c in record.candidates] == ["cred_analytics"]
assert [c.credential_id for c in policy.resolved_credentials] == ["cred_analytics"]
+ assert [c.credential_id for c in policy.auto_bound_credentials] == ["cred_analytics"]
assert policy.live_page_admitted_urls == {"cred_analytics": _LIVE_LOGIN_URL}
+ @pytest.mark.asyncio
+ async def test_a_page_reconfirming_a_turn_start_bind_is_not_double_stamped(self) -> None:
+ already = _cred("analytics", "cred_analytics", _SAVED_LOGIN_URL)
+ policy = RequestPolicy(resolved_credentials=[already])
+ await _resolve_live_page(
+ policy,
+ page_url=_LIVE_LOGIN_URL,
+ org_credentials=[already],
+ )
+
+ # A credential the turn already bound is not re-stamped as a fresh auto-bind by a later page.
+ assert policy.auto_bound_credentials == []
+ assert policy.live_page_admitted_urls == {}
+
@pytest.mark.asyncio
async def test_two_page_matches_bind_nothing_and_record_both_candidates(self) -> None:
policy = RequestPolicy()
@@ -3093,6 +3112,7 @@ class TestLivePageCredentialObservation:
assert record.verdict == "ambiguous"
assert [c.credential_id for c in record.candidates] == ["cred_one", "cred_two"]
assert policy.resolved_credentials == []
+ assert policy.auto_bound_credentials == []
assert policy.live_page_admitted_urls == {}
assert policy.live_page_resolution is record