Skip to content

docs: correct Agents SDK guidance - #32762

Open
ben-reitz wants to merge 4 commits into
productionfrom
docs/agents-audit-sync
Open

docs: correct Agents SDK guidance#32762
ben-reitz wants to merge 4 commits into
productionfrom
docs/agents-audit-sync

Conversation

@ben-reitz

Copy link
Copy Markdown

Summary

Correct outdated Agents SDK examples and security guidance.

Documentation checklist

@cloudflare-docs-bot

cloudflare-docs-bot Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Review

⚠️ 1 warning found in commit 7503161.

👉 Fix in your agent 👈
Fix the following review findings in PR #32762 (https://github.com/cloudflare/cloudflare-docs/pull/32762).

Before making changes, review each finding and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g. the fix requires disproportionate effort for minimal benefit,
  or the finding is factually incorrect), explain why
- If you need clarification before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order

After triaging, follow this order:
1. Post a comment on this PR for any findings you are skipping, with the finding ID and your reasoning.
2. Then commit the fixes for the legitimate findings.

The comment must come before the commit — the bot reads PR comments when a new
push triggers a review, so skip comments posted after the push will be missed.

---

## Code Review

### Warnings (1)

#### CR-6d2017216f6a · Unvalidated JSON.parse
- **File:** `src/content/docs/agents/communication-channels/webhooks/index.mdx` line 40
- **Issue:** All three changed payload-parsing sites (lines 40, 95, and 189) call JSON.parse on raw external body text without a try/catch. A malformed payload will throw an unhandled exception and surface as a 500 instead of a controlled 400.
- **Fix:** Wrap each JSON.parse in a try/catch block and return new Response('Invalid payload', { status: 400 }) when parsing fails.

Code Review

This code review is in beta and may not always be helpful — use your judgment.

Warnings (1)
File Issue
agents/communication-channels/webhooks/index.mdx line 40 Unvalidated JSON.parse — All three changed payload-parsing sites (lines 40, 95, and 189) call JSON.parse on raw external body text without a try/catch. A malformed payload will throw an unhandled exception and surface as a 500 instead of a controlled 400. Fix: Wrap each JSON.parse in a try/catch block and return new Response('Invalid payload', { status: 400 }) when parsing fails.

Conventions

No convention issues found.

Style Guide Review

No style-guide issues found.

Commands

Only codeowners can run commands. Post a comment with the command to trigger it.

Command Description
/review Runs a review now. Incremental if a prior review exists, full if not.
/full-review Re-reviews the entire PR diff from scratch, ignoring incremental history. Useful after a rebase, when you want a fresh review, or if the bot gets out of sync and reports issues that no longer exist.
/ignore-review-limit Permanently lifts the 2-review automatic limit for this PR. Future pushes will trigger reviews as normal.
/disable-auto-review Stops automatic reviews from triggering on future pushes to this PR. Codeowners can still run /review or /full-review manually.
/rebase Rebases the PR branch against production. On conflict, attempts to resolve automatically using AI. Stops with an explanation if confidence is not high enough.

@github-actions github-actions Bot added the product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. label Aug 14, 2026
```sh
npm install @cloudflare/ai-chat agents ai workers-ai-provider
```
<PackageManagers pkg="@cloudflare/ai-chat agents ai @ai-sdk/react workers-ai-provider" />

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example imports React helpers, so the install command needs this package.

import { Agent, callable, type StreamingResponse } from "agents";

