Skip to content

[Agents] Sync recovery, context-overflow, and agent-tool docs#31251

Merged
whoiskatrin merged 2 commits into
productionfrom
agents-sync-recovery-context-overflow
Jun 5, 2026
Merged

[Agents] Sync recovery, context-overflow, and agent-tool docs#31251
whoiskatrin merged 2 commits into
productionfrom
agents-sync-recovery-context-overflow

Conversation

@threepointone
Copy link
Copy Markdown
Contributor

Summary

Syncs the Agents SDK documentation with changes that landed in the cloudflare/agents repository after the last docs sync (#31098). These are updates to existing pages — no new pages or moved files.

The upstream changes center on durable chat recovery and a new mid-turn context-overflow recovery layer:

Area Page What changed
Chat recovery budgets communication-channels/chat/chat-agents chatRecovery config table, ChatRecoveryProgressContext, ctx.reason seal values, and "Turns waiting on a human are not sealed"
Think recovery harnesses/think/recovery "Recovery budgets and limits" and the new "Context-window overflow recovery" (reactive + proactive layers)
Think config harnesses/think/configuration New contextOverflow configuration row
Lifecycle hooks harnesses/think/lifecycle-hooks New classifyChatError hook and ChatErrorContext.classification
Client tools harnesses/think/client-tools "Surviving restarts while waiting for a human" (links to the canonical explanation)
Agent tools runtime/execution/agent-tools Progress-keyed re-attach, AgentToolInterruptedReason, and the agentToolReattach* options
Observability runtime/operations/observability chat:context:compacted event and the "Chat context events" table
Sessions runtime/lifecycle/sessions Callout clarifying auto-compaction runs between turns

Validated locally with pnpm run check (0 errors) and by running the dev server — all eight pages return HTTP 200 and render the new content.

Documentation checklist

@github-actions github-actions Bot added product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. size/m labels Jun 5, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

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, @thomasgauvin, @threepointone, @whoiskatrin, @cloudflare/product-owners, @cloudflare/ai-agents, @cloudflare/dev-plat-leads

@threepointone threepointone marked this pull request as ready for review June 5, 2026 10:58
@cloudflare-docs-bot
Copy link
Copy Markdown
Contributor

cloudflare-docs-bot Bot commented Jun 5, 2026

Review

💡 0 suggestions found in commit e0bda65.

Acknowledged by author (3)
File Issue Note
agents/harnesses/think/lifecycle-hooks.mdx line 344 Escape angle brackets in MDX prose <TypeScriptExample> is a valid JSX component reference, no escaping needed
agents/harnesses/think/lifecycle-hooks.mdx line 350 Escape angle brackets in MDX prose This syntax is generic TypeScript/JSX class definition, no escaping needed
agents/harnesses/think/lifecycle-hooks.mdx line 360 Escape angle brackets in MDX prose </TypeScriptExample> is a valid JSX component closing tag, no escaping needed
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.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

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

Devin Review found 1 potential issue.

View 4 additional findings in Devin Review.

Open in Devin Review


```ts
export class MyAgent extends Think<Env> {
chatRecovery = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Missing override keyword on chatRecovery in code example

The new code example at src/content/docs/agents/harnesses/think/recovery.mdx:127 declares chatRecovery = { without the override keyword. Every other chatRecovery example across the codebase uses override chatRecovery = … — see recovery.mdx:31, chat-agents.mdx:586, chat-agents.mdx:602. The omission is inconsistent and will cause a compile error for users who copy this example into a project with noImplicitOverride: true in their tsconfig.json.

Suggested change
chatRecovery = {
override chatRecovery = {
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@ask-bonk ask-bonk Bot added documentation Documentation edits triage Waiting for a docs team review. labels Jun 5, 2026
Copy link
Copy Markdown
Contributor

@ask-bonk ask-bonk Bot left a comment

Choose a reason for hiding this comment

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

Syncs Agents SDK docs with upstream recovery, context-overflow, and agent-tool changes. 1 suggested change and 2 comments below.

Issues:

  • MEDIUMsrc/content/docs/agents/harnesses/think/lifecycle-hooks.mdx:338 New bare ts example should be wrapped in <TypeScriptExample>.
  • MEDIUMsrc/content/docs/agents/runtime/lifecycle/sessions.mdx:432 Possessive for inanimate object (model’s).
  • LOWsrc/content/docs/agents/runtime/operations/observability.mdx:214 Past-tense description in an events table that otherwise uses present tense.

Out of scope: The onExhausted descriptions in chat-agents.mdx and recovery.mdx differ slightly (Inspect ctx.reason for why. vs Inspect ctx.reason.). Consider aligning them in a follow-up.

When `.compactAfter(threshold)` is set, `appendMessage()` checks the estimated token count after each write. If it exceeds the threshold, `compact()` is called automatically. Auto-compaction failure is non-fatal — the message is already saved.

:::note
Auto-compaction is checked **between turns** (on each `appendMessage()`), not within a turn. A single long, tool-heavy turn can grow past the model's context window mid-flight, before the next check. `@cloudflare/think` adds opt-in mid-turn recovery on top of this — refer to [Context-window overflow recovery](/agents/harnesses/think/recovery/#context-window-overflow-recovery).
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Avoid possessive for inanimate objects (style guide):

Suggested change
Auto-compaction is checked **between turns** (on each `appendMessage()`), not within a turn. A single long, tool-heavy turn can grow past the model's context window mid-flight, before the next check. `@cloudflare/think` adds opt-in mid-turn recovery on top of this — refer to [Context-window overflow recovery](/agents/harnesses/think/recovery/#context-window-overflow-recovery).
Auto-compaction is checked **between turns** (on each `appendMessage()`), not within a turn. A single long, tool-heavy turn can grow past the model context window mid-flight, before the next check. `@cloudflare/think` adds opt-in mid-turn recovery on top of this — refer to [Context-window overflow recovery](/agents/harnesses/think/recovery/#context-window-overflow-recovery).


Or write your own, optionally delegating to the bundled classifier:

```ts
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wrap this new example in <TypeScriptExample> to match the bundled-classifier example above it and the style guide.


| Type | Payload | When |
| ------------------------ | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `chat:context:compacted` | `{ reason, shortened, requestId?, attempt? }` | Think compacted the session to handle a context-window overflow. `reason` is `"proactive"` (the `contextOverflow.proactive` guard fired before a step) or `"reactive"` (`contextOverflow.reactive` fired after an overflow). `shortened` is whether compaction actually reduced history — `false` means a retry would overflow again. Refer to [Context-window overflow recovery](/agents/harnesses/think/recovery/#context-window-overflow-recovery). |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Use present tense to match the rest of the table ("Think compacts" instead of "Think compacted").

@ask-bonk
Copy link
Copy Markdown
Contributor

ask-bonk Bot commented Jun 5, 2026

Reviewed PR #31251 and posted feedback on GitHub.

Labels applied: documentation, triage

Validation: pnpm run check passed with 0 errors.

What changed: This PR syncs the Agents SDK docs with upstream cloudflare/agents changes across 8 pages. It adds durable-recovery budget details (maxRecoveryWork, shouldKeepRecovering, onExhausted), a new mid-turn context-overflow recovery layer (contextOverflow.reactive / proactive), the classifyChatError lifecycle hook, progress-keyed agent-tool re-attach semantics, and the chat:context:compacted observability event.

Posted review: 1 inline suggestion + 2 comments.

  • MEDIUM lifecycle-hooks.mdx:338 — New bare ts example should be wrapped in <TypeScriptExample> per the style guide.
  • MEDIUM sessions.mdx:432 — "model's context window" uses a possessive for an inanimate object; suggested "model context window".
  • LOW observability.mdx:214 — The new chat:context:compacted row uses past tense ("Think compacted") while the rest of the event table uses present tense; suggested "Think compacts".

github run

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 5, 2026

Preview URL: https://e0bda65a.preview.developers.cloudflare.com
Preview Branch URL: https://agents-sync-recovery-context-overflow.preview.developers.cloudflare.com

Files with changes (up to 15)

Original Link Updated Link
https://developers.cloudflare.com/agents/harnesses/think/lifecycle-hooks/ https://agents-sync-recovery-context-overflow.preview.developers.cloudflare.com/agents/harnesses/think/lifecycle-hooks/
https://developers.cloudflare.com/agents/communication-channels/chat/chat-agents/ https://agents-sync-recovery-context-overflow.preview.developers.cloudflare.com/agents/communication-channels/chat/chat-agents/
https://developers.cloudflare.com/agents/harnesses/think/recovery/ https://agents-sync-recovery-context-overflow.preview.developers.cloudflare.com/agents/harnesses/think/recovery/
https://developers.cloudflare.com/agents/runtime/operations/observability/ https://agents-sync-recovery-context-overflow.preview.developers.cloudflare.com/agents/runtime/operations/observability/
https://developers.cloudflare.com/agents/runtime/lifecycle/sessions/ https://agents-sync-recovery-context-overflow.preview.developers.cloudflare.com/agents/runtime/lifecycle/sessions/
https://developers.cloudflare.com/agents/harnesses/think/configuration/ https://agents-sync-recovery-context-overflow.preview.developers.cloudflare.com/agents/harnesses/think/configuration/
https://developers.cloudflare.com/agents/runtime/execution/agent-tools/ https://agents-sync-recovery-context-overflow.preview.developers.cloudflare.com/agents/runtime/execution/agent-tools/
https://developers.cloudflare.com/agents/harnesses/think/client-tools/ https://agents-sync-recovery-context-overflow.preview.developers.cloudflare.com/agents/harnesses/think/client-tools/

@whoiskatrin whoiskatrin merged commit 703fab4 into production Jun 5, 2026
13 checks passed
@whoiskatrin whoiskatrin deleted the agents-sync-recovery-context-overflow branch June 5, 2026 13:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Documentation edits product:agents Build and deploy AI-powered Agents on Cloudflare that can act autonomously. size/m triage Waiting for a docs team review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants