Repository navigation
feat(context): bind context blocks to a session, recorded in the transcript - #2773
Open
mattzcarey wants to merge 7 commits into
Open
mattzcarey wants to merge 7 commits into
mattzcarey wants to merge 7 commits into
Conversation
🦋 Changeset detectedLatest commit: bde8a57 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Contributor
🟢 agents import sizes: 1 entry point changed, no growth
Changed exports (4)
How this worksEach runtime export is bundled on its own, minified, and gzipped. Changes smaller than 100 B, or smaller than 1% and 1 KiB, are ignored. Growth over 10% or 5 KiB is marked 🔴. This report is informational and does not fail CI. The workflow artifact contains every measurement. Compared |
Bring back withContext()/withCachedPrompt() on the Sessions handle. The session stores the frozen prompt by default, backs provider-less blocks with SQLite, supports searchable: true, and refreshes the prompt after compact() and clearMessages(). Think declares its blocks on the default session and its context methods are no longer deprecated. Refs #2772
…script Context records the system prompt snapshot and each delivered remind change on the user message of the turn, and each request is a projection of that record, so earlier turns are sent unchanged and the prefix cache holds. Sessions is unchanged. Think's context runs on Context, ThinkHarness takes a context option, and the harness-backed Think plugs configureContext into it.
…uations, and forged records - keep a pending refresh and a pointer to the latest snapshot in the block storage, so a refresh survives eviction and a bounded history window still opens with the recorded prompt - never record on a user message that already has an answer (regeneration); the change rides on that request only - ThinkHarness prepares context on every model call, placing changes it could not record, and reserves the context metadata key so clients cannot forge it - update the workspace skills test to assert the delivered request
mattzcarey
force-pushed
the
feat/session-context
branch
from
October 29, 2026 17:44
eed362f to
f10d0cb
Compare
1 task done
… state - ContextBlocks keeps blocks and tools only: freezeSystemPrompt, refreshSystemPrompt, reminder and the prompt store are gone; Context records the prompt in the session, and renderSystemPrompt() renders the blocks without storing anything - replace the in-memory unit tests for the old frozen prompt, provider init, and search tool with integration tests on a real Durable Object and session - mark the context exports and the ThinkHarness context option experimental and update the changeset
…st it adversarially - each change record names its snapshot and carries everything delivered since, and lookups take the newest record on the stored path to the history's last message, so a bounded window sees exactly what the full history does: never a prompt from a later turn or another branch, and not a changed answer once compaction hides a record - reserve the _context_state label for Context's own state - add an invariant test that drives random sessions on a real Durable Object (turns, block changes, refreshes, regenerations, compactions) and checks every window against the full path after every step
…at requests extend each other - a snapshot taken after a refresh used the values loaded when the refresh was asked for, so a block changed in between went out stale; always reload when recording a snapshot - add an invariant test: in random sessions on a real Durable Object, each turn's request extends the previous one exactly (what the provider is sent), except after a refresh, a compaction, or a branch switch, and a change is delivered once per branch
…compacted leaf - every turn's user message carries a record or a pointer to one, and the lookup walks the stored path to the nearest user message that has one, so there is no bounded index for an old branch to fall out of - a history that ends in a compaction summary walks from the stored message the compaction ends at - tests: regenerate an old turn after 300 later changes, compaction that reaches the last message, and invariants that compact to the end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
agents/contextgetsContext(experimental): context blocks bound to a session. The transcript records the system prompt each turn was sent with and every context change delivered after it, and each model request is a projection of that record. Think's context now runs on it,ThinkHarnesstakes acontextoption, andSessionsis unchanged.Context never rewrites what the model has already been sent:
cf_agents_context_blocksrows), so nothing migrates; a small state row keeps a pending refresh and a pointer to the latest snapshot, so a refresh survives eviction and a bounded history window still opens with the recorded promptContextBlockskeeps only blocks and tools:freezeSystemPrompt,refreshSystemPrompt,reminder, and the prompt store move toContext.ThinkHarnessreserves the context metadata key, so client input cannot carry a record.This replaces the
_system_promptrow and the moving reminder (#2772). pi and Claude Code work the same way: context changes land at turn boundaries and stay where they were delivered. Think's prompt-cache test shows the result: a turn after a reminder now extends the previous request instead of losing the last user message from the cache.Agents workers, Think workers,
ThinkHarness, and ai-chat tests ran, pluspnpm run check. Context is covered by integration tests on a real Durable Object and session. Docs: cloudflare/cloudflare-docs#34718.