PromptHub
Back to Blog
Developer Tools Artificial Intelligence

Stop Writing Brittle Selenium Scripts! Cerebellum AI Automates Browsers Intelligently

B

Bright Coding

Author

13 min read 91 views
Stop Writing Brittle Selenium Scripts! Cerebellum AI Automates Browsers Intelligently

Stop Writing Brittle Selenium Scripts! Cerebellum AI Automates Browsers Intelligently

What if your browser automation could think? What if instead of writing hundreds of lines of fragile XPath selectors and sleep timers, you could simply tell an AI agent: "Find a USB C to C cable that is 10 feet long and add it to cart"—and watch it actually do it?

Sound like science fiction? It's not. It's Cerebellum, and it's about to make your old Selenium workflows look like ancient history.

Here's the brutal truth every developer knows: traditional browser automation is a nightmare. Your carefully crafted selectors break when a designer sneezes. Dynamic content loads unpredictably. CAPTCHAs laugh at your headless Chrome. And every "simple" task explodes into hundreds of lines of defensive code, retry logic, and prayer. We've all been there—debugging why a button click failed at 2 AM because someone added a div wrapper.

But what if the automation itself could understand what it's looking at? What if it could read a page like a human, reason about elements, plan multi-step strategies, and adapt when things change? That's exactly what Cerebellum delivers. Built by Han Wang and collaborators, this open-source system transforms browser automation from brittle scripting into intelligent agent behavior powered by large language models.

In this deep dive, I'll expose how Cerebellum works under the hood, why developers are quietly abandoning traditional automation stacks, and how you can deploy this secret weapon in your own projects today. The future of browser automation isn't more selectors—it's AI that actually comprehends the web.


What Is Cerebellum? The Brain Behind Smarter Browsing

Cerebellum is a lightweight, AI-driven browser agent that accomplishes user-defined goals on webpages through keyboard and mouse actions—without you writing explicit step-by-step automation scripts.

Created by Han Wang with collaborators Darwin Lo, Michael Shuffett, and Shane Moran, Cerebellum represents a paradigm shift in how we think about web interaction. Rather than imperatively commanding how to do something, you declaratively state what you want—and the system figures out the rest.

The name itself is clever neuroscience: the cerebellum coordinates movement and motor learning. Similarly, this system coordinates complex sequences of browser actions through learned, adaptive planning.

Why it's trending now:

  • LLM capabilities finally caught up: Claude 3.5 Sonnet's visual reasoning makes genuine page understanding possible
  • Traditional automation pain reached critical mass: Teams spend more time maintaining Selenium scripts than building features
  • Agent-based AI exploded in 2024: From AutoGPT to browser-use, developers crave autonomous systems
  • MIT License means enterprise-friendly adoption: No legal friction for commercial use

Currently, Claude 3.5 Sonnet is the only supported LLM—a deliberate choice given its superior visual reasoning and action-planning capabilities. The project is actively evolving with a bold roadmap including local model training and multi-LLM support.


Key Features That Destroy Traditional Automation

Cerebellum isn't just another wrapper around Selenium. It's a fundamentally different architecture with capabilities that expose the limitations of conventional approaches:

🧠 LLM-Powered Action Planning

Instead of hardcoded scripts, Cerebellum uses Claude 3.5 Sonnet as an ActionPlanner to analyze page state, reason about available actions, and decide optimal next steps. The LLM sees annotated screenshots, understands element relationships, and plans strategically—not syntactically.

🌐 Universal Browser Compatibility

Works with any Selenium-supported browser. Chrome, Firefox, Safari, Edge—your choice. This isn't a browser-specific hack; it's architecture-agnostic by design.

📋 Intelligent Form Filling

Pass user data as JSON, and Cerebellum intelligently maps fields to form elements. No more mapping each input manually. The AI comprehends label semantics, placeholder text, and field context to populate forms correctly.

🎯 Runtime Instruction Adaptation

Issue commands mid-session to dynamically adjust strategy. Traditional automation would require stopping, rewriting, and restarting. Cerebellum accepts course corrections in natural language while maintaining session context.

📸 Visual State Understanding

