Skip to content

The agent that turns websites into APIs!

feat: add stagehand

kalil032119050cac7431
diff --git a/README.md b/README.md
index 6fa5bc8..1d813f1 100644
--- a/README.md
+++ b/README.md
@@ -15,7 +15,7 @@ CLI tool that captures browser traffic and automatically generates production-re
## ✨ Features
- 🌐 **Browser Automation**: Built on Playwright with stealth mode for realistic browsing
-- πŸ€– **Autonomous Agent Mode**: Fully automated browser interaction using AI agents (browser-use)
+- πŸ€– **Autonomous Agent Mode**: Fully automated browser interaction using AI agents (browser-use, stagehand)
- πŸ“Š **HAR Recording**: Captures all network traffic in HTTP Archive format
- 🧠 **AI-Powered Generation**: Uses Claude 4.5 to analyze traffic and generate clean Python code
- πŸ”Œ **OpenCode SDK Support**: Native integration with OpenCode SDK for more flexibility
@@ -23,7 +23,7 @@ CLI tool that captures browser traffic and automatically generates production-re
- πŸ“¦ **Production Ready**: Generated scripts include error handling, type hints, and documentation
- πŸ’Ύ **Session History**: All runs saved locally with full message logs
- πŸ’° **Cost Tracking**: Detailed token usage and cost estimation with cache support
-- πŸ”‘ **Multi-Provider Support**: Supports Browser-Use, OpenAI, and Google LLMs for agent mode
+- πŸ”‘ **Multi-Provider Support**: Supports Browser-Use and Stagehand agent providers with multiple LLM options
## Limitations
@@ -118,12 +118,21 @@ Fully automated browser interaction using AI agents:
pip install git+https://github.com/browser-use/browser-use.git@<commit-hash>
```
+**Agent Provider Configuration:**
+- **Browser-Use** (default): Supports Browser-Use LLM, OpenAI, and Google models
+- **Stagehand**: Supports OpenAI and Anthropic Computer Use models
+
**Agent Model Configuration:**
-- **Browser-Use LLM** (default): Requires `BROWSER_USE_API_KEY`
-- **OpenAI Models**: Format `openai/{model}` (e.g., `openai/gpt-4`), requires `OPENAI_API_KEY`
-- **Google Models**: Format `google/{model}` (e.g., `google/gemini-pro`), requires `GOOGLE_API_KEY`
+- **Browser-Use Provider**:
+ - **Browser-Use LLM**: Requires `BROWSER_USE_API_KEY`
+ - **OpenAI Models**: Format `openai/{model}` (e.g., `openai/gpt-4`), requires `OPENAI_API_KEY`
+ - **Google Models**: Format `google/{model}` (e.g., `google/gemini-pro`), requires `GOOGLE_API_KEY`
+- **Stagehand Provider**:
+ - **OpenAI Computer Use Models**: Format `openai/{cua-model}` (e.g., `openai/computer-use-preview-2025-03-11`), requires `OPENAI_API_KEY`
+ - **Anthropic Computer Use Models**: Format `anthropic/{cua-model}` (e.g., `anthropic/claude-sonnet-4-5-20250929`), requires `ANTHROPIC_API_KEY`
+ - Note: Stagehand only supports Computer Use Agents (CUA) models
-Configure agent model in `/settings` β†’ "agent model"
+Configure agent provider and model in `/settings` β†’ "agent provider" and "agent model"
### CLI Commands
@@ -153,15 +162,23 @@ Settings are stored in `~/.reverse-api/config.json`:
{
"model": "claude-sonnet-4-5",
"sdk": "claude",
+ "agent_provider": "browser-use",
"agent_model": "bu-llm",
"output_dir": null
}
```
+### Agent Provider Configuration
+
+The `agent_provider` setting controls which browser automation library is used:
+- **`browser-use`** (default): Browser-Use library with support for multiple LLM providers
+- **`stagehand`**: Stagehand library with OpenAI and Anthropic Computer Use models
+
### Agent Model Configuration
The `agent_model` setting controls which LLM is used for autonomous browser agents:
+**For Browser-Use Provider:**
- **`bu-llm`** (default): Browser-Use's own LLM
- Requires: `BROWSER_USE_API_KEY` environment variable
- **`openai/{model}`**: OpenAI models (e.g., `openai/gpt-4`, `openai/gpt-3.5-turbo`)
@@ -171,19 +188,31 @@ The `agent_model` setting controls which LLM is used for autonomous browser agen
- Requires: `GOOGLE_API_KEY` environment variable
- Optional: Install `langchain-google-genai` for additional model support
+**For Stagehand Provider:**
+- **`openai/{cua-model}`**: OpenAI Computer Use models (e.g., `openai/computer-use-preview-2025-03-11`)
+ - Requires: `OPENAI_API_KEY` environment variable
+ - Supported models: `computer-use-preview-2025-03-11`
+- **`anthropic/{cua-model}`**: Anthropic Computer Use models (e.g., `anthropic/claude-sonnet-4-5-20250929`)
+ - Requires: `ANTHROPIC_API_KEY` environment variable
+ - Supported models: `claude-sonnet-4-5-20250929`, `claude-haiku-4-5-20251001`, `claude-opus-4-5-20251101`
+- Note: Stagehand's `agent.execute()` mode only supports Computer Use Agents (CUA)
+
**Setting API Keys:**
```bash
# Browser-Use (default)
export BROWSER_USE_API_KEY="your-api-key"
-# OpenAI
+# OpenAI (required for OpenAI models and Stagehand)
export OPENAI_API_KEY="your-api-key"
-# Google
+# Anthropic (required for Anthropic models with Stagehand)
+export ANTHROPIC_API_KEY="your-api-key"
+
+# Google (for Browser-Use only)
export GOOGLE_API_KEY="your-api-key"
```
-Change agent model in `/settings` β†’ "agent model" or edit `config.json` directly.
+Change agent provider and model in `/settings` β†’ "agent provider" and "agent model" or edit `config.json` directly.
### SDK Selection
@@ -238,9 +267,7 @@ Generated `api_client.py` includes:
- βœ… **OpenCode** - Integration with OpenCode
- πŸ”„ **Codex** - Codex SDK support
-### Browser Agent Support
-- βœ… **Browser-use** - Browser automation for API discovery (implemented)
-- πŸ”„ **Stagehand** - Additional browser agent provider support
+
## πŸ› οΈ Development
diff --git a/src/reverse_api/browser.py b/src/reverse_api/browser.py
index cff2bf5..abc247c 100644
--- a/src/reverse_api/browser.py
+++ b/src/reverse_api/browser.py
@@ -1,5 +1,7 @@
"""Browser management with Playwright for HAR recording."""
+import io
+import logging
import os
import asyncio
@@ -7,6 +9,7 @@ import json
import random
import signal
import sys
+from contextlib import redirect_stderr
from pathlib import Path
from typing import Optional
@@ -19,6 +22,23 @@ from .utils import get_har_dir, get_timestamp
console = Console()
+# Null stderr stream for suppressing logs
+_null_stderr = io.StringIO()
+
+
+def _suppress_stagehand_logs():
+ """Suppress all Stagehand-related logs. Call before importing stagehand."""
+ for name in ["stagehand", "agent", "browserbase"]:
+ logger = logging.getLogger(name)
+ logger.setLevel(logging.CRITICAL + 100)
+ logger.propagate = False
+ logger.handlers = [logging.NullHandler()]
+
+
+def _null_logger(message: dict) -> None:
+ """Null logger that discards all messages."""
+ pass
+
# Realistic Chrome user agents (updated for late 2024/2025)
USER_AGENTS = [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36",
@@ -432,11 +452,14 @@ class ManualBrowser:
return self.har_path
-def parse_agent_model(agent_model: str) -> tuple[str, str | None]:
+def parse_agent_model(
+ agent_model: str, agent_provider: str = "browser-use"
+) -> tuple[str, str | None]:
"""Parse agent_model string into provider and model name.
Args:
agent_model: Model string in format "bu-llm" or "{provider}/{model_name}"
+ agent_provider: Agent provider ("browser-use" or "stagehand")
Returns:
Tuple of (provider, model_name) where model_name is None for "bu-llm"
@@ -453,7 +476,38 @@ def parse_agent_model(agent_model: str) -> tuple[str, str | None]:
parts = agent_model.split("/", 1)
if len(parts) == 2:
provider, model_name = parts
- return (provider.lower(), model_name)
+ provider = provider.lower()
+
+ if agent_provider == "stagehand":
+ openai_cua_models = [
+ "computer-use-preview-2025-03-11",
+ ]
+
+ anthropic_cua_models = [
+ "claude-sonnet-4-5-20250929",
+ "claude-haiku-4-5-20251001",
+ "claude-opus-4-5-20251101",
+ ]
+
+ if provider == "openai":
+ if model_name not in openai_cua_models:
+ raise ValueError(
+ f"Unsupported OpenAI model: {model_name}. "
+ f"Supported OpenAI CUA models: {', '.join(openai_cua_models)}"
+ )
+ elif provider == "anthropic":
+ if model_name not in anthropic_cua_models:
+ raise ValueError(
+ f"Unsupported Anthropic model: {model_name}. "
+ f"Supported Anthropic CUA models: {', '.join(anthropic_cua_models)}"
+ )
+ else:
+ raise ValueError(
+ f"Stagehand only supports OpenAI and Anthropic Computer Use models. "
+ f"Got: {agent_model}. Expected format: 'openai/{{model}}' or 'anthropic/{{model}}'"
+ )
+
+ return (provider, model_name)
raise ValueError(
f"Invalid agent_model format: {agent_model}. "
@@ -461,11 +515,14 @@ def parse_agent_model(agent_model: str) -> tuple[str, str | None]:
)
-def get_required_api_key(provider: str) -> tuple[str, str]:
+def get_required_api_key(
+ provider: str, agent_provider: str = "browser-use"
+) -> tuple[str, str]:
"""Get the required API key environment variable name for a provider.
Args:
- provider: Provider name ("bu-llm", "openai", or "google")
+ provider: Provider name ("bu-llm", "openai", "google", or "anthropic")
+ agent_provider: Agent provider ("browser-use" or "stagehand")
Returns:
Tuple of (env_var_name, display_name)
@@ -473,10 +530,17 @@ def get_required_api_key(provider: str) -> tuple[str, str]:
Raises:
ValueError: If provider is not supported
"""
+ if agent_provider == "stagehand":
+ if provider == "anthropic":
+ return ("ANTHROPIC_API_KEY", "Anthropic API key")
+ else:
+ return ("OPENAI_API_KEY", "OpenAI API key")
+
provider_map = {
"bu-llm": ("BROWSER_USE_API_KEY", "Browser-Use API key"),
"openai": ("OPENAI_API_KEY", "OpenAI API key"),
"google": ("GOOGLE_API_KEY", "Google API key"),
+ "anthropic": ("ANTHROPIC_API_KEY", "Anthropic API key"),
}
if provider not in provider_map:
@@ -488,17 +552,20 @@ def get_required_api_key(provider: str) -> tuple[str, str]:
return provider_map[provider]
-def validate_api_key(provider: str) -> tuple[bool, str | None]:
+def validate_api_key(
+ provider: str, agent_provider: str = "browser-use"
+) -> tuple[bool, str | None]:
"""Validate that the required API key exists for the provider.
Args:
- provider: Provider name ("bu-llm", "openai", or "google")
+ provider: Provider name ("bu-llm", "openai", "google", or "anthropic")
+ agent_provider: Agent provider ("browser-use" or "stagehand")
Returns:
Tuple of (is_valid, error_message)
"""
try:
- env_var_name, display_name = get_required_api_key(provider)
+ env_var_name, display_name = get_required_api_key(provider, agent_provider)
api_key = os.getenv(env_var_name)
if not api_key:
@@ -513,10 +580,11 @@ def validate_api_key(provider: str) -> tuple[bool, str | None]:
class AgentBrowser:
- """Manages autonomous browser session with browser-use and HAR recording.
+ """Manages autonomous browser session with browser-use or stagehand and HAR recording.
- Launches Chromium, captures HAR via CDP Network domain,
- and browser-use connects via CDP for AI-powered automation.
+ Supports two agent providers:
+ - browser-use: Uses browser-use library with multiple LLM providers
+ - stagehand: Uses Stagehand library with OpenAI Computer Use models only
"""
def __init__(
@@ -526,6 +594,7 @@ class AgentBrowser:
output_dir: str | None = None,
timeout: int = 300,
agent_model: str = "bu-llm",
+ agent_provider: str = "browser-use",
start_url: Optional[str] = None,
):
"""Initialize agent browser."""
@@ -534,6 +603,7 @@ class AgentBrowser:
self.output_dir = output_dir
self.timeout = timeout
self.agent_model = agent_model
+ self.agent_provider = agent_provider
self.start_url = start_url
# Setup paths
@@ -550,6 +620,7 @@ class AgentBrowser:
"run_id": self.run_id,
"prompt": self.prompt,
"mode": "agent",
+ "agent_provider": self.agent_provider,
"agent_model": self.agent_model,
"start_time": self._start_time,
"end_time": end_time,
@@ -561,6 +632,13 @@ class AgentBrowser:
json.dump(metadata, f, indent=2)
async def _run_with_har_capture(self, cdp_url: str = None) -> dict:
+ """Run agent with HAR recording. Routes to browser-use or stagehand based on agent_provider."""
+ if self.agent_provider == "stagehand":
+ return await self._run_with_stagehand()
+ else:
+ return await self._run_with_browser_use()
+
+ async def _run_with_browser_use(self) -> dict:
"""Run agent with HAR recording via browser-use's built-in HAR capture."""
import logging
@@ -630,21 +708,23 @@ class AgentBrowser:
try:
# Parse agent model and validate API key
try:
- provider, model_name = parse_agent_model(self.agent_model)
+ provider, model_name = parse_agent_model(
+ self.agent_model, self.agent_provider
+ )
except ValueError as e:
result["error"] = str(e)
console.print(f" [red]error:[/red] {e}")
return result
# Validate API key
- is_valid, error_msg = validate_api_key(provider)
+ is_valid, error_msg = validate_api_key(provider, self.agent_provider)
if not is_valid:
result["error"] = error_msg
console.print(f" [red]error:[/red] {error_msg}")
return result
# Create appropriate LLM instance
- env_var_name, _ = get_required_api_key(provider)
+ env_var_name, _ = get_required_api_key(provider, self.agent_provider)
api_key = os.getenv(env_var_name)
if provider == "bu-llm":
@@ -743,6 +823,195 @@ class AgentBrowser:
return result
+ async def _run_with_stagehand(self) -> dict:
+ """Run agent with HAR recording via Stagehand's built-in HAR capture."""
+ _suppress_stagehand_logs()
+
+ try:
+ from stagehand import Stagehand
+ except ImportError:
+ return {
+ "success": False,
+ "message": None,
+ "error": "stagehand is required. Install with: pip install 'reverse-api-engineer[agent]'",
+ }
+
+ result = {"success": False, "message": None, "error": None}
+ stagehand = None
+
+ try:
+ try:
+ provider, model_name = parse_agent_model(
+ self.agent_model, self.agent_provider
+ )
+ except ValueError as e:
+ result["error"] = str(e)
+ console.print(f" [red]error:[/red] {e}")
+ return result
+
+ is_valid, error_msg = validate_api_key(provider, self.agent_provider)
+ if not is_valid:
+ result["error"] = error_msg
+ console.print(f" [red]error:[/red] {error_msg}")
+ return result
+
+ console.print(f" [dim]starting stagehand with har...[/dim]")
+
+ env_var_name, _ = get_required_api_key(provider, self.agent_provider)
+ api_key = os.getenv(env_var_name)
+
+ with redirect_stderr(_null_stderr):
+ stagehand = Stagehand(env="LOCAL", verbose=0, logger=_null_logger)
+ await stagehand.init()
+
+ # Set up HAR recording using Playwright's route_from_har
+ # Create empty HAR file first, then use route_from_har with update=True to record
+ if hasattr(stagehand, "context") and stagehand.context:
+ self.har_dir.mkdir(parents=True, exist_ok=True)
+
+ import json
+
+ empty_har = {
+ "log": {
+ "version": "1.2",
+ "creator": {"name": "reverse-api-engineer", "version": "0.2.0"},
+ "pages": [],
+ "entries": [],
+ }
+ }
+
+ with open(self.har_path, "w") as f:
+ json.dump(empty_har, f)
+
+ # Use route_from_har with update=True to record all network traffic
+ try:
+ await stagehand.context.route_from_har(
+ str(self.har_path),
+ update=True, # Records new HAR file
+ not_found="abort", # Abort requests not in HAR (but we have empty HAR)
+ )
+ except Exception as e:
+ console.print(
+ f" [dim]warning: could not set up HAR recording: {e}[/dim]"
+ )
+
+ agent_options = {
+ "api_key": api_key,
+ }
+
+ with redirect_stderr(_null_stderr):
+ if provider == "anthropic":
+ agent = stagehand.agent(
+ provider="anthropic",
+ model=model_name,
+ options=agent_options,
+ )
+ else:
+ # OpenAI (default for stagehand)
+ agent = stagehand.agent(
+ provider="openai",
+ model=model_name,
+ options=agent_options,
+ )
+
+ console.print(f" [dim]stagehand started[/dim]")
+
+ # Navigate to start URL first if provided (best practice per Stagehand docs)
+ if self.start_url:
+ # Stagehand agent has access to the page, navigate before executing
+ # We'll include the URL in the instruction if agent doesn't expose page directly
+ task_instruction = f"{self.prompt}\n\nStart URL: {self.start_url}"
+ else:
+ task_instruction = self.prompt
+
+ # Execute the task
+ with redirect_stderr(_null_stderr):
+ agent_result = await agent.execute(
+ {
+ "instruction": task_instruction,
+ "maxSteps": self.timeout
+ // 10, # Convert timeout seconds to reasonable step limit
+ }
+ )
+
+ # Extract result from agent_result
+ # According to Stagehand v2 docs, when using object form, result has:
+ # - success: boolean indicating if task completed
+ # - result/text: the actual result content
+ final_message = None
+ task_success = False
+
+ if agent_result:
+ if isinstance(agent_result, dict):
+ task_success = agent_result.get("success", False)
+ final_message = (
+ agent_result.get("message")
+ or agent_result.get("result")
+ or agent_result.get("text")
+ )
+ elif hasattr(agent_result, "success"):
+ task_success = agent_result.success
+ # Only extract message field, ignore actions, usage, etc.
+ if hasattr(agent_result, "message") and agent_result.message:
+ final_message = str(agent_result.message)
+ elif hasattr(agent_result, "result"):
+ final_message = str(agent_result.result)
+ elif hasattr(agent_result, "text"):
+ final_message = agent_result.text
+ else:
+ # Fallback: try to get message if it exists as attribute
+ final_message = getattr(
+ agent_result, "message", "Task completed"
+ )
+ elif isinstance(agent_result, str):
+ # String result (simple form)
+ final_message = agent_result
+ task_success = True # Assume success if string returned
+ elif hasattr(agent_result, "message") and agent_result.message:
+ # Object with message attribute
+ final_message = str(agent_result.message)
+ task_success = getattr(
+ agent_result,
+ "success",
+ getattr(agent_result, "completed", True),
+ )
+ elif hasattr(agent_result, "result"):
+ final_message = str(agent_result.result)
+ task_success = True
+ elif hasattr(agent_result, "text"):
+ final_message = agent_result.text
+ task_success = True
+ else:
+ # Last resort: try message attribute, otherwise use default
+ final_message = getattr(agent_result, "message", "Task completed")
+ task_success = True
+
+ result["success"] = task_success
+ result["message"] = final_message or "Task completed"
+
+ except Exception as e:
+ result["error"] = str(e)
+ console.print(f" [yellow]stagehand error: {e}[/yellow]")
+ finally:
+ if stagehand:
+ try:
+ with redirect_stderr(_null_stderr):
+ await stagehand.close()
+ except Exception:
+ pass
+
+ # Check if HAR file was created and has content
+ if self.har_path.exists():
+ har_size = self.har_path.stat().st_size
+ if har_size > 100: # HAR file should have some content
+ console.print(f" [dim]har saved: {har_size} bytes[/dim]")
+ else:
+ console.print(f" [dim]har file exists but appears empty[/dim]")
+ else:
+ console.print(f" [dim]har not saved[/dim]")
+
+ return result
+
def start(self) -> Path:
"""Start agent execution with HAR recording. Returns HAR path when done."""
self._start_time = get_timestamp()
@@ -784,6 +1053,7 @@ def run_agent_browser(
output_dir: str | None = None,
timeout: int = 300,
agent_model: str = "bu-llm",
+ agent_provider: str = "browser-use",
start_url: Optional[str] = None,
) -> Path:
"""Run agent browser with HAR recording."""
@@ -793,6 +1063,7 @@ def run_agent_browser(
output_dir=output_dir,
timeout=timeout,
agent_model=agent_model,
+ agent_provider=agent_provider,
start_url=start_url,
)
return agent_browser.start()
diff --git a/src/reverse_api/cli.py b/src/reverse_api/cli.py
index 48b30c6..3dd1ede 100644
--- a/src/reverse_api/cli.py
+++ b/src/reverse_api/cli.py
@@ -317,6 +317,7 @@ def handle_settings():
choices=[
Choice(title="> change model", value="model"),
Choice(title="> change sdk", value="sdk"),
+ Choice(title="> agent provider", value="agent_provider"),
Choice(title="> agent model", value="agent_model"),
Choice(title="> output directory", value="output_dir"),
Choice(title="> back", value="back"),
@@ -376,14 +377,56 @@ def handle_settings():
config_manager.set("sdk", sdk)
console.print(f" [dim]updated[/dim] sdk: {sdk}\n")
+ elif action == "agent_provider":
+ provider_choices = [
+ Choice(title="> browser-use", value="browser-use"),
+ Choice(title="> stagehand", value="stagehand"),
+ Choice(title="> back", value="back"),
+ ]
+ provider = questionary.select(
+ "",
+ choices=provider_choices,
+ pointer="",
+ qmark="",
+ style=questionary.Style(
+ [
+ ("highlighted", f"fg:{THEME_PRIMARY} bold"),
+ ]
+ ),
+ ).ask()
+ if provider and provider != "back":
+ config_manager.set("agent_provider", provider)
+ console.print(f" [dim]updated[/dim] agent provider: {provider}\n")
+ # If switching to stagehand, validate current model
+ if provider == "stagehand":
+ current_model = config_manager.get("agent_model", "bu-llm")
+ try:
+ from .browser import parse_agent_model
+
+ parse_agent_model(current_model, provider)
+ except ValueError:
+ console.print(
+ f" [yellow]warning:[/yellow] Current agent model '{current_model}' may not be compatible with stagehand.\n"
+ )
+ console.print(
+ f" [dim]Stagehand supports OpenAI and Anthropic Computer Use models[/dim]\n"
+ f" [dim]Examples: openai/computer-use-preview-2025-03-11, anthropic/claude-sonnet-4-5-20250929[/dim]\n"
+ )
+
elif action == "agent_model":
from .browser import parse_agent_model
current = config_manager.get("agent_model", "bu-llm")
+ agent_provider = config_manager.get("agent_provider", "browser-use")
+
+ instruction = "(Format: 'bu-llm' or 'provider/model', e.g., 'openai/gpt-4')"
+ if agent_provider == "stagehand":
+ instruction = "(Format: 'openai/model' or 'anthropic/model', e.g., 'openai/computer-use-preview-2025-03-11' or 'anthropic/claude-sonnet-4-5-20250929')"
+
new_model = questionary.text(
" > agent model",
default=current or "bu-llm",
- instruction="(Format: 'bu-llm' or 'provider/model', e.g., 'openai/gpt-4')",
+ instruction=instruction,
qmark="",
style=questionary.Style(
[
@@ -397,19 +440,28 @@ def handle_settings():
if not new_model:
console.print(" [yellow]error:[/yellow] agent model cannot be empty\n")
else:
- # Validate format
+ # Validate format with current agent_provider
try:
- parse_agent_model(new_model)
+ parse_agent_model(new_model, agent_provider)
config_manager.set("agent_model", new_model)
console.print(f" [dim]updated[/dim] agent model: {new_model}\n")
except ValueError as e:
console.print(f" [yellow]error:[/yellow] {e}\n")
- console.print(
- " [dim]Valid formats:[/dim]\n"
- " [dim] - bu-llm[/dim]\n"
- " [dim] - openai/model_name (e.g., openai/gpt-4)[/dim]\n"
- " [dim] - google/model_name (e.g., google/gemini-pro)[/dim]\n"
- )
+ if agent_provider == "stagehand":
+ console.print(
+ " [dim]Valid formats for stagehand:[/dim]\n"
+ " [dim] - openai/computer-use-preview-2025-03-11[/dim]\n"
+ " [dim] - anthropic/claude-sonnet-4-5-20250929[/dim]\n"
+ " [dim] - anthropic/claude-haiku-4-5-20251001[/dim]\n"
+ " [dim] - anthropic/claude-opus-4-5-20251101[/dim]\n"
+ )
+ else:
+ console.print(
+ " [dim]Valid formats:[/dim]\n"
+ " [dim] - bu-llm[/dim]\n"
+ " [dim] - openai/model_name (e.g., openai/gpt-4)[/dim]\n"
+ " [dim] - google/model_name (e.g., google/gemini-pro)[/dim]\n"
+ )
elif action == "output_dir":
current = config_manager.get("output_dir")
@@ -640,8 +692,9 @@ def run_agent_capture(
run_id = generate_run_id()
timestamp = get_timestamp()
- # Get agent model from config
+ # Get agent model and provider from config
agent_model = config_manager.get("agent_model", "bu-llm")
+ agent_provider = config_manager.get("agent_provider", "browser-use")
# Record initial session
session_manager.add_run(
@@ -661,12 +714,12 @@ def run_agent_capture(
prompt=prompt,
output_dir=output_dir,
agent_model=agent_model,
+ agent_provider=agent_provider,
start_url=url,
)
# Optionally run reverse engineering
if reverse_engineer:
- # Ask if user wants a new prompt for the engineer
engineer_prompt = prompt
try:
wants_new_prompt = questionary.confirm(
@@ -681,7 +734,7 @@ def run_agent_capture(
),
).ask()
- if wants_new_prompt is None: # Ctrl+C or similar
+ if wants_new_prompt is None:
raise KeyboardInterrupt
if wants_new_prompt:
@@ -698,13 +751,12 @@ def run_agent_capture(
),
).ask()
- if new_prompt is None: # Ctrl+C or similar
+ if new_prompt is None:
raise KeyboardInterrupt
if new_prompt and new_prompt.strip():
engineer_prompt = new_prompt.strip()
except KeyboardInterrupt:
- # User cancelled, use original prompt
pass
result = run_engineer(
diff --git a/uv.lock b/uv.lock
index 6f8d560..216cf56 100644
--- a/uv.lock
+++ b/uv.lock
@@ -240,7 +240,7 @@ wheels = [
[[package]]
name = "browser-use"
version = "0.11.2"
-source = { git = "https://github.com/browser-use/browser-use.git?rev=1a96cf7ef00bfbb6e21978f77e347639c316fff8#1a96cf7ef00bfbb6e21978f77e347639c316fff8" }
+source = { git = "https://github.com/browser-use/browser-use.git?rev=49a345fb19e9f12befc5cc1658e0033873892455#49a345fb19e9f12befc5cc1658e0033873892455" }
dependencies = [
{ name = "aiohttp" },
{ name = "anthropic" },
@@ -4875,13 +4875,12 @@ wheels = [
[[package]]
name = "reverse-api-engineer"
-version = "0.1.0"
+version = "0.2.0"
source = { editable = "." }
dependencies = [
{ name = "aiohttp" },
{ name = "anthropic" },
{ name = "brotli" },
- { name = "browser-use" },
{ name = "claude-agent-sdk" },
{ name = "click" },
{ name = "playwright" },
@@ -4891,12 +4890,17 @@ dependencies = [
{ name = "rich" },
]
+[package.optional-dependencies]
+agent = [
+ { name = "browser-use" },
+]
+
[package.metadata]
requires-dist = [
{ name = "aiohttp", specifier = ">=3.12.15" },
{ name = "anthropic", specifier = ">=0.40.0" },
{ name = "brotli", specifier = ">=1.2.0" },
- { name = "browser-use", git = "https://github.com/browser-use/browser-use.git?rev=1a96cf7ef00bfbb6e21978f77e347639c316fff8" },
+ { name = "browser-use", marker = "extra == 'agent'", git = "https://github.com/browser-use/browser-use.git?rev=49a345fb19e9f12befc5cc1658e0033873892455" },
{ name = "claude-agent-sdk", specifier = ">=0.1.0" },
{ name = "click", specifier = ">=8.1.0" },
{ name = "playwright", specifier = ">=1.40.0" },
@@ -4905,6 +4909,7 @@ requires-dist = [
{ name = "requests", specifier = ">=2.32.5" },
{ name = "rich", specifier = ">=13.0.0" },
]
+provides-extras = ["agent"]
[package.metadata.requires-dev]
dev = []