Frameworks

Connect Twin to LangChain or AutoGen

Register Twin Browser as a single tool in LangChain or AutoGen so your agent can act on the web — with compile-once economics instead of paying the model on every browser step.

If your agent already runs on LangChain or AutoGen, you do not need to rebuild it to give it a browser. Twin ships tool adapters for both, so the browser becomes one more tool your agent can call. This guide shows the minimal wiring for each.

How does Twin fit into a tool-using agent?

Both LangChain and AutoGen drive an LLM that decides which tools to call. You register a single Twin tool that takes a goal and a URL; when the agent decides it needs to act on the web, it calls that tool and Twin handles the browser. The agent's own model only chooses the goal — Twin's pipeline handles execution, and repeated calls hit the semantic cache.

Wiring up LangChain

Add the Twin tool to your agent's tool list. The adapter wraps a REST call to /api/v1/run (or /api/v1/dispatch for cache-first behavior) and returns the structured result to the agent.

LangChain toolpython
from langchain_core.tools import tool
import os, requests

@tool
def twin_browser(goal: str, url: str) -> dict:
    """Act on a web page: give a natural-language goal and a target URL."""
    r = requests.post(
        "https://twin-browser.com/api/v1/dispatch",
        headers={"Authorization": f"Bearer {os.environ['TWIN_API_KEY']}"},
        json={"goal": goal, "url": url},
        timeout=120,
    )
    r.raise_for_status()
    return r.json()

# agent = create_react_agent(llm, tools=[twin_browser])

Wiring up AutoGen

Register the same function as a callable tool on your AutoGen assistant. AutoGen will invoke it when the conversation calls for a browser action.

AutoGen toolpython
import os, requests
from autogen import AssistantAgent, register_function

def twin_browser(goal: str, url: str) -> dict:
    """Run a browser goal via Twin and return structured output."""
    r = requests.post(
        "https://twin-browser.com/api/v1/dispatch",
        headers={"Authorization": f"Bearer {os.environ['TWIN_API_KEY']}"},
        json={"goal": goal, "url": url}, timeout=120,
    )
    return r.json()

assistant = AssistantAgent("assistant", llm_config=llm_config)
register_function(twin_browser, caller=assistant, executor=user_proxy,
                  description="Act on a web page from a goal + URL.")

Why route through dispatch?

Pointing the adapter at /api/v1/dispatch makes every call cache-first: the first time the agent runs a task it compiles a skill, and every similar call after that replays deterministically with no LLM planning cost. Your agent's framework does not change — only the cost curve does.

Keep going

The mechanics behind this guide: the semantic dispatch cache, deterministic replay, and skill compilation. Plug Twin into MCP, LangChain, or the REST API, or see it applied to AI agents and RPA replacement. Weighing options? See how Twin compares.

Do I need a different key for LangChain vs AutoGen?
No. The same per-tenant Bearer API key works across REST, MCP, and both framework adapters. Authorization, billing, and audit logging are uniform across every entry point.
Will my agent framework see the cost savings automatically?
Yes, if you point the adapter at /api/v1/dispatch. Cache hits and deterministic replays happen inside Twin, transparently to LangChain or AutoGen.

Run your first skill

Compile a task once, then replay it deterministically with zero LLM calls. Start free.