The system captures and annotates screenshots with interactive element markers, giving the LLM genuine visual context—not just DOM dumps. This visual grounding dramatically reduces hallucination and misidentification.

📑 Tabbed Browsing Support

Already handles multi-tab scenarios, a notorious pain point in traditional automation where window management becomes spaghetti code.

🔮 Training Dataset Generation (Coming)

Future versions will convert successful browsing sessions into training data—enabling fine-tuned models and continuous improvement from real-world usage.


Use Cases Where Cerebellum Absolutely Dominates

1. E-Commerce Automation at Scale

Imagine monitoring hundreds of SKUs across competitors, checking stock availability, or executing purchases when items restock. Traditional automation breaks when sites A/B test layouts or update their frontend frameworks. Cerebellum adapts visually and semantically—reading "Add to Cart" whether it's a button, a link, or a React↗ Bright Coding Blog component.

2. Complex Multi-Step Form Workflows

Insurance applications, government filings, enterprise SaaS onboarding—these involve branching logic, conditional fields, and dynamic validation. Cerebellum's LLM planner handles decision trees that would require hundreds of conditional statements in traditional scripts.

3. Data Extraction from Dynamic Sites

While full extraction is on the roadmap, current capabilities already enable goal-directed information gathering. Tell it "Find the CEO's email on this company's website" and it navigates About pages, press releases, and contact sections intelligently—no sitemap required.

4. Accessibility Testing & QA

Verify that workflows remain completable even when visual presentation changes. Cerebellum's semantic understanding catches issues that pixel-comparison tools miss, like broken form labels or misleading button text.

5. Legacy System Interaction

That internal tool from 2012 with no API? Cerebellum doesn't need REST endpoints or GraphQL schemas. If a human can click through it, the agent can learn to navigate it—opening modernization paths without expensive rewrites.


Step-by-Step Installation & Setup Guide

Ready to stop writing brittle selectors? Here's how to get Cerebellum running in minutes.

Prerequisites

  • Python↗ Bright Coding Blog 3.8+ or Node.js/TypeScript environment
  • Selenium-compatible browser installed (Chrome recommended)
  • Anthropic API key for Claude 3.5 Sonnet access

Python Setup

# Clone the repository
git clone https://github.com/theredsix/cerebellum.git
cd cerebellum/python

# Create virtual environment (recommended)
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Configure your Anthropic API key
export ANTHROPIC_API_KEY="your-key-here"
# On Windows: set ANTHROPIC_API_KEY=your-key-here

TypeScript Setup

# Navigate to TypeScript directory
cd cerebellum/typescript

# Install dependencies
npm install

# Or with yarn
yarn install

# Configure environment
cp .env.example .env
# Edit .env with your ANTHROPIC_API_KEY

Browser Driver Configuration

Ensure your WebDriver matches your browser version:

# For Chrome: chromedriver must match Chrome version
# Download from: https://chromedriver.chromium.org/downloads

# Verify installation
chromedriver --version

Verify Installation

Run the included example to confirm everything works:

# Python
python examples/google_shopping.py

# TypeScript
npx ts-node examples/google_shopping.ts

Pro tip: Start with headed mode (visible browser) to observe the agent's decision-making. Once confident, switch to headless for production deployments.


REAL Code Examples from Cerebellum

Let's examine actual patterns from the repository, with detailed explanations of how this AI agent operates.

Example 1: Defining a Goal-Driven Browser Session

from cerebellum import BrowserAgent, ActionPlanner

# Initialize the LLM-powered planner with Claude 3.5 Sonnet
planner = ActionPlanner(
    model="claude-3-5-sonnet-20241022",  # Currently required model
    api_key=os.environ["ANTHROPIC_API_KEY"]
)

# Create browser agent with the planner as its "brain"
agent = BrowserAgent(
    planner=planner,
    browser="chrome",  # Any Selenium-supported browser
    headless=False     # Set True for production
)

# Define goal in natural language—no selectors, no XPaths
goal = "Find a USB C to C cable that is 10 feet long and add it to cart"

# Execute: the LLM plans and performs all actions autonomously
result = agent.execute(goal)

