agentql JavaScript SDK reference
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:
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
typescript
const agentqlPage = await wrap(await browser.newPage());
Arguments
page
Playwright's Page
Returns
- Promise<AgentQL Page> - The wrapped Page object with AgentQL extensions.
configure
Configures the AgentQL service.
Usage
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.