
Agents Sdk
Add Cloudflare Agents SDK browser tools (search, execute, CDP sessions) to Workers AI chat agents when you need real JS rendering or interaction.
Overview
agents-sdk is an agent skill for the Build phase that wires Cloudflare Agents SDK experimental browser tools into Workers AI chat agents.
Install
npx skills add https://github.com/cloudflare/skills --skill agents-sdkWhat is this skill?
- Experimental Browse the Web: CDP-powered scrape, screenshot, and page interaction for agents
- Wrangler setup: BROWSER binding, LOADER worker_loaders, nodejs_compat flag
- AI SDK integration via createBrowserTools merged into streamText tools
- browser_search for web search results; browser_execute for navigate plus JS IIFEs in fresh sessions
- Guidance: real browser for JS rendering; fetch() when HTML or API data is enough
- 2 primary browser tools documented: browser_search and browser_execute
- Requires BROWSER binding, LOADER worker_loaders, and nodejs_compat in wrangler
Adoption & trust: 11.5k installs on skills.sh; 1.7k GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your Cloudflare agent needs to read dynamic web pages or run in-page scripts but fetch-only tools return empty or static HTML.
Who is it for?
Indie devs building AIChatAgent workers that must search the web or execute JS on target URLs.
Skip if: Static API ingestion, non-Cloudflare deployments, or tasks where headless fetch is sufficient and browser cost is unjustified.
When should I use this skill?
Building Cloudflare Agents that need real browser rendering, web search tools, or CDP sessions instead of fetch-only HTTP.
What do I get? / Deliverables
You configure browser bindings and expose browser_search and browser_execute (or CDP sessions) alongside your agent tools in a streamText flow.
- wrangler.jsonc browser and compatibility configuration
- Agent class integrating createBrowserTools with streamText
- Working browser_search or browser_execute tool calls from the agent
Recommended Skills
Journey fit
Installing browser bindings and agent tool wiring happens while building agent products on Cloudflare, not during initial idea research. This is agent-platform tooling—wrangler browser binding, AI SDK tools—not generic frontend CSS work.
How it compares
Cloudflare-hosted agent browser tools—not Playwright-on-laptop scripts or generic MCP browser servers outside Workers.
Common Questions / FAQ
Who is agents-sdk for?
Builders using Cloudflare Agents and the AI SDK who need CDP browser capabilities inside a Worker-bound chat agent.
When should I use agents-sdk?
During Build agent-tooling when configuring wrangler browser bindings, createBrowserTools, or choosing browser tools versus fetch for web data.
Is agents-sdk safe to install?
Browser automation can reach arbitrary URLs; review the Security Audits panel on this page and constrain agent permissions and URLs in production.
SKILL.md
READMESKILL.md - Agents Sdk
# Browse the Web (Experimental) Fetch https://developers.cloudflare.com/agents/api-reference/browse-the-web/ for complete documentation. CDP-powered browser tools that let agents scrape, screenshot, and interact with web pages. ## Setup ```jsonc // wrangler.jsonc { "browser": { "binding": "BROWSER" }, "worker_loaders": [{ "binding": "LOADER" }], "compatibility_flags": ["nodejs_compat"] } ``` ## Usage with AI SDK ```typescript import { createBrowserTools } from "agents/browser/ai"; export class MyAgent extends AIChatAgent<Env> { async onChatMessage(onFinish) { const browserTools = createBrowserTools({ browser: this.env.BROWSER, loader: this.env.LOADER }); const result = streamText({ model: openai("gpt-4o"), messages: await convertToModelMessages(this.messages), tools: { ...myTools, ...browserTools }, onFinish }); return result.toUIMessageStreamResponse(); } } ``` ## Available Tools | Tool | Purpose | |------|---------| | `browser_search` | Search the web and return results | | `browser_execute` | Navigate to URL, execute JS, return results | The LLM writes async JavaScript IIFEs that run in a fresh browser session. ## When to Use - Need a real browser (JS rendering, screenshots, interaction) → browser tools - Just need HTML/API data → use `fetch()` instead (faster, cheaper) ## Low-Level API ```typescript import { connectBrowser, CdpSession } from "agents/browser"; const browser = await connectBrowser(this.env.BROWSER); const cdp = new CdpSession(browser); await cdp.send("Page.navigate", { url: "https://example.com" }); ``` # Callable Methods Fetch https://developers.cloudflare.com/agents/api-reference/callable-methods/ for complete documentation. ## Overview `@callable()` exposes agent methods to clients via WebSocket RPC. ```typescript import { Agent, callable } from "agents"; export class MyAgent extends Agent<Env, State> { @callable() async greet(name: string): Promise<string> { return `Hello, ${name}!`; } @callable() async processData(data: unknown): Promise<Result> { // Long-running work return result; } } ``` ## Client Usage ```typescript // Basic call const greeting = await agent.call("greet", ["World"]); // With timeout const result = await agent.call("processData", [data], { timeout: 5000 // 5 second timeout }); ``` ## Streaming Responses ```typescript import { Agent, callable, StreamingResponse } from "agents"; export class MyAgent extends Agent<Env, State> { @callable({ streaming: true }) async streamResults(stream: StreamingResponse, query: string) { for await (const item of fetchResults(query)) { stream.send(JSON.stringify(item)); } stream.close(); } @callable({ streaming: true }) async streamWithError(stream: StreamingResponse) { try { // ... work } catch (error) { stream.error(error.message); // Signal error to client return; } stream.close(); } } ``` Client with streaming: ```typescript await agent.call("streamResults", ["search term"], { stream: { onChunk: (data) => console.log("Chunk:", data), onDone: () => console.log("Complete"), onError: (error) => console.error("Error:", error) } }); ``` ## Introspection ```typescript // Get list of callable methods on an agent const methods = await agent.call("getCallableMethods", []); // Returns: ["greet", "processData", "streamResults", ...] ``` ## When to Use | Scenario | Use | |----------|-----| | Browser/mobile calling agent | `@callable()` | | External service calling agent | `@callable()` | | Worker calling agent (same codebase) | DO RPC directly | | Agent calling another agent | `getAgentByName()` + DO RPC | # Client SDK Fetch https://developers.cloudflare.com/agents/api-reference/client-sdk/ for complete documentation. ## React: `useAgent` ```tsx import { useAgent } from "agents/react"; function App() { const [state, setState] = useState({ count: 0