You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Migrate Agents docs to Workers AI examples
Replace OpenAI-specific examples with Workers AI / AI SDK usage across Agents docs. Examples now use an Env AI binding, createWorkersAI / workers-ai-provider, and streamText/generateText from the ai SDK instead of direct OpenAI clients or API keys. Updated WebSocket/SSE streaming, long-running model examples, and SQL/state persistence to consume this.env.AI.run streams/responses. Updated Wrangler/config mentions to use the ai binding and clarified AI Gateway/model routing guidance. Files changed: browse-the-web.mdx, http-sse.mdx, store-and-sync-state.mdx, using-ai-models.mdx, index.mdx.
* formatting
* docs: clarify Agent class and add LLM patterns
Revise agent-class.mdx to clarify the Agent/Server/DurableObject layering, tighten wording, fix small code snippets (ws.send, storage access, Response usage), standardize PartyKit/Server references, and add a new Layer 3 section describing AIChatAgent. Replace calling-llms.mdx with a complete rewrite that focuses on using LLMs inside stateful Agents: explains state-as-context, surviving disconnections, autonomous model calls, multi-model pipelines, and caching; adds multiple TypeScript examples and Next Steps link cards, and updates the page tag to "AI".
* docs: fix MCP docs bugs and inconsistencies
- authorization.mdx: remove orphaned <diagram> tag, fix broken anchor
(#3 -> #2), fix "oAuth" -> "OAuth", add pcx_content_type, rewrite
permission code to use correct MCP tool handler signature, replace
MyMCPServer.Router with .serve(), remove unused DirectoryListing import
- mcp-client-api.mdx: fix this.env bug in createMcpOAuthProvider (capture
env before returning object literal), fix import path for error utils,
remove dead code after return, replace OpenAI example with Workers AI
- mcp-handler-api.mdx: fix misleading intro (stateless vs stateful, not
SSE), fix storage.kv -> storage.get/put, fix {} as ExecutionContext,
wrap global McpServer in factory function, fix "accessable" typo
- remote-mcp-server.mdx: fix MyMCP.Router -> .serve(), fix Auth0/WorkOS
anchors pointing to #stytch, fix https://localhost -> http://localhost,
fix broken MCP client link
- securing-mcp-server.mdx: fix apiHandlers -> apiRoute + apiHandler
- test-remote-mcp-server.mdx: fix https -> http localhost, fix "lets you
to test" typo, remove outdated claim about Claude Desktop
- tools.mdx: add missing tags, add .js extension to import, remove
unused Render import, fix stale repo link
- governance.mdx: add pcx_content_type, remove empty import
- index.mdx: fix http -> https links for Claude and Cursor
- mcp-servers-for-cloudflare.mdx: fix "streamble-http" typo, remove
unused Render import, fix link to source code -> docs
- transport.mdx: remove unused Render/TabItem/Tabs imports
- oauth-mcp-client.mdx: fix extends Agent -> Agent<Env> (5 instances)
- connect-mcp-client.mdx: fix extends Agent -> Agent<Env> (3 instances)
Co-authored-by: Cursor <cursoragent@cursor.com>
* docs: rewrite MCP tools page, fix handler and authorization docs
tools.mdx: Full rewrite from 36-line stub to comprehensive reference.
Covers tool definitions, results, error handling, descriptions best
practices, Zod input validation, and usage with both createMcpHandler
and McpAgent. All examples use the factory function pattern.
mcp-handler-api.mdx: Add missing State type definition in stateful
example, fix onMcpRequest -> onRequest in Worker handler, remove
unused Render import.
authorization.mdx: Rewrite bottom half to show auth context usage
for both McpAgent (this.props) and createMcpHandler (getMcpAuthContext),
with proper type definitions. Clarify the two permission approaches
(check inside handler vs conditional registration) and when to use each.
Co-authored-by: Cursor <cursoragent@cursor.com>
---------
Co-authored-by: Cursor <cursoragent@cursor.com>
|`onStart(props?)`| When the instance starts, or wakes from hibernation. Receives optional [initialization props](/agents/api-reference/routing/#props) passed via `getAgentByName` or `routeAgentRequest`. |
59
-
|`onRequest(request)`| For each HTTP request to the instance |
60
-
|`onConnect(connection, ctx)`| When a WebSocket connection is established |
61
-
|`onMessage(connection, message)`| For each WebSocket message received |
62
-
|`onError(connection, error)`| When a WebSocket error occurs |
63
-
|`onClose(connection, code, reason, wasClean)`| When a WebSocket connection closes |
64
-
|`onEmail(email)`| When an email is routed to the instance |
65
-
|`onStateChanged(state, source)`| When state changes (from server or client) |
59
+
|`onRequest(request)`| For each HTTP request to the instance |
60
+
|`onConnect(connection, ctx)`| When a WebSocket connection is established |
61
+
|`onMessage(connection, message)`| For each WebSocket message received |
62
+
|`onError(connection, error)`| When a WebSocket error occurs |
63
+
|`onClose(connection, code, reason, wasClean)`| When a WebSocket connection closes |
64
+
|`onEmail(email)`| When an email is routed to the instance |
65
+
|`onStateChanged(state, source)`| When state changes (from server or client)|
Copy file name to clipboardExpand all lines: src/content/docs/agents/api-reference/browse-the-web.mdx
+7-10Lines changed: 7 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,16 +20,17 @@ Agents can browse the web using the [Browser Rendering](/browser-rendering/) API
20
20
21
21
The [Browser Rendering](/browser-rendering/) allows you to spin up headless browser instances, render web pages, and interact with websites through your Agent.
22
22
23
-
You can define a method that uses Puppeteer to pull the content of a web page, parse the DOM, and extract relevant information by calling the OpenAI model:
23
+
You can define a method that uses Puppeteer to pull the content of a web page, parse the DOM, and extract relevant information by calling a model via [Workers AI](/workers-ai/):
@@ -42,21 +43,14 @@ export class MyAgent extends Agent {
42
43
"body",
43
44
(element) =>element.innerHTML,
44
45
);
45
-
const client =newOpenAI({
46
-
apiKey: this.env.OPENAI_API_KEY,
47
-
});
48
46
49
-
let resp =awaitclient.chat.completions.create({
50
-
model: this.env.MODEL,
47
+
let resp =awaitthis.env.AI.run("@cf/zai-org/glm-4.7-flash", {
51
48
messages: [
52
49
{
53
50
role: "user",
54
51
content: `Return a JSON object with the product names, prices and URLs with the following format: { "name": "Product Name", "price": "Price", "url": "URL" } from the website content below. <content>${bodyContent}</content>`,
55
52
},
56
53
],
57
-
response_format: {
58
-
type: "json_object",
59
-
},
60
54
});
61
55
62
56
responses.push(resp);
@@ -79,6 +73,9 @@ You'll also need to add install the `@cloudflare/puppeteer` package and add the
| **Reconciliation** | Same `type` + `id` → updates in-place | Yes | Progressive state (searching → found) |
681
+
| **Append** | No `id`, or different `id` → appends | Yes | Log entries, multiple citations |
682
+
| **Transient** | `transient:true` → not added to `message.parts` | No | Ephemeral status (thinking indicator) |
683
683
684
684
Transient parts are broadcast to connected clients in real time but excluded from SQLite persistence and `message.parts`. Use the `onData` callback to consume them.
0 commit comments