Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
Stop replacing Copilot answers that show an example block when nothing was proposed (SKY-17769) (#8819)
Andrew Neilson8c93f8d27276
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.pyindex 26eeb6c23..19144371d 100644--- a/skyvern/forge/sdk/copilot/agent.py+++ b/skyvern/forge/sdk/copilot/agent.py@@ -2809,10 +2809,7 @@ _INTERNAL_VOCAB_LEAK_REPLY = ("Tell me what you'd like to do next — describe the page action, data to collect, sign-in step, ""or check you want, and I'll translate that into a supported workflow update.")-_BLOCK_YAML_IN_REPLY_REWRITE_NO_PROPOSAL = (- "I drafted a change to the workflow but haven't applied it yet. Want me to update the workflow now?"-)-_BLOCK_YAML_IN_REPLY_REWRITE_WITH_PROPOSAL = "I made the change you described to the workflow."+_BLOCK_YAML_IN_REPLY_REWRITE = "I made the change you described to the workflow."_PROPOSAL_ACCEPT_UI_ACTION_RE = re.compile(r"\b(?:accept|always\s+accept)\b", re.IGNORECASE)_PROPOSAL_REJECT_UI_ACTION_RE = re.compile(r"\b(?:reject|discard)\b", re.IGNORECASE)@@ -4086,11 +4083,7 @@ async def _translate_to_agent_result(soft_rewrite_reasons.append(_residual_vocab_reason)output_policy_verdict.remove(_residual_vocab_reason)if OutputPolicyReason.WORKFLOW_YAML_IN_REPLY in output_policy_verdict.reason_codes:- user_response = (- _BLOCK_YAML_IN_REPLY_REWRITE_WITH_PROPOSAL- if last_workflow is not None- else _BLOCK_YAML_IN_REPLY_REWRITE_NO_PROPOSAL- )+ user_response = _BLOCK_YAML_IN_REPLY_REWRITEsoft_rewrite_reasons.append(OutputPolicyReason.WORKFLOW_YAML_IN_REPLY)output_policy_verdict.remove(OutputPolicyReason.WORKFLOW_YAML_IN_REPLY)final_output_kind = (diff --git a/skyvern/forge/sdk/copilot/output_policy.py b/skyvern/forge/sdk/copilot/output_policy.pyindex aa72ec7c6..d8609c3bb 100644--- a/skyvern/forge/sdk/copilot/output_policy.py+++ b/skyvern/forge/sdk/copilot/output_policy.py@@ -392,7 +392,12 @@ def evaluate_output_policy(verdict.add(OutputPolicyReason.INTERNAL_CLASSIFIER_VOCAB_LEAK)if response_type in _USER_VISIBLE_REPLY_TYPES and _contains_self_prescriptive_phrase(user_response):verdict.add(OutputPolicyReason.SELF_PRESCRIPTIVE_PHRASE_LEAK)- if response_type in ("REPLY", "ASK_QUESTION") and looks_like_workflow_yaml_in_chat(user_response):+ # Without a proposal, block YAML in a reply is usually an example answering a question.+ if (+ has_workflow_proposal+ and response_type in ("REPLY", "ASK_QUESTION")+ and looks_like_workflow_yaml_in_chat(user_response)+ ):verdict.add(OutputPolicyReason.WORKFLOW_YAML_IN_REPLY)if isinstance(request_policy, RequestPolicy):diff --git a/tests/unit/test_copilot_output_policy.py b/tests/unit/test_copilot_output_policy.pyindex 0e7b0b28f..4e7522aba 100644--- a/tests/unit/test_copilot_output_policy.py+++ b/tests/unit/test_copilot_output_policy.py@@ -767,7 +767,7 @@ def test_flags_block_yaml_pasted_into_user_response() -> None:request_policy=_policy(),response_type="REPLY",user_response=user_response,- has_workflow_proposal=False,+ has_workflow_proposal=True,)assert not verdict.allowed@@ -786,7 +786,7 @@ def test_block_yaml_in_reply_is_not_hard_blocking() -> None:"label: submit_form\n""```\n"),- has_workflow_proposal=False,+ has_workflow_proposal=True,)assert OutputPolicyReason.WORKFLOW_YAML_IN_REPLY in verdict.reason_codes@@ -2313,40 +2313,34 @@ def test_yaml_block_scalar_standard_term_does_not_hard_block_ask_question() -> Nassert OutputPolicyReason.INTERNAL_BLOCK_TAXONOMY_LEAK not in verdict.reason_codes-def test_translate_to_agent_result_rewrites_block_yaml_pasted_in_reply() -> None:- leak = (- "I've now updated the workflow to also accept the form's URL as a parameter, named `form_url`. "- "Here's how the block now looks:\n\n"- " - label: navigate_and_fill_form\n"- " block_type: navigation\n"- " navigation_goal: Fill the abuse form.\n"- ' url: "{{ form_url }}"\n'- " parameter_keys:\n"- " - name\n"- " - form_url\n"+def test_translate_to_agent_result_keeps_a_block_example_when_no_workflow_was_proposed() -> None:+ answer = (+ "A loop block runs the blocks inside it once for each item in a list. To visit a list of URLs:\n\n"+ "```yaml\n"+ "- block_type: for_loop\n"+ " label: visit_each_url\n"+ " loop_over_parameter_key: urls\n"+ " loop_blocks:\n"+ " - block_type: goto_url\n"+ " label: open_url\n"+ ' url: "{{ visit_each_url.current_value }}"\n'+ "```\n")- result = _fake_run_result({"type": "REPLY", "user_response": leak})+ result = _fake_run_result({"type": "REPLY", "user_response": answer})- with patch("skyvern.forge.sdk.copilot.agent.LOG.info") as log_info:- agent_result = asyncio.run(- agent_module._translate_to_agent_result(- result,- _ctx(),- global_llm_context=None,- chat_request=_chat_request(),- organization_id="org-1",- )+ agent_result = asyncio.run(+ agent_module._translate_to_agent_result(+ result,+ _ctx(),+ global_llm_context=None,+ chat_request=_chat_request(),+ organization_id="org-1",)+ )- assert "block_type" not in agent_result.user_response- assert "navigation_goal" not in agent_result.user_response- assert "parameter_keys" not in agent_result.user_response- assert "haven't applied it yet" in agent_result.user_response+ assert agent_result.user_response == answerassert agent_result.updated_workflow is None- final_log = next(call for call in log_info.call_args_list if call.args[0] == "copilot output policy final verdict")- assert final_log.kwargs["soft_rewrite_reason_codes"] == ["workflow_yaml_in_reply"]- assert final_log.kwargs["contained_failure"] is True- assert agent_result.output_policy_diagnostics["soft_rewrite_reason_codes"] == ["workflow_yaml_in_reply"]+ assert agent_result.output_policy_diagnostics["soft_rewrite_reason_codes"] == []assert agent_result.output_policy_diagnostics["final_output_policy_allowed"] is True@@ -2381,7 +2375,6 @@ def test_translate_to_agent_result_rewrites_block_yaml_when_workflow_attached()assert "block_type" not in agent_result.user_responseassert "navigation_goal" not in agent_result.user_responseassert "parameter_keys" not in agent_result.user_response- assert "haven't applied it yet" not in agent_result.user_responseassert "made the change" in agent_result.user_responseassert agent_result.updated_workflow is workflow