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_taskand 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
pip install "langchain[mcp]" deepagents langchain-openainpm install @langchain/mcp-adapters@^2.0.0 @langchain/core @langchain/langgraph deepagents @langchain/openaiThe 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.
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())import { MCPAdapter } from "@langchain/mcp-adapters";
import { createDeepAgent } from "deepagents";
const adapter = new MCPAdapter({
servers: { pilotfish: { command: "npx", args: ["-y", "@gaiventures/pilotfish-mcp"] } },
});
try {
const tools = await adapter.listTools();
const agent = createDeepAgent({ model: "openai:gpt-6.1-sol", tools });
const result = await agent.invoke({
messages: [{ role: "user", content: "On news.ycombinator.com, list the top 3 stories with their points." }],
});
console.log(result.messages.at(-1)?.text);
} finally {
await adapter.close();
}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).
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())import { MCPAdapter } from "@langchain/mcp-adapters";
import { createDeepAgent } from "deepagents";
const adapter = new MCPAdapter({
servers: {
pilotfish: {
url: "https://pilotfish-be.gai.ventures/mcp",
headers: { Authorization: `Bearer ${process.env.PILOTFISH_KEY}` },
},
},
});
try {
const tools = await adapter.listTools();
const agent = createDeepAgent({ model: "openai:gpt-6.1-sol", tools });
const result = await agent.invoke({
messages: [{ role: "user", content: "Use browser_task: find the cheapest nonstop SFO to JFK this Friday on Google Flights." }],
});
console.log(result.messages.at(-1)?.text);
} finally {
await adapter.close();
}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
- Model Context Protocol in LangChain: transports, connections and authentication for
MCPAdapter. - Browser use in Deep Agents: browser scope, sandboxes and keeping sessions safe.