Skip to content

Automate browser based workflows with AI

SKY-11192 stop under-claiming verified Copilot output (#6710)

Andrew Neilson79b6878e3513
diff --git a/skyvern/forge/sdk/copilot/agent.py b/skyvern/forge/sdk/copilot/agent.py
index 11e662a83..9f65cf888 100644
--- a/skyvern/forge/sdk/copilot/agent.py
+++ b/skyvern/forge/sdk/copilot/agent.py
@@ -853,11 +853,16 @@ def _rewrite_failed_test_response(user_response: str, ctx: CopilotContext) -> st
block_count = ctx.last_update_block_count if isinstance(ctx.last_update_block_count, int) else None
positive_block_count = block_count if block_count is not None and block_count > 0 else None
- if outcome_fully_verified(ctx) and has_keepable_draft and positive_block_count is not None:
- block_word = "block" if positive_block_count == 1 else "blocks"
+ if outcome_fully_verified(ctx) and has_keepable_draft:
+ if positive_block_count is not None:
+ block_word = "block" if positive_block_count == 1 else "blocks"
+ return (
+ f"I created a workflow with {positive_block_count} {block_word} and verified the requested "
+ "outcome from workflow run evidence and the current browser page. The workflow is ready to review."
+ )
return (
- f"I created a workflow with {positive_block_count} {block_word} and verified the requested "
- "outcome from the current browser page after the run. The workflow is ready to review."
+ "I built the workflow and verified the requested outcome from workflow run evidence and the current "
+ "browser page. The workflow is ready to review."
)
policy = ctx.request_policy if isinstance(ctx.request_policy, RequestPolicy) else None
@@ -2320,7 +2325,9 @@ async def _translate_to_agent_result(
user_response = _rewrite_failed_test_response(str(user_response), ctx)
verified_workflow, verified_yaml = _verified_workflow_or_none(ctx)
# Default-true preserves backwards-compat with stale prompts and missing fields.
- agent_admits_incomplete = _is_explicit_false(action_data.get("goal_reached"))
+ agent_admits_incomplete = _is_explicit_false(
+ action_data.get("goal_reached")
+ ) and not verified_goal_claim_authorized(ctx)
typed_outcome_reply = _render_typed_run_outcome_reply(
ctx,
response_type=resp_type,
diff --git a/skyvern/forge/sdk/copilot/tools/run_execution.py b/skyvern/forge/sdk/copilot/tools/run_execution.py
index 24206213c..aeda447af 100644
--- a/skyvern/forge/sdk/copilot/tools/run_execution.py
+++ b/skyvern/forge/sdk/copilot/tools/run_execution.py
@@ -1916,9 +1916,7 @@ def _adjudicated_run_outcome(
_outcome_unverified_reason(copilot_ctx, completion_verification)
),
)
- if copilot_ctx.last_full_workflow_test_ok:
- return RecordedRunOutcome(verdict="demonstrated")
- return RecordedRunOutcome(verdict="not_evaluated")
+ return RecordedRunOutcome(verdict="demonstrated")
if copilot_ctx.last_test_suspicious_success:
return RecordedRunOutcome(
verdict="not_demonstrated",
diff --git a/tests/unit/test_copilot_agent_helpers.py b/tests/unit/test_copilot_agent_helpers.py
index c40eac901..c6ee768dc 100644
--- a/tests/unit/test_copilot_agent_helpers.py
+++ b/tests/unit/test_copilot_agent_helpers.py
@@ -1902,7 +1902,7 @@ workflow_definition:
assert agent_result.workflow_yaml == "title: drafted"
assert agent_result.proposal_disposition == "review_untested"
- def test_demonstrated_recorded_outcome_overrides_goal_reached_false_underclaim(self) -> None:
+ def test_goal_reached_false_cannot_underclaim_verified_outcome(self) -> None:
from skyvern.forge.sdk.copilot.completion_verification import CompletionVerificationResult, CriterionVerdict
wf = SimpleNamespace(name="verified")
@@ -1910,7 +1910,7 @@ workflow_definition:
last_workflow=wf,
last_workflow_yaml="title: verified",
last_test_ok=True,
- last_full_workflow_test_ok=True,
+ last_full_workflow_test_ok=False,
last_update_block_count=4,
last_run_outcome=RecordedRunOutcome(verdict="demonstrated", workflow_run_id="wr_secret"),
completion_verification_result=CompletionVerificationResult(
@@ -1922,7 +1922,7 @@ workflow_definition:
result = _fake_run_result(
{
"type": "REPLY",
- "user_response": "I drafted this but did not test it end-to-end.",
+ "user_response": "I drafted the workflow, but it has not been tested end-to-end.",
"goal_reached": False,
}
)
@@ -1936,10 +1936,14 @@ workflow_definition:
assert agent_result.updated_workflow is wf
assert agent_result.workflow_yaml == "title: verified"
assert agent_result.proposal_disposition == "auto_applicable"
+ assert "draft" not in agent_result.user_response.lower()
+ assert "not been tested" not in agent_result.user_response.lower()
+ assert "tested end-to-end" not in agent_result.user_response.lower()
assert "created and tested" in agent_result.user_response.lower()
assert "demonstrated the requested outcome" in agent_result.user_response.lower()
- assert "did not test" not in agent_result.user_response.lower()
assert "wr_secret" not in agent_result.user_response
+ assert agent_result.narrative_payload is not None
+ assert agent_result.narrative_payload["verifiedSuccess"] is True
def test_demonstrated_recorded_outcome_overrides_misleading_free_text(self) -> None:
from skyvern.forge.sdk.copilot.completion_verification import CompletionVerificationResult, CriterionVerdict
diff --git a/tests/unit/test_copilot_run_outcome_event.py b/tests/unit/test_copilot_run_outcome_event.py
index a68724719..61b4735c1 100644
--- a/tests/unit/test_copilot_run_outcome_event.py
+++ b/tests/unit/test_copilot_run_outcome_event.py
@@ -230,6 +230,34 @@ async def test_satisfied_adjudication_emits_demonstrated(monkeypatch: pytest.Mon
assert ctx.last_full_workflow_test_ok is True
+async def test_satisfied_adjudication_emits_demonstrated_with_unverified_prefix(
+ monkeypatch: pytest.MonkeyPatch,
+) -> None:
+ result = _clean_run_result()
+ ctx = _ctx(result["data"]["blocks"])
+ ctx.last_workflow = SimpleNamespace(
+ workflow_definition=SimpleNamespace(
+ blocks=[
+ SimpleNamespace(block_type="code", label="search_registry_person"),
+ SimpleNamespace(block_type="code", label="review_results"),
+ ]
+ )
+ )
+
+ async def _stub_verification(*args: Any, **kwargs: Any) -> CompletionVerificationResult:
+ return _evaluated(satisfied=True)
+
+ monkeypatch.setattr(run_execution, "_maybe_run_completion_verification", _stub_verification)
+ await _verify_and_record_run_blocks_result(ctx, result, time.monotonic())
+
+ frames = _run_outcome_frames(ctx.stream) # type: ignore[arg-type]
+ assert [frame.verdict for frame in frames] == ["evaluating", "demonstrated"]
+ assert frames[-1].reason_code is None
+ assert ctx.last_full_workflow_test_ok is False
+ assert ctx.last_run_outcome == RecordedRunOutcome(verdict="demonstrated", workflow_run_id="wr_test")
+
+
@pytest.mark.asyncio
async def test_verification_skipped_emits_not_evaluated(monkeypatch: pytest.MonkeyPatch) -> None:
result = _clean_run_result()