Skip to content

ThinkHarness says when a model call's prefix changed, and why - #3260

Merged
mattzcarey merged 3 commits into
mainfrom
slim/ext-prefix
Nov 26, 2026
Merged

mattzcarey merged 3 commits into
mainfrom
slim/ext-prefix

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

Before a model call whose prefix differs from the session's previous call, so a provider's prompt cache of it is lost, ThinkHarness emits a prefix-changed session event with the causes. The causes are the tools sent (names added, removed and changed), a different system prompt sent (a context refresh, or one beforeTurn returns), or history compacted, edited or deleted around the harness. The harness-backed Think forwards it as chat:prefix:changed on the chat channel, beside chat:context:compacted. It's named chat: rather than the design's think:, because a think: event would land on the lifecycle channel. A changed context block isn't a cause, because it's sent after the new message and the prefix holds. The Think class emits it from E4.

The tools and system causes are facts context already computes: recordSent returns the diff behind the notice, and compares a hash of the system prompt sent with the one on the last turn's record (one more field on the record context already writes). The history rewrites come from the harness's Sessions change feed (compaction, a message updated outside the harness's own writes, a delete), kept per session until that session's next model call. The transcript isn't hashed. It also adds the third-prompt assertion Devin asked for on #3250.

Cost: no row and no extra read. Per model call: one SHA-256 of the system prompt and one map lookup for the session's rewrites. The tool diff is the one the notice already computes. A turn whose tools or prompt changed writes that turn's context record (one annotation, the same record a tool change already writes); a steady turn writes nothing. A session from before this change records its first hash once, and that first call can't report a refresh, because there's no earlier hash to compare with. Memory: one set of at most three names per session with a rewrite not yet followed by a call. A rewrite before an eviction goes unreported.

Validation:

  • harness.test.ts: tools then refresh give tools then system, a changed remind block gives nothing, steady turns give nothing; an edit and a compaction give messages.
  • Think prefix-changed.test.ts (on the harness-backed shell under both configs): chat:prefix:changed once, with the tool added.
  • Harness-think suite 125, context suite 106, pnpm run check green.

Devin Review

…rness-backed Think emits chat:prefix:changed
@changeset-bot

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: b9bbd23

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

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

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: b9bbd23

devin-ai-integration[bot]

This comment was marked as resolved.

@agent-think

agent-think Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

✅ agents import sizes: no significant changes (fa8de315 → b9bbd238, workflow run)

devin-ai-integration[bot]

This comment was marked as resolved.

… sent with the last turn's, on the context record

@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 2 new potential issues.

Devin Review

Comment thread packages/agents/src/context/context.ts Resolved
Comment thread packages/agents/src/context/context.ts Resolved
@mattzcarey
mattzcarey merged commit 6d641c3 into main Nov 26, 2026
29 checks passed
@mattzcarey
mattzcarey deleted the slim/ext-prefix branch November 26, 2026 12:04
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.

1 participant