bstraehle commited on
Commit
b4335d5
·
verified ·
1 Parent(s): a6d1157

Update agents/tools/ai_tools.py

Browse files
Files changed (1) hide show
  1. agents/tools/ai_tools.py +12 -1
agents/tools/ai_tools.py CHANGED
@@ -65,7 +65,7 @@ class AITools():
65
 
66
  Args:
67
  question (str): Question about a URL
68
- url (str): The URL
69
 
70
  Returns:
71
  str: Answer to the question
@@ -74,6 +74,17 @@ class AITools():
74
  RuntimeError: If processing fails
75
  """
76
  try:
 
 
 
 
 
 
 
 
 
 
 
77
  stagehand_tool = StagehandTool(
78
  api_key=os.environ["BROWSERBASE_API_KEY"],
79
  project_id=os.environ["BROWSERBASE_PROJECT_ID"],
 
65
 
66
  Args:
67
  question (str): Question about a URL
68
+ url (str): The target URL (must be http/https). "http://"/"https://" will be auto-added if missing.
69
 
70
  Returns:
71
  str: Answer to the question
 
74
  RuntimeError: If processing fails
75
  """
76
  try:
77
+ raw_url = url.strip()
78
+
79
+ if not raw_url.lower().startswith(("http://", "https://")):
80
+ raw_url = f"https://{raw_url}"
81
+
82
+ from urllib.parse import urlparse
83
+ parsed = urlparse(raw_url)
84
+
85
+ if not parsed.scheme or not parsed.netloc:
86
+ raise RuntimeError(f"Invalid URL: {raw_url}")
87
+
88
  stagehand_tool = StagehandTool(
89
  api_key=os.environ["BROWSERBASE_API_KEY"],
90
  project_id=os.environ["BROWSERBASE_PROJECT_ID"],