Agent framework integration

Twin Browser + Haystack

Haystack is deepset’s open-source framework for LLM pipelines and agents. Its `Tool` class wraps any Python callable with a name, a description and a JSON-schema `parameters` object, and there is a `@tool` decorator that generates the schema from your function signature.

Agent framework4-step setupBearer key auth

How Twin plugs into Haystack

Haystack pipelines are usually built over content you can already reach. Twin extends that to content you cannot: wrap `/api/v1/run` in a `Tool` and a Haystack agent can sign into a portal, run a multi-step flow and hand the structured result back into the pipeline. Because the schema is explicit, you can constrain exactly what the model is allowed to ask the browser to do.

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 Haystackdone
  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 Haystack.

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

Haystack — Twin as a Toolpython
import os, requests
from haystack.tools import Tool

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

def twin_run(url: str, prompt: str) -> str:
    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())

parameters = {
    "type": "object",
    "properties": {
        "url": {"type": "string", "description": "Page to start from."},
        "prompt": {"type": "string", "description": "What to do there."},
    },
    "required": ["url", "prompt"],
}

twin_tool = Tool(
    name="twin_run",
    description="Perform a task in a real browser on an authorized URL.",
    parameters=parameters,
    function=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 Haystack

    pip install haystack-ai. Nothing Twin-specific is installed.

  2. Write the callable

    A plain function that POSTs { url, prompt, success } to /api/v1/run.

  3. Wrap it in a Tool

    Construct Tool(name=…, description=…, parameters=…, function=…), or use the @tool decorator to generate the schema.

  4. Attach it

    Pass the tool to your agent or tool-invoking component and run the pipeline.

FAQ

Haystack on Twin — common questions

Do I have to write the parameters schema by hand?
No — Haystack ships a @tool decorator and a create_tool_from_function helper that generate it from your signature. The explicit form is shown here because it makes the contract with the model visible, which is usually what you want around a tool that can act on the web.
Can I restrict which sites the tool may touch?
Validate the url argument in your own function before calling Twin — that is the enforcement point closest to your code. Twin separately treats the target URL you pass as the authorization signal and audit-logs every call.

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