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.
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.
- Receive goal from Haystackdone
- Compile DOM → token-efficient indexed statedone
- Match the semantic dispatch cacherunning
- Replay compiled skill — 0 LLM callsqueued
What you get through Haystack
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 Haystack.
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 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.
Install Haystack
pip install haystack-ai. Nothing Twin-specific is installed.
Write the callable
A plain function that POSTs { url, prompt, success } to /api/v1/run.
Wrap it in a Tool
Construct Tool(name=…, description=…, parameters=…, function=…), or use the @tool decorator to generate the schema.
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?
Can I restrict which sites the tool may touch?
Related
More ways to connect Twin
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.
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.
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 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.