AgentQL

The agentql module provides utility methods to set configurations, including the API key, and to convert Playwright's Page to AgentQL's Page, which gives access to AgentQL's querying API.

The following example demonstrates how to set the API key and wrap a Playwright Page object to use AgentQL's querying capabilities:

agentql_example.js
javascript
const { wrap, configure } = require('agentql'); 
const { chromium } = require('playwright');

(async () => {
  // Configure the API key
  configure({ apiKey: process.env.AGENTQL_API_KEY });

  const browser = await chromium.launch({ headless: false });
  const page = await wrap(await browser.newPage()); // Wraps the Playwright Page to access AgentQL's features.

  await page.goto('https://duckduckgo.com');

  const QUERY = `
  {
      search_box
      search_btn
  }
  `;

  const response = await page.queryElements(QUERY);
  await response.search_box.type('AgentQL');
  await response.search_btn.click();

  // Used only for demo purposes. It allows you to see the effect of the script.
  await page.waitForTimeout(10000);

  await browser.close();
})();

Methods

wrap

Wraps a Playwright Page instance to add AgentQL's querying methods. See AgentQL Page reference for API details.

Usage

agentql_example.ts
typescript
const agentqlPage = await wrap(await browser.newPage());

Arguments

Returns


configure

Configures the AgentQL service.

Usage

agentql_example.js
javascript
configure({ apiKey: 'YOUR_API_KEY' });

Arguments

  • options (object) - The configuration options. Supports the following options:
    • apiKey (string) - The API key for the AgentQL service.

Returns