class MyAgent extends Agent {
@callable({ streaming: true })

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This now matches the streaming API the SDK actually exposes.


if (
!(await this.verifySignature(body, signature, this.env.WEBHOOK_SECRET))
!(await verifyGitHubWebhook(

@ben-reitz ben-reitz Aug 14, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file now shows a complete, working GitHub webhook flow instead of several disconnected examples:

  • It accepts only POST requests and checks GitHub's X-Hub-Signature-256 against the raw body before parsing any JSON.
  • It uses crypto.subtle.verify() and rejects malformed signatures instead of comparing hand-built signature strings.
  • It chooses the Agent from the signed repository.full_name value, rather than trusting an unsigned URL segment or header.
  • It uses GitHub's real event and signature headers and reuses the same verification helper throughout the page.
  • It makes clear that Slack, Stripe, and other providers need their own checks, and that routing should only use data returned after those checks pass.

as a whole, these changes make the examples usable as they've been written (and prevent forged webhook data from selecting or reaching an Agent).

};

export class ProjectManager extends Agent<ProjectState> {
export class ProjectManager extends Agent<Env, ProjectState> {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Agent type expects the environment first and state second.

[vars]
EMAIL_SECRET = "change-me-in-production"
```
1. Store the signing key as a Wrangler secret. Do not put it in `vars` or commit it to source control:

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The signing key is a secret, so it should not live in committed configuration.

### RPC and Callable Methods

`agents` takes Durable Objects RPC one step further by implementing RPC through WebSockets, so clients can call methods on the Agent directly. To make a method callable through WebSocket, use the `@callable()` decorator. Methods can return a serializable value or a stream (when using `@callable({ stream: true })`).
`agents` takes Durable Objects RPC one step further by implementing RPC through WebSockets, so clients can call methods on the Agent directly. To make a method callable through WebSocket, use the `@callable()` decorator. Methods can return a serializable value or a stream (when using `@callable({ streaming: true })`).

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK calls this option streaming; using stream does not work.

"staging": {
"name": "my-agent-staging",
"durable_objects": {
"bindings": [{ "name": "MyAgent", "class_name": "MyAgent" }],

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Named Wrangler environments do not inherit Durable Object bindings, so each one needs its own copy.

### Cross origin

Cookies do not help across origins. Pass credentials in the URL query, then verify on the server.
Cross-origin cookie behavior depends on the cookie's domain and `SameSite` attributes, whether the two origins are same-site, and browser third-party cookie policy. If you cannot rely on a cookie, pass a short-lived credential in the URL query and verify it on the server.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cookies are not always blocked across origins, so this explains when they work and when a short-lived token is needed.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request requires reviews from CODEOWNERS as it changes files that match the following patterns:

Pattern Owners
/src/content/docs/agents/ @irvinebroque, @rita3ko, @elithrar, @cloudflare/product-owners, @cloudflare/ai-agents, @cloudflare/dev-plat-leads

@github-actions

github-actions Bot commented Aug 14, 2026

Copy link
Copy Markdown
Contributor

Preview URL: https://7503161a.preview.developers.cloudflare.com
Preview Branch URL: https://docs-agents-audit-sync.preview.developers.cloudflare.com

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/agents/communication-channels/webhooks/ https://docs-agents-audit-sync.preview.developers.cloudflare.com/agents/communication-channels/webhooks/
https://developers.cloudflare.com/agents/runtime/operations/cross-domain-authentication/ https://docs-agents-audit-sync.preview.developers.cloudflare.com/agents/runtime/operations/cross-domain-authentication/
https://developers.cloudflare.com/agents/examples/email-agent/ https://docs-agents-audit-sync.preview.developers.cloudflare.com/agents/examples/email-agent/
https://developers.cloudflare.com/agents/concepts/agentic-patterns/long-running-agents/ https://docs-agents-audit-sync.preview.developers.cloudflare.com/agents/concepts/agentic-patterns/long-running-agents/
https://developers.cloudflare.com/agents/communication-channels/chat/client-sdk/ https://docs-agents-audit-sync.preview.developers.cloudflare.com/agents/communication-channels/chat/client-sdk/
https://developers.cloudflare.com/agents/communication-channels/chat/chat-agents/ https://docs-agents-audit-sync.preview.developers.cloudflare.com/agents/communication-channels/chat/chat-agents/
https://developers.cloudflare.com/agents/runtime/operations/configuration/ https://docs-agents-audit-sync.preview.developers.cloudflare.com/agents/runtime/operations/configuration/
https://developers.cloudflare.com/agents/runtime/lifecycle/agent-class/ https://docs-agents-audit-sync.preview.developers.cloudflare.com/agents/runtime/lifecycle/agent-class/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. size/m

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants