AgentQL Documentation

repository·main·Indexed 23 days ago

https://github.com/tinyfish-io/agentql

AgentQL is a suite of tools enabling LLMs and AI agents to interact with the web using natural language queries. It features SDKs for Python and JavaScript, a REST API, and a browser extension for robust, self-healing web data extraction and automation. The JavaScript SDK (v1.0.0) supports methods like queryData() and getByPrompt() for tasks such as paginated data collection, interacting with UI interruptions, and automating logins.

Tokens
15.6K
Snippets
64
Records
98
Agent score
78%

What's inside AgentQL

  1. What is AgentQL?

    main

    AgentQL is a suite of tools designed to connect LLMs and AI agents to the web by enabling data extraction and workflow automation on live websites. It uses an AI-powered natural language query language to pinpoint data and elements on any web page, including those with authenticated or dynamically generated content.

    Key capabilities include:

    • Natural Language Selectors: Find elements intuitively based on page content.
    • Structured Output: Define the shape of your data directly within your queries.
    • Self-healing Queries: Resilience to UI changes over time.
    • Transforms: Apply data transformations directly within queries.
    • Cross-site Compatibility: Use the same query across different websites with similar content structures.
  2. Overview of AgentQL tools

    main

    AgentQL provides several interfaces for different development workflows:

    • Python SDK: For running automation and scraping scripts in Python.
    • JavaScript SDK: For running automation and scraping scripts in JavaScript.
    • REST API: For executing queries directly without using an SDK.
    • Integrations: Support for agent frameworks (e.g., Langchain), automation tools (e.g., Zapier), and an MCP server.
    • Debugger Browser Extension: A Chrome extension to debug and refine queries in real-time on live sites.
    • AgentQL Query Language: A natural language-based language for defining queries.
    • Playground: A web-based environment to test queries and export Python scripts.
  3. Adjust scrolling methods for dynamic content

    main

    When dealing with infinite scroll, a single scrolling method might not work for all websites due to multiple scrollable areas or custom key mappings. You can experiment with different interaction patterns to find the one that works for your target site.

    In the provided example, you can swap the scrolling mechanism by replacing the function call:

    • End Key Method: Uses key_press_end_scroll(page) to simulate pressing the End key.
    • Mouse Wheel Method: Use mouse_wheel_scroll(page) to simulate scrolling via the mouse wheel.

    Testing these different methods is recommended when page.goto navigates to a site with complex scroll behaviors.

  4. Run AgentQL in stealth mode to avoid bot detection

    main

    To lower the risk of being detected by anti-bot systems when using AgentQL, you can implement stealth mode techniques. This involves randomizing browser fingerprints and network characteristics to make automated requests appear more like organic human traffic.

    Key techniques include:

    • Randomizing HTTP Headers: Varying headers like User-Agent, Accept-Language, and Referer so consecutive requests do not look identical.
    • Randomizing Window Size: Changing the browser viewport dimensions to avoid detection via static window sizes.
    • Randomizing Timezone and Geolocation: Varying the browser's perceived location and time settings.
    • Using a Proxy Server (Optional): Routing traffic through an external proxy provider (e.g., NetNut or BrightData) using a host, username, and password configuration.
  5. Use a remote browser for AgentQL queries

    main
    You can execute AgentQL queries using a remotely hosted browser by connecting to it via the Chrome DevTools Protocol (CDP). This approach allows the browser to be managed externally while your script interacts with it. The script handles the allocation of the AgentQL Remote Browser, establishes the connection, and executes the query.
  6. Run the news aggregator sentiment analysis example

    main

    This example demonstrates how to use AgentQL to extract news headlines from a selection of URLs and save the results to a CSV file. To run this example:

    1. Install the AgentQL SDK.
    2. Save the provided JavaScript file locally as main.js.
    3. Execute the script using Node.js from your project folder.

    Note: While the title mentions sentiment analysis, the core logic of this specific script focuses on returning news headlines from URLs.

    node main.js