Skip to content

Automate browser based workflows with AI

fix: prevent country code duplication in phone format checker (SKY-8395) (#5125)

LawyZheng9de05b2c03f8
diff --git a/.github/actions/setup-ai-env/uv-sync.sh b/.github/actions/setup-ai-env/uv-sync.sh
new file mode 100755
index 000000000..6de0eb111
--- /dev/null
+++ b/.github/actions/setup-ai-env/uv-sync.sh
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+set -euo pipefail
+
+# Build uv sync command with optional --group flags from UV_SYNC_GROUPS env var.
+# UV_SYNC_GROUPS: comma-separated list of groups (whitespace trimmed, empty entries ignored).
+
+args=(sync)
+
+if [[ -n "${UV_SYNC_GROUPS:-}" ]]; then
+ IFS=',' read -ra raw_groups <<< "$UV_SYNC_GROUPS"
+ for group in "${raw_groups[@]}"; do
+ # Trim leading/trailing whitespace
+ group="${group#"${group%%[![:space:]]*}"}"
+ group="${group%"${group##*[![:space:]]}"}"
+ if [[ -n "$group" ]]; then
+ args+=(--group "$group")
+ fi
+ done
+fi
+
+uv "${args[@]}"
diff --git a/skyvern/core/script_generations/script_skyvern_page.py b/skyvern/core/script_generations/script_skyvern_page.py
index 6af13799b..65fdb91fe 100644
--- a/skyvern/core/script_generations/script_skyvern_page.py
+++ b/skyvern/core/script_generations/script_skyvern_page.py
@@ -759,40 +759,6 @@ class ScriptSkyvernPage(SkyvernPage):
)
return ""
- async def _auto_solve_captchas(self) -> bool:
- """Proactively detect and solve captchas after page load.
- Returns True if a captcha was detected and solved."""
- context = skyvern_context.current()
- is_script = context and context.script_mode
- try:
- from cloud.webeye.utils.captcha import cloudflare_detect_and_wait_for_resolve
-
- # Wait for CapMonster extension to inject its addon div into the DOM.
- # The extension needs a moment after page load to detect any Turnstile
- # widget and inject its overlay. We use wait_for with a short timeout
- # so non-captcha pages only add ~5s latency (acceptable since code mode
- # saves minutes vs agent mode).
- capmonster_div = self.page.locator('div[class~="cm-addon-turnstile"]')
- try:
- await capmonster_div.wait_for(state="attached", timeout=5_000)
- except Exception:
- # No CapMonster div appeared β€” no Cloudflare captcha on this page
- return False
-
- if is_script:
- print(" πŸ”“ Cloudflare captcha detected, solving...")
-
- detected, solved = await cloudflare_detect_and_wait_for_resolve(self.page, timeout=90)
- if detected and is_script:
- print(f" {'βœ“' if solved else 'βœ—'} Cloudflare captcha {'solved' if solved else 'not solved'}")
- return detected and solved
- except ImportError:
- # cloud module not available (open source)
- return False
- except Exception:
- LOG.warning("Auto captcha solve failed", exc_info=True)
- return False
-
async def goto(self, url: str, **kwargs: Any) -> None:
url = render_template(url)
url = prepend_scheme_and_validate_url(url)
@@ -838,7 +804,7 @@ class ScriptSkyvernPage(SkyvernPage):
context = skyvern_context.current()
if not context or not context.organization_id or not context.task_id or not context.step_id:
# Fallback: solve directly without DB context
- await self._auto_solve_captchas()
+ await app.AGENT_FUNCTION.auto_solve_captchas(self.page)
return None
task = await app.DATABASE.get_task(context.task_id, context.organization_id)
diff --git a/skyvern/forge/agent_functions.py b/skyvern/forge/agent_functions.py
index 22fce7ea1..1b8bbdd4a 100644
--- a/skyvern/forge/agent_functions.py
+++ b/skyvern/forge/agent_functions.py
@@ -489,6 +489,12 @@ class AgentFunction:
async def post_cache_step_execution(self, task: Task, step: Step) -> None:
return
+ async def auto_solve_captchas(self, page: Page) -> bool:
+ """Proactively detect and solve captchas on the current page.
+ Returns True if a captcha was detected and solved.
+ Cloud override provides actual solving; OSS base is a no-op."""
+ return False
+
async def generate_async_operations(
self,
organization: Organization,
diff --git a/skyvern/forge/prompts/skyvern/check-phone-number-format.j2 b/skyvern/forge/prompts/skyvern/check-phone-number-format.j2
index ecc6319ef..066fdebfb 100644
--- a/skyvern/forge/prompts/skyvern/check-phone-number-format.j2
+++ b/skyvern/forge/prompts/skyvern/check-phone-number-format.j2
@@ -1,10 +1,11 @@
You need to help checking two goals:
-1. Based on the context/intention, check whether the current value is used to input as a phone number
+1. Based on the context/intention, check whether the current value is used to input as a phone number
2. If the current value is a phone number, check whether the format of the phone number matches the required format based on the user's goals, user details, and HTML elements.
There are several checkpoints to verify the format of the phone number:
+- Whether the country code is already present near the phone number field (as a dropdown, input, or displayed text). If so, do NOT include the country code in the recommended number.
- Whether the phone number should add hyphen.
-- Whether the phone number should add country code.
+- Whether the phone number should add country code. Only add if there is NO separate country code element on the page.
- Whether the phone number should add space between the country code and the area code.
MAKE SURE YOU OUTPUT VALID JSON. No text before or after JSON, no trailing commas, no comments (//), no unnecessary quotes, etc.
@@ -16,7 +17,7 @@ Reply in JSON format with the following keys:
"thought": str, // Think step by step. Describe your thought about how you come up with the phone_number_format. Use information you see on the site to explain.
"phone_number_format": str, // Think step by step. The format of the phone number required on the page according to HTML elements. Null if is_phone_number_input is False.
"is_current_format_correct": bool, // True if the current phone number format is matching the required format. Null if is_phone_number_input is False.
-"recommended_phone_number": str, // If is_current_format_correct is True or is_phone_number_input is False, return null. Otherwise, return the recommended phone number with the correct format.
+"recommended_phone_number": str, // If is_current_format_correct is True or is_phone_number_input is False, return null. Otherwise, return the recommended phone number with the correct format. Exclude country code if handled by a separate element.
}
Context/Intention
diff --git a/skyvern/forge/prompts/skyvern/task_v2.j2 b/skyvern/forge/prompts/skyvern/task_v2.j2
index 27bf8d3a4..a4fc6894f 100644
--- a/skyvern/forge/prompts/skyvern/task_v2.j2
+++ b/skyvern/forge/prompts/skyvern/task_v2.j2
@@ -6,7 +6,6 @@ You have access to the following task types to take actions:
- loop: this task can be used to generate a list of planning sessions like this. When to use a loop task? Use loop when there are multiple parallel tasks you can do with the same goal. Each task in the loop has the same goal but with different objects/values/targets/variables. Use loop task when it's in a "breadth first search" situation where you can go through a list of values and execute the same task for each value. Examples:
- When the goal is "Open up to 10 links from an ecomm search result page, and extract information like the price of each product.", loop task should be used to iterate through a list of links or URLs. In each iteration of the loop, the task will go to the linked page and trigger another planning session with the goal of extracting price information of the product
- When the goal is "download 5 documents found on a page", loop task should be used to iterate through a list of document names. Each document will trigger another planning session to download the relative document
-{% if enable_termination %}
You may also determine that the user goal is IMPOSSIBLE to achieve. Use termination ONLY when there is CLEAR, EXPLICIT, and UNAMBIGUOUS evidence that the goal cannot ever be accomplished. Be very conservative - when in doubt, continue trying.
@@ -32,7 +31,6 @@ Do NOT terminate when:
- The page structure is different than expected but might still contain the needed functionality
When in doubt, DO NOT terminate. Try an alternative approach instead.
-{% endif %}
MAKE SURE YOU OUTPUT VALID JSON. No text before or after JSON, no trailing commas, no comments (//), no unnecessary quotes, etc.
@@ -43,14 +41,12 @@ Reply in JSON format with the following keys:
"require_extraction": bool, // True if the user goal requires information extraction. False otherwise.
"task_history_information": str, // Think step by step. In task history, what information has been collected that's helpful and relevant to the user goal, and what information is missing if any.
"information_extracted": optional[bool], // True if the needed information has been extracted. False if the needed information has not been extracted. If task history has no "extract" type, that means no data extraction has happened, return false. Null if the user goal does not require information extraction.
- "thoughts": str, // Think step by step. What has been done so far and what is the next reasonable mini goal a human can do foreseeably move towards the overall goal.{% if enable_termination %} If the goal appears impossible to achieve, explain why.{% endif %}
+ "thoughts": str, // Think step by step. What has been done so far and what is the next reasonable mini goal a human can do foreseeably move towards the overall goal. If the goal appears impossible to achieve, explain why.
"user_goal_achieved": bool, // True if the user goal has been completed, false otherwise. If the user wants to extract information and it has not been done, the user goal is not achieved.
-{% if enable_termination %}
"should_terminate": bool, // True ONLY if the user goal is definitively IMPOSSIBLE to achieve. Must have explicit evidence from the page. See termination guidelines above. False if there's any chance the goal can still be achieved.
"termination_reason": str, // If should_terminate is true, quote the EXACT error message or text from the page that proves impossibility. Be specific. Null if should_terminate is false.
-{% endif %}
- "plan": str, // The mini goal to achieve to move towards the user goal. DO NOT come up or hallucinate any data that's not provided in the user goal. Be accurate and precise. Return null if the user goal has been achieved{% if enable_termination %} or if should_terminate is true{% endif %}.
- "task_type": str, // One of the available task types: navigate, extract, loop. Null if user_goal_achieved is true{% if enable_termination %} or should_terminate is true{% endif %}.
+ "plan": str, // The mini goal to achieve to move towards the user goal. DO NOT come up or hallucinate any data that's not provided in the user goal. Be accurate and precise. Return null if the user goal has been achieved or if should_terminate is true.
+ "task_type": str, // One of the available task types: navigate, extract, loop. Null if user_goal_achieved is true or should_terminate is true.
"loop_values": list[str], // a list of string values to iterate through for loop task. null if it's not a loop task
"is_loop_value_link": bool, // true if the loop_values is a list of urls to go to before for each planning session inside the loop
}
diff --git a/skyvern/forge/prompts/skyvern/task_v2_check_completion.j2 b/skyvern/forge/prompts/skyvern/task_v2_check_completion.j2
index 6068dec5d..59f4e1045 100644
--- a/skyvern/forge/prompts/skyvern/task_v2_check_completion.j2
+++ b/skyvern/forge/prompts/skyvern/task_v2_check_completion.j2
@@ -1,4 +1,4 @@
-You're to assist the user to achieve the user goal in the web. Given the user goal, the latest screenshot of the page and the mini tasks that have been completed by the user along the way, help decide whether the user goal has been achieved{% if enable_termination %}, is impossible to achieve,{% endif %} or needs more steps.
+You're to assist the user to achieve the user goal in the web. Given the user goal, the latest screenshot of the page and the mini tasks that have been completed by the user along the way, help decide whether the user goal has been achieved, is impossible to achieve, or needs more steps.
Reply in JSON format with the following keys:
{
@@ -7,14 +7,11 @@ Reply in JSON format with the following keys:
"require_extraction": bool, // True if the user goal requires information extraction. False otherwise.
"task_history_information": str, // Think step by step. In task history, what information has been collected that's helpful and relevant to the user goal, and what information is missing if any.
"information_extracted": optional[bool], // True if the needed information has been extracted. False if the needed information has not been extracted (no extract task in history). Null if the user goal does not require information extraction.
- "thoughts": str, // Think step by step. Would completing the tasks in the task history be good enough to achieve the user goal? If more tasks need to be completed to achieve the goal, what would be the next task?{% if enable_termination %} If the goal appears impossible, explain why.{% endif %}
+ "thoughts": str, // Think step by step. Would completing the tasks in the task history be good enough to achieve the user goal? If more tasks need to be completed to achieve the goal, what would be the next task? If the goal appears impossible, explain why.
"user_goal_achieved": bool, // True if the user goal has been completed, false otherwise. If the user wants to extract information and it has not been done, the user goal is not achieved. If info extraction is not required, use the task history, assisted by the screenshot to decide if the user goal has been achieved.
-{% if enable_termination %}
"should_terminate": bool, // True ONLY if there is CLEAR, EXPLICIT, UNAMBIGUOUS evidence that the goal is IMPOSSIBLE. The page must explicitly state the action cannot be done. False if there's ANY chance the goal can still be achieved.
"termination_reason": str // If should_terminate is true, quote the EXACT error message or text from the page that proves impossibility. Null if should_terminate is false.
-{% endif %}
}
-{% if enable_termination %}
CRITICAL - Be very conservative about termination. Only terminate when:
- The page shows an EXPLICIT error message stating impossibility (e.g., "Account does not exist", "Product discontinued", "Access permanently denied")
@@ -24,7 +21,6 @@ CRITICAL - Be very conservative about termination. Only terminate when:
- NOT when you're on a wrong page that could be navigated away from
When in doubt, set should_terminate to false and continue trying.
-{% endif %}
User goal:
```
diff --git a/skyvern/services/task_v2_service.py b/skyvern/services/task_v2_service.py
index 0c5659d67..b00a89227 100644
--- a/skyvern/services/task_v2_service.py
+++ b/skyvern/services/task_v2_service.py
@@ -602,16 +602,6 @@ async def run_task_v2_helper(
current_run_id,
properties={"organization_id": organization_id, "task_url": task_v2.url},
)
- enable_task_v2_termination = await app.EXPERIMENTATION_PROVIDER.is_feature_enabled_cached(
- "ENABLE_TASK_V2_TERMINATION",
- current_run_id,
- properties={"organization_id": organization_id, "task_url": task_v2.url},
- )
- LOG.info(
- "Task v2 termination feature flag",
- enable_task_v2_termination=enable_task_v2_termination,
- organization_id=organization_id,
- )
skyvern_context.set(
SkyvernContext(
organization_id=organization_id,
@@ -785,7 +775,6 @@ async def run_task_v2_helper(
user_goal=user_prompt,
task_history=task_history,
local_datetime=datetime.now(context.tz_info).isoformat(),
- enable_termination=bool(enable_task_v2_termination),
)
thought = await app.DATABASE.create_thought(
task_v2_id=task_v2_id,
@@ -854,8 +843,7 @@ async def run_task_v2_helper(
)
break
- # Only handle termination if the feature flag is enabled
- if enable_task_v2_termination and should_terminate is True:
+ if should_terminate is True:
task_v2 = await _handle_task_v2_termination(
task_v2_id=task_v2_id,
organization_id=organization_id,
@@ -1038,7 +1026,6 @@ async def run_task_v2_helper(
user_goal=user_prompt,
task_history=task_history,
local_datetime=datetime.now(context.tz_info).isoformat(),
- enable_termination=bool(enable_task_v2_termination),
)
thought = await app.DATABASE.create_thought(
task_v2_id=task_v2_id,
@@ -1097,8 +1084,7 @@ async def run_task_v2_helper(
)
break
- # Only handle termination if the feature flag is enabled
- if enable_task_v2_termination and should_terminate:
+ if should_terminate:
task_v2 = await _handle_task_v2_termination(
task_v2_id=task_v2_id,
organization_id=organization_id,
diff --git a/tests/unit/test_setup_ai_env.py b/tests/unit/test_setup_ai_env.py
new file mode 100644
index 000000000..77f86843c
--- /dev/null
+++ b/tests/unit/test_setup_ai_env.py
@@ -0,0 +1,39 @@
+from __future__ import annotations
+
+import os
+import stat
+import subprocess
+from pathlib import Path
+
+REPO_ROOT = Path(__file__).resolve().parents[2]
+SCRIPT_PATH = REPO_ROOT / ".github/actions/setup-ai-env/uv-sync.sh"
+
+
+def _make_fake_uv(tmp_path: Path) -> Path:
+ uv = tmp_path / "uv"
+ uv.write_text('#!/usr/bin/env bash\nprintf "%s\\n" "$@" > "$UV_ARGS_FILE"\n', encoding="utf-8")
+ uv.chmod(uv.stat().st_mode | stat.S_IEXEC)
+ return uv
+
+
+def test_setup_ai_env_uv_sync_groups_are_expanded(tmp_path: Path) -> None:
+ fake_bin = tmp_path / "bin"
+ fake_bin.mkdir()
+ _make_fake_uv(fake_bin)
+ args_file = tmp_path / "uv_args.txt"
+
+ env = os.environ.copy()
+ env["PATH"] = f"{fake_bin}:{env['PATH']}"
+ env["UV_SYNC_GROUPS"] = " cloud, dev , ,"
+ env["UV_ARGS_FILE"] = str(args_file)
+
+ result = subprocess.run(["bash", str(SCRIPT_PATH)], cwd=REPO_ROOT, env=env, capture_output=True, text=True)
+
+ assert result.returncode == 0, result.stderr
+ assert args_file.read_text(encoding="utf-8").splitlines() == [
+ "sync",
+ "--group",
+ "cloud",
+ "--group",
+ "dev",
+ ]