Agent framework integration

Twin Browser + LlamaIndex

LlamaIndex is a data framework for LLM applications — indexing, retrieval and agents over your own content. Its agents call tools, and `FunctionTool.from_defaults` turns any Python function into one, taking the name and description from the function and its docstring.

Agent framework4-step setupBearer key auth

How Twin plugs into LlamaIndex

LlamaIndex is strongest on content you already have. Twin is how the content gets there when it lives behind a login: a `FunctionTool` wrapping `/api/v1/run` lets an agent sign into a portal and pull the document, and `/api/v1/extract` returns structured JSON from a page without an action. Index the result as you would any other source — and when the same fetch repeats, compile it into a skill so the retrieval step stops paying a planner.

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 LlamaIndexdone
  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 LlamaIndex.

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

LlamaIndex — Twin as a FunctionToolpython
import os, requests
from llama_index.core.tools import FunctionTool

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

def twin_run(url: str, prompt: str) -> str:
    """Useful for fetching content from a page that requires signing in."""
    r = requests.post(
        f"{TWIN}/run",
        headers={"Authorization": f"Bearer {os.environ['TWIN_API_KEY']}"},
        json={"url": url, "prompt": prompt, "success": {"kind": "extracted"}},
        timeout=300,
    )
    return str(r.json())

twin_tool = FunctionTool.from_defaults(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 LlamaIndex

    pip install llama-index. Nothing Twin-specific is installed.

  2. Write the function

    A plain function that POSTs to /api/v1/run, with a docstring the model will read as the tool description.

  3. Wrap it

    FunctionTool.from_defaults(twin_run) turns it into a tool.

  4. Give it to an agent

    Pass the tool into your agent; index whatever it returns.

FAQ

LlamaIndex on Twin — common questions

Should I use /run or /extract for indexing?
Use /extract when the page is reachable and you only want structured data off it — a matching extraction template can return that deterministically, with no LLM cost at all. Use /run when getting to the page is the hard part: a login, a form, several steps.
Does Twin store the content it retrieves?
Twin has its own ETL endpoints that chunk, embed and load content into a queryable store, but nothing forces you through them — a plain /run or /extract returns the result and you index it wherever you like.

Wire up LlamaIndex 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.