Agent framework integration

Twin Browser + LangChain

LangChain is a Python and JavaScript framework for building LLM applications. 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 framework4-step setupBearer key auth

How Twin plugs into LangChain

There is no Twin LangChain package to install; the integration is one `@tool`-decorated function that posts to `/api/v1/run`. LangChain keeps the orchestration and Twin takes the expensive part — planning and driving the browser — off the agent loop. Once a goal succeeds reliably, compile it and point the tool at `/api/v1/dispatch` instead: a re-worded request then matches the compiled skill through the semantic cache rather than re-planning from scratch.

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

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 match the semantic dispatch cache and replay deterministically.

LangChain — Twin as a toolpython
import os, requests
from langchain.tools import tool
from langchain.agents import create_agent

TWIN = "https://twin-browser.com/api/v1"

@tool
def twin_run(url: str, prompt: str) -> dict:
    """Perform a task in a real browser on an authorized URL.

    Args:
        url: The page to start from.
        prompt: What to do there, in plain language.
    """
    return requests.post(
        f"{TWIN}/run",
        headers={"Authorization": f"Bearer {os.environ['TWIN_API_KEY']}"},
        json={"url": url, "prompt": prompt, "success": {"kind": "extracted"}},
        timeout=300,
    ).json()

agent = create_agent(model, tools=[twin_run])

Base URL https://twin-browser.com/api/v1 · auth Authorization: Bearer ab_live_… · over MCP the same engine is run_goal, compile_skill and run_skill — the full tool table.

  1. Install LangChain

    pip install langchain plus your model provider package. Nothing Twin-specific is installed.

  2. Set your key

    Export TWIN_API_KEY with a key from the dashboard.

  3. Define the tool

    Decorate a function that POSTs { url, prompt, success } to /api/v1/run with @tool from langchain.tools.

  4. Give it to the agent

    Pass the tool into create_agent. The model calls it when the task needs a browser.

FAQ

LangChain on Twin — common questions

Is there an official Twin Browser LangChain package?
No, and there is no pip install for one. The integration is a normal LangChain tool wrapping the REST API — the six lines above are the entire adapter, which is also why it keeps working when LangChain changes its agent constructors.
How is this cheaper than driving a browser from the agent loop?
A browser tool inside the loop pays your model on every step it takes. Twin plans once, compiles the successful path into a skill, and replays it — so the repeated part of the workflow stops scaling with your token bill.

Wire up LangChain in minutes.

Free to start. Usage-based credits from $29/mo — each call billed the higher of its flat action price or its metered cost.