Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Use current credential scope in deferral gates (#7716)
Andrew Neilsona137cbea80e6
diff --git a/skyvern/forge/sdk/copilot/request_policy.py b/skyvern/forge/sdk/copilot/request_policy.pyindex c3a87ede2..abf248719 100644--- a/skyvern/forge/sdk/copilot/request_policy.py+++ b/skyvern/forge/sdk/copilot/request_policy.py@@ -4618,6 +4618,7 @@ def _can_defer_unresolved_credential_name_for_draft(policy: RequestPolicy,*,global_llm_context: str,+ user_message: str,) -> bool:if policy.clarification_reason != "credential_name_unresolved":return False@@ -4626,7 +4627,7 @@ def _can_defer_unresolved_credential_name_for_draft(# anchoring before the name can enter resolved_credentials and authorize a run.if policy.credential_refs:return True- if _has_resolvable_credential_scope(policy):+ if _has_resolvable_credential_scope(policy, user_message):return Trueif _previous_credential_clarification_was_asked(global_llm_context):return True@@ -4637,13 +4638,14 @@ def _should_defer_repeated_unresolved_credential_question(policy: RequestPolicy,*,chat_history: list[WorkflowCopilotChatHistoryMessage],+ user_message: str,) -> bool:if not _last_assistant_message_was_saved_credential_question(chat_history):return Falsereturn (policy.credential_input_kind in ("none", "credential_name")and policy.clarification_reason == "credential_name_unresolved"- and not _has_resolvable_credential_scope(policy)+ and not _has_resolvable_credential_scope(policy, user_message))@@ -5017,6 +5019,7 @@ async def build_request_policy(and not _can_defer_unresolved_credential_name_for_draft(policy,global_llm_context=global_llm_context,+ user_message=user_message,)):policy.requires_user_clarification = True@@ -5028,6 +5031,7 @@ async def build_request_policy(if _should_defer_repeated_unresolved_credential_question(policy,chat_history=chat_history,+ user_message=user_message,):policy.requires_user_clarification = Falsepolicy.allow_update_workflow = Truediff --git a/tests/unit/test_copilot_request_policy_workflow_credentials.py b/tests/unit/test_copilot_request_policy_workflow_credentials.pyindex 9b56efccb..b926a2e29 100644--- a/tests/unit/test_copilot_request_policy_workflow_credentials.py+++ b/tests/unit/test_copilot_request_policy_workflow_credentials.py@@ -1,6 +1,7 @@from __future__ import annotationsimport textwrap+from datetime import UTC, datetimefrom types import SimpleNamespacefrom unittest.mock import AsyncMock, patch@@ -16,18 +17,25 @@ from skyvern.forge.sdk.copilot.request_policy import (_AMBIGUOUS_URL_CREDENTIAL_QUESTION,_LOGIN_CREDENTIAL_QUESTION,_SAVED_CREDENTIAL_NAME_QUESTION,+ _SAVED_CREDENTIAL_NAME_QUESTION_STABLE_PREFIX,_STORED_CREDENTIAL_URL_QUESTION,CREDENTIAL_DEFERRED_DRAFT_REASONS,CREDENTIAL_PROMPT_CLARIFICATION_REASONS,RequestPolicy,+ _can_defer_unresolved_credential_name_for_draft,_classification_from_raw,_resolve_credentials,+ _should_defer_repeated_unresolved_credential_question,_workflow_credential_inputs_unbound,build_request_policy,credential_prompt_reason,)from skyvern.forge.sdk.copilot.tools.credentials import _credential_run_approval_errorfrom skyvern.forge.sdk.schemas.credentials import CredentialType+from skyvern.forge.sdk.schemas.workflow_copilot import (+ WorkflowCopilotChatHistoryMessage,+ WorkflowCopilotChatSender,+)def _yaml(body: str) -> str:@@ -570,6 +578,47 @@ async def _resolve_direct(return load_mock, by_ids_mock+ "user_message",+ ["Use credential ID cred_current.", "Use the saved credential named current-login."],+)+def test_draft_deferral_recognizes_current_turn_credential_scope(user_message: str) -> None:+ policy = RequestPolicy(+ credential_input_kind="none",+ clarification_reason="credential_name_unresolved",+ )++ assert _can_defer_unresolved_credential_name_for_draft(+ policy,+ global_llm_context="",+ user_message=user_message,+ )+++ "user_message",+ ["Use credential ID cred_current.", "Use the saved credential named current-login."],+)+def test_repeated_question_deferral_preserves_current_turn_credential_scope(user_message: str) -> None:+ policy = RequestPolicy(+ credential_input_kind="none",+ clarification_reason="credential_name_unresolved",+ )+ history = [+ WorkflowCopilotChatHistoryMessage(+ sender=WorkflowCopilotChatSender.AI,+ content=_SAVED_CREDENTIAL_NAME_QUESTION_STABLE_PREFIX,+ created_at=datetime.now(UTC),+ )+ ]++ assert not _should_defer_repeated_unresolved_credential_question(+ policy,+ chat_history=history,+ user_message=user_message,+ )++@pytest.mark.asyncioasync def test_name_miss_does_not_advance_to_classifier_only_url() -> None:url_credential = _cred("url-login", "cred_url", tested_url="https://portal.example.com/login")