Skip to content

feat(context): remind the model of changed blocks without busting the prompt cache (#2089) - #2405

Merged
threepointone merged 3 commits into
fix/2205-session-mirrorfrom
feat/2089-context-reminders
Sep 28, 2026
Merged

threepointone merged 3 commits into
fix/2205-session-mirrorfrom
feat/2089-context-reminders

Conversation

@threepointone

@threepointone threepointone commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Closes #2089.

Problem

A frozen system prompt keeps the provider's prefix cache warm, but it also freezes context that changes between turns: the date, workspace state, project instructions. Today the only way to update it is refreshSystemPrompt(), which throws away the cached prefix.

Change

  • A context block can declare whenChanged: "remind". ContextBlocks.reminder() re-reads those blocks and returns the current value of any whose rendering no longer appears in the frozen prompt.
  • Think adds that text to the last user message of the model request, and never persists it.
  • The frozen prompt does not change until refreshSystemPrompt() promotes the value. Think already refreshes after a compaction.

Edge cases:

  • Restarts. The comparison is against the stored prompt, not in-memory block state. On wake the blocks are re-read from their providers, but the stored prompt still holds the old value, so an in-memory comparison would miss the change.
  • Precise matching. Each section is matched with both ends pinned. Content that only grew or shrank at the start or end, or lost a trailing newline, counts as changed. A label that is a prefix of another label does not collide.
  • Blocks that change emptiness. A block that becomes empty, or gains content after rendering empty, is reported.
  • Request shape. The reminder joins the final user message, because not every provider accepts two user messages in a row. A request that ends in a partial assistant message keeps it last, so the continue checkpoint still follows.
  • Mid-turn compaction. The proactive compaction guard re-applies the reminder. The compaction refreshes the stored prompt, but the running request keeps its original system prompt.
  • Cost of a standing reminder. It moves to each new user message, so the previous user message falls out of the cached prefix. The system prompt never does. The docs say so.

Tests

  • context.test.ts covers promotion, restart through a shared prompt store, and the edge-change and emptiness cases, each with the block first and last. It also checks that init() is not called again.
  • prompt-cache.test.ts runs six turns and shows that the system message stays byte-identical, reminders appear only while the value differs, the only prefix break before the refresh is the previous user message, and the refresh busts the cache once. It fails without the Think wiring.

@changeset-bot

changeset-bot Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 94b7f6f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
agents Minor
@cloudflare/think Minor
@cloudflare/agent-think Patch

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

@threepointone
threepointone added this pull request to stack #2407 September 28, 2026 14:47
@threepointone
threepointone marked this pull request as ready for review September 28, 2026 14:50

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

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.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 1 potential issue.

Devin Review

Comment thread packages/agents/src/context/blocks.ts Outdated
@threepointone
threepointone force-pushed the feat/2089-context-reminders branch from 62a5145 to 64a089d Compare September 28, 2026 15:46
@agent-think

agent-think Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (0cb19a64 → 94b7f6fa, workflow run)

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

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.

Note

Newer findings are available below. Devin Review posted a newer report on this PR, in addition to the findings presented here.

Devin Review found 2 new potential issues.

Devin Review

Comment thread packages/think/src/think.ts Outdated
Comment thread docs/agents/context.md
@pkg-pr-new

pkg-pr-new Bot commented Sep 28, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@2405

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@2405

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@2405

hono-agents

npm i https://pkg.pr.new/hono-agents@2405

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@2405

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@2405

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@2405

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@2405

commit: 94b7f6f

threepointone and others added 3 commits September 28, 2026 17:51
… prompt cache (#2089)

A block declared whenChanged: "remind" is re-read each turn. While its
rendering no longer appears in the frozen prompt, ContextBlocks.reminder()
returns its current value, and Think adds it to the last user message of
the model request without persisting it. refreshSystemPrompt() promotes
the value and ends the reminders.

Co-authored-by: Cursor <cursoragent@cursor.com>
…n is exact

Co-authored-by: Cursor <cursoragent@cursor.com>
…ply continuation

Co-authored-by: Cursor <cursoragent@cursor.com>
@threepointone
threepointone force-pushed the feat/2089-context-reminders branch from 64a089d to 94b7f6f Compare September 28, 2026 16:54

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

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.

Devin Review found 1 new potential issue.

Devin Review

Comment thread packages/think/src/think.ts
@threepointone
threepointone merged commit 11f87b5 into main Sep 28, 2026
22 of 35 checks passed
@threepointone
threepointone deleted the feat/2089-context-reminders branch September 28, 2026 18:04
@github-actions github-actions Bot mentioned this pull request Oct 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Append reminders to fake system prompt “updates" without cache invalidation

1 participant