LlamaIndex Integration

AgentQL integrates with LlamaIndex, allowing you to build RAG (Retrieval-Augmented Generation) models and AI assistants for AI-powered search and decision making.

LlamaIndex is a leading framework for building LLM-powered agents over data with LLMs and workflows.

Setup AgentQL with LlamaIndex

  1. Start a new Python virtual environment and run the following command in your terminal to install LlamaIndex:
terminal
pip install llama-index
  1. Since LlamaIndex uses the OpenAI gpt-3.5-turbo model by default, you need to set up an OPENAI_API_KEY as an environment variable to use the model.
terminal
export OPENAI_API_KEY=<YOUR_OPENAI_API_KEY>
  1. Install AgentQL's tools:
terminal
pip install llama-index-tools-agentql
  1. Configure the AGENTQL_API_KEY environment variable. You can get an AgentQL API key here.
terminal
export AGENTQL_API_KEY=<YOUR_AGENTQL_API_KEY>
  1. Create a new Python file main.py and import AgentQL's tools:
# for importing extract_web_data_with_rest_api
from llama_index.tools.agentql import AgentQLRestAPIToolSpec

# for importing extract_web_data_from_browser and get_web_element_from_browser
from llama_index.tools.playwright.base import PlaywrightToolSpec

You can now start building your first app on LlamaIndex with AgentQL!

Usage

AgentQL provides the following three tools:

In order to use the extract_web_data_from_browser and get_web_element_from_browser, you need to have a Playwright browser instance.

How to use AgentQL's AgentQLBrowserToolSpec

  1. Install Playwright on LlamaIndex:
terminal
pip install llama-index-tools-playwright
  1. Instantiate your Playwright browser instance:
from llama_index.tools.playwright.base import PlaywrightToolSpec
async_browser = await PlaywrightToolSpec.create_async_playwright_browser()
  1. Choose the Playwright tools you would like to use:
playwright_tool_list = playwright_tool.to_tool_list()
playwright_agent_tool_list = [tool for tool in playwright_tool_list if tool.metadata.name in ["click", "get_current_page", "navigate_to"]]
  1. Instantiate AgentQLBrowserToolSpec:
from llama_index.tools.agentql import AgentQLBrowserToolSpec
agentql_browser_tool = AgentQLBrowserToolSpec(async_browser=async_browser)

You can learn more about the AgentQL tools available and their usage in the here.

Support

If you have any questions about using AgentQL with LlamaIndex, you can join LlamaIndex's community