LogoLogo
SupportDashboard
  • Community
  • Welcome to Hyperbrowser
  • Get Started
    • Quickstart
      • AI Agents
        • Browser Use
        • Claude Computer Use
        • OpenAI CUA
      • Web Scraping
        • Scrape
        • Crawl
        • Extract
      • Browser Automation
        • Puppeteer
        • Playwright
        • Selenium
  • Agents
    • Browser Use
    • Claude Computer Use
    • OpenAI CUA
  • HyperAgent
    • About HyperAgent
      • HyperAgent SDK
      • HyperAgent Types
  • Quickstart
  • Multi-Page actions
  • Custom Actions
  • MCP Support
    • Tutorial
  • Examples
    • Custom Actions
    • LLM support
    • Cloud Support
      • Setting Up
      • Proxies
      • Profiles
    • MCP Examples
      • Google Sheets
      • Weather
        • Weather Server
    • Output to Schema
  • Web Scraping
    • Scrape
    • Crawl
    • Extract
  • Sessions
    • Overview
      • Session Parameters
    • Advanced Privacy & Anti-Detection
      • Stealth Mode
      • Proxies
      • Static IPs
      • CAPTCHA Solving
      • Ad Blocking
    • Profiles
    • Recordings
    • Live View
    • Extensions
    • Downloads
  • Guides
    • Model Context Protocol
    • Scraping
    • AI Function Calling
    • Extract Information with an LLM
    • Using Hyperbrowser Session
    • CAPTCHA Solving
  • Integrations
    • ⛓️LangChain
    • 🦙LlamaIndex
  • reference
    • Pricing
    • SDKs
      • Node
        • Sessions
        • Profiles
        • Scrape
        • Crawl
        • Extensions
      • Python
        • Sessions
        • Profiles
        • Scrape
        • Crawl
        • Extensions
    • API Reference
      • Sessions
      • Scrape
      • Crawl
      • Extract
      • Agents
        • Browser Use
        • Claude Computer Use
        • OpenAI CUA
      • Profiles
      • Extensions
Powered by GitBook
On this page
  • Components of a custom action
  • An example custom action
  • How to use
Export as PDF

Custom Actions

Connect your web agent to the wider web

Some times, you'll need to do thing that are tough to achieve using just the built-in actions. For such cases, you can make your own custom action. Custom actions have full access to both the LLM, the browser page, and all other functionality possible within NodeJS.

Components of a custom action

A custom action requires 3 components:

  • type : This is used to distinguish a specific action from others available to the LLM. Make it unique and relevant to the task this action is supposed to perform.

  • actionParams : This describes the parameters that the custom action should accept. It expects a zod object.

  • run : A function that processes the instructions/parameteres produced by the LLM, and previous actions.

Response

The run of each custom action is required to output a dictionary containing the success value,and a message describing what happened. This could be the description of the error, or the success response.

Here's a simple example which introduces a custom action to navigate to a random wikipedia page.

An example custom action

import { HyperAgent } from "@hyperbrowser/agent";
import {
  AgentActionDefinition,
  ActionContext,
  ActionOutput,
} from "@hyperbrowser/agent/types";

const actionParams = z
  .object({})
  .describe(
    "Navigate to a random wikipedia page and return the title and url of the page."
  );

export const GoToWikipediaActionDefinition: AgentActionDefinition = {
  type: "go_to_random_wikipedia_page",
  actionParams: actionParams,
  run: async function (
    ctx: ActionContext,
    params: z.infer<typeof actionParams>
  ): Promise<ActionOutput> {
    await ctx.page.goto("https://en.wikipedia.org/wiki/Special:Random", {
      waitUntil: "domcontentloaded",
    });

    const url = ctx.page.url();
    const title = await ctx.page.title();
    return {
      success: true,
      message: `Succesfully navigated to URL: ${url} and title: ${title}`,
    };
  },
};

How to use

Each instance of HyperAgent accepts an array of customActions . These actions are used in addition to other built-in actions.

const agent = new HyperAgent({
  llm: llm,
  customActions: [GoToWikipediaActionDefinition],
});
PreviousMulti-Page actionsNextMCP Support

Last updated 1 month ago