Repository navigation
ThinkHarness says when a model call's prefix changed, and why - #3260
Merged
Merged
Conversation
…rness-backed Think emits chat:prefix:changed
|
| 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
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
Contributor
|
✅ agents import sizes: no significant changes ( |
…each cause compares with
… sent with the last turn's, on the context record
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.
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-changedsession event with the causes. The causes are the tools sent (names added, removed and changed), a different system prompt sent (a context refresh, or onebeforeTurnreturns), or history compacted, edited or deleted around the harness. The harness-backed Think forwards it aschat:prefix:changedon thechatchannel, besidechat:context:compacted. It's namedchat:rather than the design'sthink:, because athink: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. TheThinkclass emits it from E4.The tools and system causes are facts context already computes:
recordSentreturns 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 givetoolsthensystem, a changed remind block gives nothing, steady turns give nothing; an edit and a compaction givemessages.prefix-changed.test.ts(on the harness-backed shell under both configs):chat:prefix:changedonce, with the tool added.pnpm run checkgreen.