print(f"Success: {result.success}")
print(f"Actions taken: {len(result.actions)}")
print(f"Final URL: {result.final_url}")

What's happening here? Instead of scripting find_element(By.ID, "search").send_keys(), you declare intent. The BrowserAgent initializes a Selenium session, captures the page state, and feeds it to Claude. The LLM returns structured action plans—click here, type this, scroll there—which the agent executes and verifies.

Example 2: Runtime Instruction with JSON Data

# Provide structured data for form filling
user_data = {
    "email": "developer@example.com",
    "password": "secure_password_123",
    "first_name": "Alex",
    "last_name": "Developer",
    "phone": "555-0123"
}

# Goal references the data contextually
signup_goal = "Create an account using my information"

# Execute with data injection—LLM maps fields intelligently
result = agent.execute(
    goal=signup_goal,
    context={"user_data": user_data}  # JSON available to planner
)

The magic: Cerebellum doesn't need field mappings. The LLM recognizes that "email" corresponds to an input with type="email" or placeholder "Email address". It handles dynamic forms, validation errors, and multi-page flows that would break hardcoded scripts.

Example 3: Handling Tabbed Browsing and Dynamic Strategy

# Complex goal requiring tab management and adaptation
goal = "Compare prices for iPhone 15 on Amazon and Best Buy, then open the cheaper option in a new tab"

# Mid-session instruction to change approach
result = agent.execute(goal)

# Runtime course correction without restarting
if result.partial_success:
    # Agent accepts new instructions mid-flight
    adjustment = "Actually, check Walmart too before deciding"
    result = agent.continue_with_instruction(adjustment)

Why this matters: Traditional automation would require complete script rewrites for strategy changes. Cerebellum's stateful session maintains context across tabs and accepts natural language pivots—just like delegating to a human assistant.

Example 4: The Core Loop Exposed (Conceptual Implementation)

# Simplified illustration of Cerebellum's internal loop
def execute_goal(self, goal: str, max_steps: int = 50) -> Result:
    state = self.browser.get_current_state()  # Screenshot + element map
    history = []
    
    for step in range(max_steps):
        # LLM analyzes current state and history
        action = self.planner.decide_next_action(
            goal=goal,
            current_state=state,
            action_history=history,
            available_elements=self.browser.get_interactive_elements()
        )
        
        if action.type == "COMPLETE":
            return Result(success=True, actions=history)
        
        if action.type == "IMPOSSIBLE":
            return Result(success=False, reason=action.explanation)
        
        # Execute the planned action
        self.browser.execute(action)
        
        # Capture new state for next iteration
        state = self.browser.get_current_state()
        history.append(action)
    
    return Result(success=False, reason="Max steps exceeded")

This is the secret sauce: Web browsing reduced to graph traversal. Each page is a node, each action an edge, and the LLM serves as an intelligent pathfinder toward the goal node. The feedback loop—observe, plan, act, observe—enables genuine adaptation when the web changes.


Advanced Usage & Best Practices

Optimize with Explicit Constraints

While Cerebellum handles ambiguity, constraining the problem space improves reliability:

# Add domain hints for complex sites
result = agent.execute(
    goal="Book a flight",
    context={
        "preferred_airline": "Delta",
        "constraints": "non-stop only, morning departure"
    }
)

Handle Claude's Safety Refusals

