Repository navigation
feat(agents): add browserTool and export Browser for a persistent browser - #2372
Merged
ben-reitz merged 4 commits intoOct 1, 2026
Merged
Conversation
ben-reitz
added this pull request to stack #2373
September 25, 2026 08:21
🦋 Changeset detectedLatest commit: f2663c8 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
🟡 agents import sizes: 2 entry points grew
Changed exports (5)
How this worksEach runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement. Compared |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
This was referenced Sep 25, 2026
ben-reitz
force-pushed
the
feat/browser-execute-tool
branch
from
September 25, 2026 09:13
29b86ec to
41a4c01
Compare
ben-reitz
force-pushed
the
feat/browser-execute-tool
branch
4 times, most recently
from
September 25, 2026 13:48
29740e1 to
f17efd9
Compare
ben-reitz
force-pushed
the
feat/browser-execute-tool
branch
4 times, most recently
from
September 28, 2026 09:40
dbbdcd8 to
c63d7c3
Compare
ben-reitz
marked this pull request as ready for review
September 28, 2026 09:40
ben-reitz
force-pushed
the
feat/browser-execute-tool
branch
2 times, most recently
from
September 28, 2026 12:29
9edf929 to
24f8940
Compare
aron-cf
approved these changes
Sep 28, 2026
aron-cf
left a comment
Contributor
There was a problem hiding this comment.
This looks great, some minor feedback about docs and naming.
ben-reitz
removed this pull request from stack #2373
September 29, 2026 13:34
ben-reitz
added this pull request to stack #2412
September 29, 2026 13:36
ben-reitz
force-pushed
the
feat/browser-execute-tool
branch
from
September 29, 2026 13:36
24f8940 to
8bcafa6
Compare
ben-reitz
force-pushed
the
feat/browser-execute-tool
branch
from
September 30, 2026 09:25
8bcafa6 to
81df3ad
Compare
ben-reitz
force-pushed
the
feat/browser-execute-tool
branch
from
October 1, 2026 10:08
f00f590 to
cd8d15d
Compare
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
TL;DR: This ships the public API:
browserToolfor the AI SDK (including Think or yourAgentclass)Browseris exported, so agents get a browser whose tabs and logins carry over between runs.Next:
help(topic)inside the sandbox, plus a skill file.cdp.spec()for exact parameters.createBrowserToolsas@deprecated, which hasn't been done yet.This PR
This adds
browserToolinagents/browser/ai, plus theBrowserandbrowserRunexports fromagents/browser. Both are experimental and ship with a minor changeset.The host owns the
Browser, so a tool rebuilt every turn reaches the same browser. Tabs, cookies, and logins carry over until Browser Run shuts down an idle browser.browserToolreturns one AI SDK tool, not a{ browser_execute }object, so the host picks its name (same asagentTool()).What the model gets back
{ executionId, result, logs, calls } // calls are persisted, not shown to the model + restarted: true, notice: "…navigate again…" // the browser was replaced before this run + newTabs: [{ targetId, url, title }] // tabs the page openedScreenshot summaries include the notice and
newTabsas well.Types
The tool is typed:
BrowserToolhasexecute(input: { code }): Promise<BrowserToolOutput>andtoModelOutput, and fits in aToolSetorTool<{ code: string }, BrowserToolOutput>.BrowserToolOptions,BrowserToolInput,BrowserToolOutput, andBrowserNewTabare exported. The test helper no longer needs casts, andbrowser-tool.test-d.tschecks the types.Compared with existing
createBrowserToolscreateBrowserToolsbrowserToolBrowser)cdpUrl, KitesurfcreateQuickActionToolscreateBrowserToolsis unchanged. It gets deprecated in a later PR.Details
Browsergets its own codemode runtime (browser-tool_<name>), so its history never mixes withcreateBrowserToolsor other browsers.ctxis optional. It's resolved from the current Agent when not passed.createBrowserTools. The worker exportsCodemodeRuntime, which is re-exported fromagents/browser. The test worker gains a facet-onlyCodemodeRuntimebinding.docs/agents/browse-the-web.md, which the one-line changeset links to.design/browser-sessions.mdanddesign/browser-tools.mdare rewritten in plainer language.Tests
End-to-end on a real Agent and codemode facet (
browser-capability.test.ts):Not in this PR: Think, TanStack AI, and Flue wrappers; CDP recipes.
Architecture diff
Outlined boxes are components this PR changes, with one green box per change. Green-filled boxes are new. Grey boxes are unchanged.
flowchart TB classDef ctx fill:none,stroke:#8c959f,color:#8c959f classDef changes fill:#dafbe1,stroke:#1a7f37,color:#1f2328 Agent["Agent (host Durable Object)"]:::ctx subgraph Tool["browserTool · ai.ts (new)"] direction TB T1["+ one typed AI SDK tool; the host names it"]:::changes T2["+ one codemode runtime per browser"]:::changes T3["+ adds restarted, notice, newTabs to results"]:::changes T1 ~~~ T2 ~~~ T3 end Runtime["codemode runtime + sandbox"]:::ctx Conn["BrowserSessionConnector · session-connector.ts"]:::ctx subgraph B["Browser · browser.ts"] B1["+ exported from agents/browser with browserRun and its types"]:::changes end BR["Browser Run"]:::ctx Agent -->|"getTools()"| Tool Agent -->|lifecycle.use| B Tool --> Runtime Runtime --> Conn Conn -->|"connect()"| B B --> BR style Tool fill:#dafbe1,stroke:#1a7f37,stroke-width:2px,color:#1f2328 style B stroke:#1a7f37,stroke-width:2px