Agent framework integration
Twin Browser + 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.
How Twin plugs into LangGraph
This is the difference that matters in LangGraph: Twin does not have to be a tool the model chooses — it can be a NODE the graph always runs. A node is a function, so the browser step becomes a deterministic edge in your graph with a known cost, sitting outside the model loop entirely. Point it at `/api/v1/skills/{name}/run` once the flow is compiled and that node makes no model call at all; keep it on `/api/v1/run` while the flow is still being figured out.
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.
What you get through LangGraph
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 LangGraph.
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 langgraph.graph import StateGraph, MessagesState, START, END
TWIN = "https://twin-browser.com/api/v1"
def browser_step(state: MessagesState):
"""A deterministic node: no model call, one browser task."""
r = requests.post(
f"{TWIN}/run",
headers={"Authorization": f"Bearer {os.environ['TWIN_API_KEY']}"},
json={
"url": "https://app.acme.com/billing",
"prompt": "Sign in and download the latest invoice as CSV",
"success": {"kind": "textVisible", "value": "Invoice"},
},
timeout=300,
).json()
return {"messages": [{"role": "ai", "content": str(r.get("result"))}]}
graph = StateGraph(MessagesState)
graph.add_node(browser_step)
graph.add_edge(START, "browser_step")
graph.add_edge("browser_step", END)
app = graph.compile()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 LangGraph
pip install langgraph. Nothing Twin-specific is installed.
Write the node
A node is a function over state — have it POST to /api/v1/run and write the result back into state.
Wire the graph
add_node, add_edge from START, and compile. The browser step now runs deterministically in the graph.
Swap in a replay
Once the goal is compiled, point the node at /api/v1/skills/{name}/run so it costs no model call.
FAQ
LangGraph on Twin — common questions
Should Twin be a node or a tool in LangGraph?
What happens if the run hits a 2FA wall inside a graph?
Related
More ways to connect Twin
- Agent framework
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.
- Language
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.
- API
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.
Integrations
Wire up LangGraph 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.