Skip to content

Automate browser based workflows with AI

fix(SKY-9550): copilot: feasibility-gate inherits prior turn on bare-value continuations (#5853)

Andrew Neilson436e90820681
diff --git a/skyvern/forge/prompts/skyvern/feasibility-gate.j2 b/skyvern/forge/prompts/skyvern/feasibility-gate.j2
index 3dc4892b7..8c1071fbd 100644
--- a/skyvern/forge/prompts/skyvern/feasibility-gate.j2
+++ b/skyvern/forge/prompts/skyvern/feasibility-gate.j2
@@ -11,7 +11,7 @@ Your default is `proceed`. The main copilot can inspect the live page, iterate,
Refinements and corrections:
-The user's latest message may be a refinement, correction, or continuation of an earlier request rather than a fresh standalone ask. Short utterances like "I meant Fulham", "use Z instead", "change the URL to Y", "actually 5 of them", or "it's the away game" inherit the website, the action, and the surrounding framing from the prior turn. Resolve the latest message against `chat_history` and `workflow_yaml` first, then evaluate feasibility on the resolved request. NEVER return `ask_clarification` to re-ask for information already established earlier in the session — the website, the action, and the framing are all valid context to inherit.
+The user's latest message may be a refinement, correction, or continuation of an earlier request rather than a fresh standalone ask. This covers both **corrective utterances** with explicit framing words ("I meant Fulham", "use Z instead", "change the URL to Y", "actually 5 of them", "it's the away game") and **bare-value replies** that only make sense relative to a prior turn — a slot-fill carrying just the value the prior turn was about (an opaque token, a credential or key-vault reference, an id, a number). In both cases, the latest message inherits everything the prior turn established: the website, the action, the block or field name, the slot's purpose, and the surrounding framing. Resolve the latest message against `chat_history` and `workflow_yaml` first, then evaluate feasibility on the resolved request. NEVER return `ask_clarification` to re-ask for context the latest message is plainly answering — if a prior turn named a block, a field, a goal, or a target, that information is already on record and is not "missing" from the latest message.
When a concrete URL is present in the latest message OR in `workflow_yaml`, default even harder toward `proceed`. Do NOT return `ask_clarification` for any of these reasons when a URL is established:
- A word or phrase in the goal is ambiguous ("level", "latest", "best", "right one", "most popular") — the main copilot will resolve it by reading the page.
diff --git a/tests/unit/test_copilot_feasibility_gate.py b/tests/unit/test_copilot_feasibility_gate.py
index dc3195658..a3d11d0ca 100644
--- a/tests/unit/test_copilot_feasibility_gate.py
+++ b/tests/unit/test_copilot_feasibility_gate.py
@@ -8,14 +8,21 @@ exceptions, and malformed classifier output must all fall through to
from __future__ import annotations
import asyncio
+from datetime import datetime, timezone
import pytest
+from skyvern.forge.prompts import prompt_engine
+from skyvern.forge.sdk.copilot.agent import _format_chat_history
from skyvern.forge.sdk.copilot.feasibility_gate import (
FeasibilityVerdict,
_coerce_verdict,
run_feasibility_gate,
)
+from skyvern.forge.sdk.schemas.workflow_copilot import (
+ WorkflowCopilotChatHistoryMessage,
+ WorkflowCopilotChatSender,
+)
# ---------------------------------------------------------------------------
# _coerce_verdict — input shapes the classifier might return
@@ -303,15 +310,19 @@ def test_feasibility_verdict_dataclass() -> None:
# ---------------------------------------------------------------------------
-def _render_feasibility_prompt() -> str:
- from skyvern.forge.prompts import prompt_engine
-
+def _render_feasibility_prompt(
+ *,
+ user_message: str = "I meant the other one",
+ workflow_yaml: str = "name: example_workflow",
+ chat_history: str = "USER: place an order\nAI: tested, no result",
+ global_llm_context: str = "",
+) -> str:
return prompt_engine.load_prompt(
template="feasibility-gate",
- user_message="I meant the other one",
- workflow_yaml="name: example_workflow",
- chat_history="USER: place an order\nAI: tested, no result",
- global_llm_context="",
+ user_message=user_message,
+ workflow_yaml=workflow_yaml,
+ chat_history=chat_history,
+ global_llm_context=global_llm_context,
)
@@ -326,3 +337,41 @@ def test_prompt_does_not_revert_to_single_request_framing() -> None:
prompt = _render_feasibility_prompt()
assert "single user request" not in prompt
assert "before any navigation happens" not in prompt
+
+
+def test_prompt_handles_bare_value_continuation() -> None:
+ prompt = _render_feasibility_prompt()
+ assert "bare-value replies" in prompt
+ assert "slot-fill" in prompt
+
+
+def test_prompt_lists_inheritable_block_and_field_context() -> None:
+ prompt = _render_feasibility_prompt()
+ assert "block or field name" in prompt
+ assert "named a block" in prompt
+
+
+def test_prompt_carries_prior_turns_in_chat_history_section() -> None:
+ now = datetime.now(timezone.utc)
+ history_messages = [
+ WorkflowCopilotChatHistoryMessage(
+ sender=WorkflowCopilotChatSender.USER,
+ content="do you see lookup_record, the crawler isn't using the search/filter tool I'm trying to point it at",
+ created_at=now,
+ ),
+ WorkflowCopilotChatHistoryMessage(
+ sender=WorkflowCopilotChatSender.USER,
+ content="record-aaaa-bbbb-cccc-user",
+ created_at=now,
+ ),
+ ]
+ prompt = _render_feasibility_prompt(
+ user_message="record-aaaa-bbbb-cccc-pass",
+ workflow_yaml="",
+ chat_history=_format_chat_history(history_messages),
+ )
+ user_section = prompt[prompt.index("### user_message") : prompt.index("### workflow_yaml")]
+ history_section = prompt[prompt.index("### chat_history") : prompt.index("### global_llm_context")]
+ assert "record-aaaa-bbbb-cccc-pass" in user_section
+ assert "lookup_record" in history_section
+ assert "record-aaaa-bbbb-cccc-user" in history_section