DocsIntegrations

pilotfish with LangChain and Deep Agents

Give a LangChain or Deep Agents agent a real browser through LangChain's MCP adapter: the open MCP for Chrome on your own machine, or the managed MCP for whole tasks in pilotfish's cloud browser.

Which server

  • Open MCP (free, MIT): your agent drives Chrome step by step with the browser_* tools. Each screen reaches the model once, then only what changed after each action, so a browser step costs few tokens. The browser window opens on the machine the agent runs on, and you handle sign-ins and CAPTCHAs in it.
  • Managed MCP: your agent hands a whole task to browser_task and gets the answer back in a call or two, run in pilotfish's cloud browser with your saved logins, two-factor codes and a live view. Paid from your organization's credits; it needs an API key.

Install

Terminalsh
pip install "langchain[mcp]" deepagents langchain-openai

The open MCP also needs Node.js 22 or newer and Google Chrome (or another Chromium browser) on the machine the agent runs on. Use any chat model LangChain supports; the examples use OpenAI.

Open MCP

LangChain's MCPAdapter starts the server over stdio and turns its tools into LangChain tools for create_deep_agent or create_agent.

agent.pypython
import asyncio

from deepagents import create_deep_agent
from langchain.mcp import MCPAdapter

# On Windows, use "npx.cmd" as the command.
config = {"mcpServers": {"pilotfish": {"command": "npx", "args": ["-y", "@gaiventures/pilotfish-mcp"]}}}


async def main():
    async with MCPAdapter(config) as adapter:
        tools = await adapter.list_tools()
        agent = create_deep_agent(model="openai:gpt-6.1-sol", tools=tools)
        result = await agent.ainvoke(
            {"messages": [{"role": "user", "content": "On news.ycombinator.com, list the top 3 stories with their points."}]},
            config={"configurable": {"thread_id": "1"}},
        )
        print(result["messages"][-1].content)


asyncio.run(main())

Keep the adapter open for the whole run: the browser lives in the server process, and closing the adapter closes it. In JavaScript the adapter prefixes tool names with the server's name (pilotfish_browser_navigate). When a page needs a person, a tool result says NEEDS A PERSON: do it in the browser window, and the agent carries on with browser_resume. Settings such as PILOTFISH_HEADLESS go in an env entry next to args (see Settings).

Managed MCP

Connect to the endpoint over Streamable HTTP with an API key from Org settings → API keys (see Keys and sign-in).

agent.pypython
import asyncio
import os

from deepagents import create_deep_agent
from fastmcp.client import Client
from langchain.mcp import MCPAdapter


async def main():
    client = Client("https://pilotfish-be.gai.ventures/mcp", auth=os.environ["PILOTFISH_KEY"])
    async with MCPAdapter(client) as adapter:
        tools = await adapter.list_tools()
        agent = create_deep_agent(model="openai:gpt-6.1-sol", tools=tools)
        result = await agent.ainvoke(
            {"messages": [{"role": "user", "content": "Use browser_task: find the cheapest nonstop SFO to JFK this Friday on Google Flights."}]},
            config={"configurable": {"thread_id": "1"}},
        )
        print(result["messages"][-1].content)


asyncio.run(main())

Send the whole web task to browser_task in one call: pilotfish plans it, signs in, carries values between sites and checks the result. Each result starts with a status word and ends with the task's cost. A task that needs a code, a sign-in or your yes pauses with a link to answer it (see When a task needs you).

More from LangChain