LangChain Integration
AgentQL integrates with LangChain, allowing you to both extract data and take actions on the web.
LangChain helps to perform AI-powered research, workflow automation, and hands-free online interactions.
Set up AgentQL with LangChain
- Run the following command in your terminal to install LangChain:
pip install langchain
- Install a language model for your app to get started with:
pip install -qU "langchain[openai]"
- Create a new file
main.py
to instantiate your LLM containing the following:
import getpass
import os
from langchain.chat_models import init_chat_model
if not os.environ.get("OPENAI_API_KEY"):
os.environ["OPENAI_API_KEY"] = getpass.getpass("Enter API key for OpenAI: ")
model = init_chat_model("gpt-4o-mini", model_provider="openai")
- Install AgentQL's tools:
pip install -U langchain-agentql
- Configure AgentQL
Configure the AGENTQL_API_KEY
environment variable by running the command below in the terminal. You can get an AgentQL API key here.
export AGENTQL_API_KEY=<YOUR_AGENTQL_API_KEY>
- In the
main.py
file, import AgentQL's tools:
from langchain_agentql.tools import ExtractWebDataTool, ExtractWebDataBrowserTool, GetWebElementBrowserTool
You can now start building your first app on LangChain with AgentQL!
Usage
AgentQL provides the following three tools:
AgentQL also provides AgentQLBrowserToolkit
that bundles ExtractWebDataBrowserTool
and GetWebElementBrowserTool
together. These two tools require a Playwright browser but ExtractWebDataTool
doesn't. ExtractWebDataTool
calls a REST API.
How to use AgentQL's AgentQLBrowserToolkit
- Instantiate your Playwright browser instance:
from langchain_agentql.utils import create_async_playwright_browser
async_browser = await create_async_playwright_browser()
- Choose the Playwright tools you would like to use:
from langchain_community.tools.playwright import NavigateTool, ClickTool
playwright_toolkit = [
NavigateTool(async_browser=async_agent_browser),
ClickTool(async_browser=async_agent_browser, visible_only=False)
]
playwright_toolkit
You can learn more about the AgentQL tools available and their usage in the AgentQL documentation on LangChain's site.
Support
If you have any questions about using AgentQL with LangChain, you can join the LangChain community.