Agent framework integration

Twin Browser + LangChain

LangChain is a Python and JavaScript framework for building LLM applications — chains, agents, and tools. Its agent loop lets a model pick a tool, observe the result, and decide the next action, which makes browser access a natural tool to add.

Agent framework3 MCP tools: run · compile_skill · run_skillBearer key auth

How Twin plugs into LangChain

Twin provides a LangChain tool adapter that wraps the REST API as a single `Tool` your agent can call. The agent passes a natural-language goal; Twin compiles it once, then serves the next similar request from the semantic dispatch cache. You keep LangChain’s orchestration and offload the expensive part — re-running the LLM to drive the browser on every step — to Twin’s compile-once execution layer.

Twin is the browser execution layer your stack calls. The first run cold-compiles a skill; every similar request after that is matched from the cache and replayed deterministically, so your marginal cost per run trends toward zero.

app.example.com
  1. Receive goal from LangChaindone
  2. Compile DOM → token-efficient indexed statedone
  3. Match the semantic dispatch cacherunning
  4. Replay compiled skill — 0 LLM callsqueued
Wire it up

Drop Twin into LangChain

Copy, paste, and swap in your Bearer key. The first run compiles a skill; repeats hit the semantic dispatch cache and replay deterministically.

LangChain — add Twin as a toolpython
from langchain.agents import initialize_agent
from twin_browser.langchain import TwinBrowserTool

# One line: Twin's execution layer as a LangChain tool.
twin = TwinBrowserTool(api_key="tw_live_xxx")

agent = initialize_agent(
    tools=[twin],
    llm=your_llm,
    agent="zero-shot-react-description",
)

# The agent calls twin.run(goal=..., url=...). The first run compiles a
# skill; the next re-phrased request is matched from the semantic cache.
agent.run("Log into the billing portal and download the latest invoice")

Base URL https://twin-browser.com/api/v1 · auth Authorization: Bearer tw_live_… · MCP tools run, compile_skill, run_skill.

Get started

Connect LangChain in 4 steps

Install → configure your key → make the first call. The cache takes over from there.

  1. 1
    Install the adapter

    pip install twin-browser; it ships a ready-made LangChain Tool.

  2. 2
    Set your key

    Export TWIN_API_KEY with a key from the dashboard.

  3. 3
    Add the tool

    Pass TwinBrowserTool() into your agent’s tool list.

  4. 4
    Run the agent

    The agent calls the tool with a goal; repeats hit the cache automatically.

Why this stays cheap at scale

Most browser infrastructure re-runs the LLM on every execution, so cost climbs with usage. Twin compiles a task once via skill compilation, matches re-phrased requests to it, and replays without the model — so repeated workflows stop scaling with your token bill.

FAQ

LangChain on Twin — common questions

Does the LangChain adapter support both sync and async?
Yes. The tool exposes synchronous and async run methods, so it drops into both AgentExecutor and the async LangGraph runtimes.
How is this cheaper than driving a browser from LangChain directly?
Driving a browser from the agent loop pays the model on every step. Twin compiles the successful path once and replays it deterministically, so repeated workflows stop scaling with your token bill.

Wire up LangChain in minutes

Free to start. Usage-based credits from $29/mo, with LLM cost metered and passed through at 1×.