Automate browser based workflows with AI
Python aiapiautomationbrowserbrowser-automationcomputergptllmplaywrightpowerautomatepuppeteerpythonrpaseleniumvisionworkflow
SKY-12070 mint requested-output criteria for quoted fields (#7227)
Andrew Neilson65d28b166694
diff --git a/skyvern/forge/sdk/copilot/request_policy.py b/skyvern/forge/sdk/copilot/request_policy.pyindex 454e950a6..c23579c81 100644--- a/skyvern/forge/sdk/copilot/request_policy.py+++ b/skyvern/forge/sdk/copilot/request_policy.py@@ -1020,6 +1020,7 @@ def _clean_requested_output_candidate(segment: str, aliases: dict[str, str] | Noif not candidate:return None+ candidate = _normalize_named_output_field_delimiter(candidate)named_field = _OUTPUT_NAMED_FIELD_RE.search(candidate)if named_field is not None:return named_field.group(1)@@ -1093,6 +1094,27 @@ def _clean_requested_output_candidate(segment: str, aliases: dict[str, str] | Noreturn " ".join(phrase_words)+def _normalize_named_output_field_delimiter(candidate: str) -> str:+ lowered = candidate.casefold()+ for anchor in (" named", " called"):+ token_start = lowered.find(anchor)+ if token_start == -1:+ continue+ token_start += len(anchor)+ while token_start < len(candidate) and candidate[token_start].isspace():+ token_start += 1+ if token_start >= len(candidate) or candidate[token_start] not in "'\"`":+ continue+ quote = candidate[token_start]+ token_end = candidate.find(quote, token_start + 1)+ if token_end == -1:+ continue+ field_name = candidate[token_start + 1 : token_end]+ if _OUTPUT_EXPLICIT_FIELD_KEY_RE.fullmatch(field_name):+ return f"{candidate[:token_start]}{field_name}{candidate[token_end + 1 :]}"+ return candidate++def _matched_alias_phrase(candidate: str, alias_key: str) -> str | None:alias_words = alias_key.split()if not alias_words:diff --git a/tests/unit/test_copilot_request_policy_completion_criteria.py b/tests/unit/test_copilot_request_policy_completion_criteria.pyindex dbe316144..cdd284d58 100644--- a/tests/unit/test_copilot_request_policy_completion_criteria.py+++ b/tests/unit/test_copilot_request_policy_completion_criteria.py@@ -287,6 +287,40 @@ async def test_lowercase_record_id_is_augmented_as_requested_output() -> None:assert policy.completion_criteria[0].output_path == "output.record_id"+ "field_token",+ [+ pytest.param("`field_name`", id="backtick"),+ pytest.param('"field_name"', id="double_quote"),+ pytest.param("'field_name'", id="single_quote"),+ ],+)+async def test_delimited_named_output_field_is_augmented_as_requested_output(field_token: str) -> None:+ policy = await _policy_for_message(+ f"Return a final record with output field named {field_token}.",+ [],+ )++ criteria = _criteria_for_path(policy, "output.field_name")+ trace = policy.to_trace_data()++ assert len(criteria) == 1+ assert criteria[0].output_path == "output.field_name"+ assert trace["requested_output_criteria_count"] == 1+++async def test_delimited_named_output_field_dedupes_with_bare_field() -> None:+ policy = await _policy_for_message(+ "Return a final record with output field named field_name and output field named `field_name`.",+ [],+ )++ assert len(_criteria_for_path(policy, "output.field_name")) == 1+ assert policy.to_trace_data()["requested_output_criteria_count"] == 1++@pytest.mark.asyncioasync def test_leading_output_verb_does_not_enter_requested_output_slug() -> None:policy = await _policy_for_message(@@ -1288,6 +1322,97 @@ def test_requested_output_canonicalization_preserves_marker_for_approved_downloaassert criteria[0].deliverable_kind == "registered_download"+async def test_classifier_typed_download_preserves_registered_download_requested_output() -> None:+ policy = await _policy_for_message(+ "Build a workflow that downloads the May 2026 bill.",+ [+ {+ "outcome": "The requested download artifact ids include the May 2026 bill.",+ "output_path": "output.downloaded_file_artifact_ids",+ "expected_output_value": "May 2026",+ "expected_output_shape": "date",+ "requested_output_evidence_source": "registered_artifact_content",+ "deliverable_kind": "registered_download",+ }+ ],+ )++ criteria = _requested_output_subset(policy, {"output.downloaded_file_artifact_ids"})+ trace = policy.to_trace_data()++ assert len(criteria) == 1+ assert criteria[0].output_path == "output.downloaded_file_artifact_ids"+ assert criteria[0].deliverable_kind == "registered_download"+ assert criteria[0].expected_output_value == "May 2026"+ assert criteria[0].expected_output_shape == "date"+ assert criteria[0].requested_output_evidence_source == "registered_artifact_content"+ assert trace["requested_output_criteria_count"] == 1+++async def test_download_prose_without_typed_classifier_output_does_not_mint_requested_output() -> None:+ policy = await _policy_for_message(+ "Build a workflow that downloads the bill for May 2026.",+ [],+ )++ criteria = _requested_output_subset(policy, {"output.downloaded_file_artifact_ids"})++ assert criteria == []+ assert policy.to_trace_data()["requested_output_criteria_count"] == 0+++async def test_explicit_download_alias_can_mint_registered_download_requested_output() -> None:+ policy = await _policy_for_message(+ "Build a workflow that returns the May 2026 download artifact.",+ [+ {+ "outcome": "The returned record includes the download artifact.",+ "output_path": "output.downloaded_file_artifact_ids",+ "expected_output_value": "May 2026",+ "expected_output_shape": "date",+ "requested_output_evidence_source": "registered_artifact_content",+ "deliverable_kind": "registered_download",+ }+ ],+ config=CopilotConfig(+ requested_output_path_aliases={"download artifact": "output.downloaded_file_artifact_ids"}+ ),+ )++ criteria = _requested_output_subset(policy, {"output.downloaded_file_artifact_ids"})++ assert len(criteria) == 1+ assert criteria[0].expected_output_value == "May 2026"+ assert criteria[0].expected_output_shape == "date"+ assert criteria[0].requested_output_evidence_source == "registered_artifact_content"+ assert criteria[0].deliverable_kind == "registered_download"+++async def test_date_qualified_download_preserves_classifier_typed_value_and_shape() -> None:+ policy = await _policy_for_message(+ "Build a workflow that downloads the May 2026 bill.",+ [+ {+ "outcome": "The requested download is returned.",+ "output_path": "output.downloaded_file_artifact_ids",+ "expected_output_value": "April 2026",+ "expected_output_shape": "date",+ "deliverable_kind": "registered_download",+ }+ ],+ )++ criteria = _requested_output_subset(policy, {"output.downloaded_file_artifact_ids"})++ assert len(criteria) == 1+ assert criteria[0].expected_output_value == "April 2026"+ assert criteria[0].expected_output_shape == "date"++@pytest.mark.parametrize(("criterion_kwargs", "expected"),[