Skip to main content

How to Build an AI Agent That Tracks Your Competitors Using Stagehand & Browserbase

Updated 6 min readMarkdown
How to Build an AI Agent That Tracks Your Competitors Using Stagehand & Browserbase

Many teams still treat competitive intelligence as a reaction game. They wait for a rival to act, then scramble to adjust. That approach works in slow-moving markets, but speed is no longer the exception.

The real edge belongs to teams that move first. Competitive advantage is less about how quickly you respond and more about whether you’ve built systems that notice shifts before anyone else. Strategy is no longer just a quarterly report. It is a live feed.

AI-native automation makes this shift practical. With tools like Stagehand and Browserbase, you can stand up a digital analyst that never switches off. It watches pricing pages, product updates, and blog feeds, filtering signals from noise and turning them into foresight.

To level up, shift the mindset: intelligence should not be treated as a project, but as infrastructure. Those who make the shift set the pace instead of chasing it.

Why Build a Competitor Tracking Agent?

Competitive moves are often uncovered by chance. A prospect mentions a new bundle on a call. Someone notices a quiet price change. A press release surfaces days too late. By then, the window to respond has already narrowed. An AI-driven tracking agent turns that uncertainty into a system. Intelligence arrives as it happens, giving your teams room to adjust roadmaps, defend margins, and seize openings before they close.

The superpowers your clients actually need:

  • Pricing & Product Monitoring: Spot changes in competitor pricing, bundles, and promotions the moment they go live, and defend your margins with confidence.

  • News & Signal Tracking: Stay ahead of launches, partnerships, and announcements by turning the endless stream of press releases and blogs into real-time, actionable signals.

  • Hiring Signal Analysis: Read the intent behind a wave of new job postings, revealing strategic bets before they are made public.

  • Automated Sales Battlecards: Keep sales conversations sharp with living battlecards that update themselves, surfacing the latest wins, objections, and differentiators.

The Technical Stack

Building a production-ready agent comes down to two foundations: a smart automation layer and infrastructure that can carry the load at scale. Stagehand and Browserbase deliver both.

Stagehand: Turning Browsers Into Intelligent Minions

Most automation today sits at two extremes. On one side are tools like Playwright or Selenium, powerful but brittle. A single UI tweak and your scripts snap. On the other side are fully autonomous agents, flexible but opaque and hard to trust in production.

Stagehand charts a middle path. It combines the control of code with the adaptability of AI, wrapping Playwright with AI-native primitives that make automation less fragile and more usable in the real world.

  • act(): Run actions like clicks or form fills with plain instructions. Instead of chasing fragile selectors, write await page.act("Click the 'Sign In' button").

  • extract(): Pull structured data by pairing natural language instructions with a schema. Outputs arrive clean, validated, and typed.

  • observe(): Preview possible actions on a page before committing. Perfect for debugging and for building repeatable flows that don’t surprise you.

Browserbase: Infrastructure That Scales Without the Headaches

Stagehand gives your agent the intelligence, but intelligence needs a body strong enough to operate at scale. Running headless browsers yourself means wrestling with servers, concurrency limits, crashes, and scaling headaches. That’s engineering time sunk into work no one on your team really wants to do.

Browserbase is a managed cloud infrastructure that handles all of this for you. It provides a production-ready environment that allows your agent to run reliably and at scale.

  • Massive Scalability: Spin up thousands of isolated browser sessions in milliseconds. Campaigns of any size become as easy as running one local test.

  • Stealth Mode: Modern sites fight bots with CAPTCHAs, fingerprinting, and proxy checks. Browserbase’s Stealth Mode handles these defenses with managed proxies, realistic fingerprints, and automated CAPTCHA solving.

Observability: Debugging at scale is hard unless you can watch it happen. Browserbase gives you session replay, letting you review failures as if you were sitting at the browser yourself.

Build It! A Pricing Page Tracker

A pricing tracker is one of the clearest proofs of value. Done manually, it eats hours. Automated, it becomes a constant feed of high-value data: plan names, prices, and features, ready for analysis.

Before you start, create a free Browserbase account to get your API credentials. You’ll need a BROWSERBASE_API_KEY and a BROWSERBASE_PROJECT_ID to connect Stagehand to the cloud environment.

  1. Environment Setup

You need two ingredients: a browser you can trust at scale (Browserbase) and an LLM to drive the automation (OpenAI, Anthropic, Gemini, etc.).

  • Install the SDK: For a Node.js project, install Stagehand and a schema validation library like Zod:
npm install @browserbasehq/stagehand zod
  • Configure Environment Variables: Store your API keys securely in a .env file:
BROWSERBASE_API_KEY=your_browserbase_key
BROWSERBASE_PROJECT_ID=your_project_id
OPENAI_API_KEY=your_openai_key
  1. Code Implementation

With Stagehand, you describe what you want. The framework translates that into reliable browser actions and structured output.

import { Stagehand } from "@browserbasehq/stagehand";
import { z } from "zod";

const stagehand = new Stagehand({
  env: "BROWSERBASE",
  apiKey: process.env.BROWSERBASE_API_KEY,
  projectId: process.env.BROWSERBASE_PROJECT_ID,
  modelName: "gpt-4o",
  modelClientOptions: { apiKey: process.env.OPENAI_API_KEY },
});

async function scrapePricingPage() {
  await stagehand.init();
  const page = stagehand.page;
  await page.goto("https://www.apple.com/ph/shop/buy-iphone");

  const pricingData = await page.extract({
    instruction: "Extract the pricing plans and their details, including price, name, and key features.",
    schema: z.object({
      plans: z.array(z.object({
        name: z.string().describe("The name of the plan"),
        price: z.string().describe("The price of the plan"),
        features: z.array(z.string()).describe("A list of key features included in the plan"),
      })),
    }),
  });

  console.log(JSON.stringify(pricingData, null, 2));
  await stagehand.close();
}

scrapePricingPage().catch(console.error);

When you run this, the agent will navigate to the target URL, extract structured pricing data, and output a clean JSON object similar to this:

Try It Yourself

You now have a working scraper that pulls structured pricing data into JSON. The next step is to experiment.

Open the code and look for this line:

await page.goto("https://www.apple.com/ph/shop/buy-iphone");

Swap the URL with any pricing page, product listing, or even your own site. The rest of the code stays the same. Stagehand still follows your instruction and schema. With just this edit, you can repurpose the agent for entirely new use cases.

Taking It Further: Production-Ready Tips

To move your agent from a script to a production system, consider these advanced techniques.

Handling Edge Cases with observe: Preview what the AI plans to do before it acts. Cache those steps so future runs are consistent, more predictable, and cheaper to operate.

Deploying as a Serverless Function: Wrap the agent in a serverless function (AWS Lambda, Vercel, etc.) and trigger it on a schedule. Browserbase keeps the heavy lifting off your plate, so your function stays lean.

Creating Actionable Alerts: Raw output is only useful if it reaches the right people. Pipe summaries into Slack, Teams, or email. Flag and bundle smaller changes into a weekly digest.

Conclusion

  • Competitive intelligence is no longer a quarterly exercise - it needs to be continuous.

  • Stagehand and Browserbase let you build a live system that detects market shifts early.

  • Instead of reacting to rivals, your team gains a steady stream of foresight:

    • Pricing changes

    • Product updates

    • Strategic signals that shape decisions in real time

The stack is simple: Stagehand makes automation flexible enough to survive real-world change, and Browserbase gives it the scale and reliability to run nonstop. Together, they let you build agents that don’t just collect data but give you the edge to act first.

No comments yet. Be the first to comment.