Agent framework integration

Twin Browser + OpenAI Agents SDK

The OpenAI Agents SDK is a lightweight Python framework for agentic applications — agents, handoffs, guardrails and sessions. Alongside function tools it can connect to MCP servers, including ones it launches itself as a local subprocess over stdio.

Agent framework4-step setupBearer key auth

How Twin plugs into OpenAI Agents SDK

This is the cleanest wiring on the page, because it needs no adapter at all: the Agents SDK launches `twin-browser-mcp` with `MCPServerStdio` and every one of Twin’s 31 tools becomes available to the agent. No tool schemas to write, no request bodies to keep in sync — the server publishes them. Pass your key in the subprocess env and the agent can run goals, compile skills, replay them, take screenshots, extract structured data and resume a paused run.

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 OpenAI Agents SDKdone
  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 OpenAI Agents SDK.

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

OpenAI Agents SDK — Twin over MCP stdiopython
import os
from agents import Agent, Runner
from agents.mcp import MCPServerStdio

async with MCPServerStdio(
    name="Twin Browser",
    params={
        "command": "npx",
        "args": ["-y", "twin-browser-mcp"],
        "env": {"TWIN_API_KEY": os.environ["TWIN_API_KEY"]},
    },
) as twin:
    agent = Agent(
        name="Ops assistant",
        instructions="Use the twin-browser tools for anything on the web.",
        mcp_servers=[twin],
    )
    result = await Runner.run(agent, "Download last month's invoice from the billing portal.")
    print(result.final_output)

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 the SDK

    pip install openai-agents. Node 20+ must be on PATH so npx can launch the MCP server.

  2. Get an API key

    Create an ab_live_ key in the Twin dashboard under Keys & Secrets.

  3. Launch the server

    Wrap MCPServerStdio around npx -y twin-browser-mcp, passing TWIN_API_KEY in the params env.

  4. Attach it to an agent

    Pass the server in mcp_servers=[...]; the agent discovers all 31 tools on connect.

FAQ

OpenAI Agents SDK on Twin — common questions

Can I connect to Twin over hosted MCP instead of stdio?
The Twin MCP server is the npm package `twin-browser-mcp` and it speaks stdio — your client launches it with `npx -y twin-browser-mcp` and passes `TWIN_API_KEY` in the env. There is no hosted HTTP or SSE MCP endpoint to point a URL at; every tool routes through the same `/api/v1` REST surface using your key.
Should I use MCP or a function tool here?
MCP, unless you want to expose exactly one narrow capability. Over MCP the tool schemas come from the server, so they stay correct when the surface changes; a hand-written function tool is one more thing to keep in sync.

Wire up OpenAI Agents SDK 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.