The README notes known issues with Claude 3.5 refusals:

  • CAPTCHAs: Claude refuses to solve them (by Anthropic's design). Implement human-in-the-loop handoffs.
  • Political content: May halt on news sites. Scope sessions to specific task domains.

Session Persistence for Debugging

# Save full session for analysis
agent.save_session("failed_booking.json")

# Later: replay or analyze LLM reasoning chain
from cerebellum import SessionAnalyzer
analyzer = SessionAnalyzer("failed_booking.json")
analyzer.visualize_decision_tree()

Production Deployment Pattern

# Headless with retry logic and alerting
agent = BrowserAgent(
    planner=planner,
    headless=True,
    screenshot_on_error=True,
    max_retries=3,
    on_failure=lambda e: alert_ops_team(e)
)

Coming Soon: Training Data Generation

When dataset conversion launches, accumulate successful sessions:

# Future API (from roadmap)
agent.enable_dataset_collection(output_dir="./training_data/")
# Successful runs become fine-tuning examples for local models

Comparison with Alternatives: Why Cerebellum Wins

Feature Traditional Selenium Playwright Puppeteer Cerebellum
Setup Complexity High (selectors, waits, retries) Medium Medium Low (declarative goals)
Maintenance Burden Fragile to DOM changes Fragile to DOM changes Fragile to DOM changes Resilient (semantic understanding)
Multi-Step Reasoning Manual scripting required Manual scripting required Manual scripting required Built-in LLM planning
Visual Understanding None None None Screenshot analysis
Runtime Adaptation None None None Natural language instructions
Browser Support All major Chromium/WebKit/Firefox Chromium only All Selenium-supported
Speed Fast Fastest Fast Slower (LLM latency)
Cost Free Free Free Anthropic API costs
Open Source Yes Yes Yes MIT License

The trade-off is clear: Cerebellum sacrifices raw speed for unprecedented flexibility and maintainability. For complex, dynamic, or frequently-changing sites, the LLM overhead pays for itself in reduced engineering time and higher success rates.


FAQ: Your Cerebellum Questions Answered

Q: Is Cerebellum free to use? A: The code is MIT-licensed and free. However, you'll need an Anthropic API key, and Claude 3.5 Sonnet usage incurs standard API costs. Budget ~$0.03-0.15 per complex task depending on page complexity.

Q: Can I use GPT-4 or local LLMs instead of Claude? A: Not yet. The roadmap includes support for additional LLMs as ActionPlanners and eventual local model integration. Claude 3.5 Sonnet is currently required due to its superior visual reasoning capabilities.

Q: How does it handle JavaScript↗ Bright Coding Blog-heavy SPAs? A: Through Selenium's full browser automation, Cerebellum waits for dynamic content like a human would—observing state changes and adapting. The LLM recognizes loading states and incomplete renders.

Q: Is this suitable for high-frequency scraping? A: Not currently. The LLM latency makes it impractical for thousands of rapid requests. Use traditional tools for bulk scraping; deploy Cerebellum for complex, adaptive tasks where intelligence outweighs speed.

Q: What about sites blocking automation? A: Cerebellum uses standard Selenium browsers, so standard detection applies. The project doesn't include anti-detection measures. Respect robots.txt and terms of service.

Q: Can it handle file uploads or downloads? A: Through the standard Selenium capabilities underlying the agent. The LLM planner can initiate these actions when relevant to the goal.

Q: How do I contribute or report issues? A: See CONTRIBUTING.md in the repository. The maintainer welcomes bug reports, feature requests, and code contributions.


Conclusion: The Future of Browser Automation Is Here

Cerebellum isn't just another tool—it's a fundamental reimagining of how machines interact with the web. By replacing brittle imperative scripts with intelligent, goal-driven agents, it solves the maintenance nightmare that has plagued automation engineers for decades.

The evidence is compelling: a system that can autonomously navigate to find specific products, fill complex forms from JSON data, and adapt strategies mid-session using nothing but natural language instructions. Yes, there's a speed cost. Yes, Claude API expenses add up. But for the right use cases—complex workflows, dynamic sites, and scenarios where reliability trumps raw throughput—Cerebellum delivers capabilities that simply didn't exist before.

My take? This is the direction the entire industry is heading. Today's novelty becomes tomorrow's standard. The teams that master AI-driven automation now will have insurmountable advantages as the technology matures—local models, reduced latency, broader LLM support.

Don't let your automation stack become legacy. Fork Cerebellum on GitHub today. Experiment with the examples. Contribute to the roadmap. And join the small but growing community of developers who've stopped fighting with selectors—and started commanding intelligent agents.

The web was built for humans. Finally, your automation can think like one.


Found this breakdown valuable? Star the repo, share with your automation-weary colleagues, and watch for my deep-dive on training local models with Cerebellum session data once that feature drops.

Comments (0)

Comments are moderated before appearing.

No comments yet. Be the first to share your thoughts!