Skip to main content
The langchain-anchorbrowser package gives LangChain agents tools that read web pages, take screenshots, and run AI web tasks in Anchor Browser. It requires Python 3.10 or later, langchain-core 1.0 or later, and the anchorbrowser SDK 1.0 or later.

Quickstart

1

Install the packages

langchain provides create_agent. langchain-openai is the model provider for this example. You can use any LangChain chat model instead. The -U flag upgrades packages that are already installed.
2

Set your API keys

Get an Anchor API key from the API keys page.
3

Run an agent

agent.py
The agent prints an answer such as The first book listed on https://books.toscrape.com is "A Light in the Attic".

Call the tools directly

Each tool is a LangChain tool, so you can call it with invoke, without an agent.
tools.py
Leave AnchorScreenshotTool out of an agent’s tools. Its base64 output is large and is not useful as text in a model’s context.

Available tools

AnchorWebTaskToolKit bundles the three web task tools. AnchorTaskToolKit bundles the six task tools. The screenshot and web task tools open a browser session for each call and close it when the call ends, even if the call fails. AnchorContentTool does not open a session. The web task tools return only the task’s result. When the task fails, the result holds the reason for the failure.

Upgrade from 0.2

Version 0.3.0 requires LangChain 1.x and the anchorbrowser 1.x SDK, so the upgrade also moves your environment to those versions. To upgrade, run the pip install -U command from the quickstart. In LangChain 1.x, LangGraph’s create_react_agent is deprecated. Build agents with create_agent from langchain.agents. Version 0.3.0 changes these tool behaviors:
  • AnchorContentTool returns the page’s HTML, not Markdown. It no longer has a format option, and it ignores a format value.
  • AnchorScreenshotTool returns a base64 string. Decode it with base64.b64decode before you save it.
  • The web task tools return the task result as a JSON string. The task tools return the API’s JSON response body.
  • The screenshot and web task tools close the browser sessions that they open.

Additional resources