---
title: Connect AgentKit with a TestingBot remote browser
description: Use AgentKit to create an AI agent with access to a remote TestingBot
  browser.
source_url:
  html: https://testingbot.com/support/ai/integrations/agentkit
  md: https://testingbot.com/support/ai/integrations/agentkit/index.md
---
# Using AgentKit with TestingBot

Create AI agents that can run browser automation tasks using TestingBot's remote browser grid and AgentKit (by inngest).

## Dependencies

To install all dependencies, please follow these steps:

[npm](https://testingbot.com#)[pnpm](https://testingbot.com#)[yarn](https://testingbot.com#)

    npm install @inngest/agent-kit playwright-core

    pnpm add @inngest/agent-kit playwright-core

    yarn add @inngest/agent-kit playwright-core

## Create a TestingBot service

In the example below, we'll show an example tool that will use Algolia to search Hacker News (HN) posts. The TestingBot remote browser grid will be used to perform the actions and return the results.

The example below uses the `chromium.connect` method to connect to a remote browser in the TestingBot cloud.

There are a lot of [Playwright Options](https://testingbot.com/support/web-automate/playwright/options) you can use to customize the browser session.

Make sure to replace `key` and `secret` with your TestingBot API key and secret.

    import "dotenv/config";
    import {
      anthropic,
      createAgent,
      createNetwork,
      createTool,
    } from "@inngest/agent-kit";
    import { createServer } from "@inngest/agent-kit/server";
    import { z } from "zod";
    import { chromium } from "playwright-core";
    
    const testingBotKey = process.env.TESTINGBOT_KEY;
    const testingBotSecret = process.env.TESTINGBOT_SECRET;
    
    const searchHN = createTool({
      name: "search_hn",
      description: "Search HN posts and comments",
      parameters: z.object({
        query: z.string().describe("The search query for HN"),
      }),
      handler: async ({ query }, { step }) => {
        return await step?.run("search-on-hn", async () => {
          const browser = await chromium.connect({
            wsEndpoint: `wss://cloud.testingbot.com/playwright?key=${testingBotKey}&secret=${testingBotSecret}&browserName=chrome&browserVersion=latest`,
          });
          try {
            const page = await browser.newPage();
    
            // Construct the search URL
            const searchUrl = `https://hn.algolia.com/?dateRange=all&page=0&prefix=false&query=${query}&sort=byPopularity&type=story`;
    
            await page.goto(searchUrl);
    
            // Wait for results to load
            await page.waitForSelector(".SearchResults", { timeout: 10000 });
    
            // Extract search results
            const results = await page.evaluate(() => {
              const posts = document.querySelectorAll(".SearchResults .Story");
              return Array.from(posts).map((post) => ({
                title: post.querySelector(".Story_title span")?.textContent?.trim(),
              }));
            });
    
            return results.slice(0, 5); // Return top 5 results
          } finally {
            await browser.close();
          }
        });
      },
    });
    
    // Create the search agent
    const searchAgent = createAgent({
      name: "hn_searcher",
      description: "An agent that searches HN for relevant information",
      system:
        "You are a helpful assistant that searches HN through algolia for relevant information.",
      tools: [searchHN],
    });
    
    // Create the network
    const hnSearchNetwork = createNetwork({
      name: "hn-search-network",
      description: "A network that searches HN using TestingBot",
      agents: [searchAgent],
      maxIter: 2,
      defaultModel: anthropic({
        model: "claude-sonnet-4-5",
        defaultParameters: {
          max_tokens: 4096,
        },
      }),
    });
    
    // Create and start the server
    const server = createServer({
      networks: [hnSearchNetwork],
    });
    
    server.listen(3010, () =>
      console.log("HN Search Agent server is running on port 3010")
    );

Was this page helpful? Yes No 

## Looking for More Help?

Have questions or need more information?   
 You can reach us via the following channels:

- [Email us](https://testingbot.com/contact/new)
- [Join our Slack Channel](https://join.slack.com/t/testingb0t/shared_invite/zt-3bcw9xch-jk19~6XPs_xBrsAgAedkCw)
