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.
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.
- Receive goal from LangChaindone
- Compile DOM → token-efficient indexed statedone
- Match the semantic dispatch cacherunning
- Replay compiled skill — 0 LLM callsqueued
What you get through LangChain
Every integration is a thin wrapper over the same execution layer, so the cache, the replay, and the corpus apply no matter how you call in.
Semantic dispatch cache
A re-phrased goal fuzzy-matches an already-compiled skill, so most calls never touch the LLM.
Deterministic replay
A compiled skill replays the exact action path with zero LLM calls — fast, repeatable, cheap.
Cross-tenant skill corpus
A skill compiled once can be safely reused across tenants, so the hit rate climbs as the network runs.
One Bearer key
Auth, usage-based billing, and an audit log run on every call — the same key works from every integration.
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.
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.
Install LangChain
pip install langchain plus your model provider package. Nothing Twin-specific is installed.
Set your key
Export TWIN_API_KEY with a key from the dashboard.
Define the tool
Decorate a function that POSTs { url, prompt, success } to /api/v1/run with @tool from langchain.tools.
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?
How is this cheaper than driving a browser from the agent loop?
Related
More ways to connect Twin
LangGraph
LangGraph is LangChain’s low-level orchestration library: you build an explicit state graph of nodes and edges, compile it, and invoke it. Nodes are plain functions over the graph state, so a node does not have to involve a model at all.
Python
Python is where most agent code lives — LangChain, LlamaIndex, CrewAI, AutoGen, Pydantic AI and the OpenAI and Anthropic SDKs are all Python-first. Anything you can express as a function call, an agent can be given as a tool.
REST API
Twin’s REST API is the universal integration path: HTTPS endpoints under `/api/v1/*`, authenticated with a Bearer key. Any language that can make an HTTP request can drive the browser execution layer — no SDK required, and none is published.
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.