Skip to content

Chat: saveMessages and continueLastTurn as submitTurn (4.iii 6f, parity 5, draft) - #3314

Closed
mattzcarey wants to merge 2 commits into
slim/chat-fn-6f5from
slim/chat-fn-6f6
Closed

mattzcarey wants to merge 2 commits into
slim/chat-fn-6f5from
slim/chat-fn-6f6

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

DRAFT, 4.iii 6f parity step 5, stacked on #3312. AIChatAgent's and Think's saveMessages and continueLastTurn map onto submitTurn.

  • saveMessages(messages) is submitTurn({ trigger: "server", messages }): the turn stores them when it starts, then answers. The function form and shouldApplyMessages/isCurrent are resolved by the host against the current transcript before it calls submitTurn; they move in the 6f switch PR, where this.messages is.
  • continueLastTurn(body, options) is submitTurn({ trigger: "server", mode: "continue", body }, { storeContext: body !== undefined, signal }). The definition extends the last assistant message, as a tool answer's turn does, with main's rules, decided before anything is stored:
    • with no assistant message last, it is skipped, reason nothing-to-continue, and nothing runs;
    • while that reply waits on a client tool or an approval, it is skipped, reason awaiting-client (continuationWaitsOnClient);
    • a reply that holds nothing once its trailing reasoning is gone is removed, and its question is answered again;
    • a body the app passes becomes the chat's stored body (storeContext); one framework code pins is that turn's only; what a turn doesn't bring comes from the stored context;
    • signal stops the turn, waiting or running.

Tests, each failing before (the first two are the happy path):

  • a saved message is answered;
  • a continue extends that same reply;
  • nothing to continue;
  • awaiting a client;
  • an empty reply is removed and answered again;
  • a stored body against a pinned one;
  • an abort of the signal.

Cost: none on the hot path. A continueLastTurn reads the transcript once, as before.

@changeset-bot

changeset-bot Bot commented Nov 26, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 0fed73f

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 no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

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@3314

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: 0fed73f

@agent-think

agent-think Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

🔴 agents import sizes: 1 entry point over threshold

Entry point Exports Largest gzip change Size now
🔴 agents/chat 24 resized up to +2.2 KiB (+409.26%) 2.7 KiB
Changed exports (24)
Import Gzip change Size now
🔴 agents/chat#INTERRUPTED_TOOL_ERROR_TEXT +2.2 KiB (+409.26%) 2.7 KiB
🔴 agents/chat#clientResolvableToolNames +2.2 KiB (+492.05%) 2.6 KiB
🔴 agents/chat#persistRepairedTranscript +2.2 KiB (+344.95%) 2.8 KiB
🔴 agents/chat#unexecutedToolNames +2.2 KiB (+440.36%) 2.7 KiB
🔴 agents/chat#streamChunksFinished +2.2 KiB (+459.13%) 2.6 KiB
🔴 agents/chat#pausedExecutionUpdate +2.2 KiB (+407.96%) 2.7 KiB
🔴 agents/chat#toolPartHasSettledResult +2.1 KiB (+451.33%) 2.6 KiB
🔴 agents/chat#applyToolUpdate +2.1 KiB (+372.54%) 2.7 KiB
🔴 agents/chat#toolResultUpdate +2.1 KiB (+371.72%) 2.7 KiB
🔴 agents/chat#crossMessageToolResultUpdate +2.1 KiB (+370.12%) 2.7 KiB
🔴 agents/chat#toolApprovalUpdate +2.1 KiB (+364.37%) 2.7 KiB
🔴 agents/chat#stripTrailingReasoning +2.1 KiB (+305.78%) 2.8 KiB
🔴 agents/chat#partAwaitsClientInteraction +2.1 KiB (+361.2%) 2.7 KiB
🔴 agents/chat#hasIncompleteToolBatch +2.1 KiB (+344.5%) 2.7 KiB
🔴 agents/chat#interruptedToolPartAsError +2.1 KiB (+279.87%) 2.9 KiB
🔴 agents/chat#replyToContinueIsEmpty +2.1 KiB (+272.19%) 2.9 KiB
🔴 agents/chat#continuationWaitsOnClient +2.1 KiB (+334.16%) 2.7 KiB
🔴 agents/chat#removeEmptyReplyToContinue +2.1 KiB (+197.97%) 3.2 KiB
🔴 agents/chat#unsettledToolCallIds +2.1 KiB (+331.94%) 2.7 KiB
🔴 agents/chat#hasPendingToolInteraction +2.1 KiB (+274.84%) 2.9 KiB
🔴 agents/chat#applyToolPartUpdate +2.1 KiB (+223.15%) 3 KiB
🔴 agents/chat#repairInterruptedToolParts +2 KiB (+142.31%) 3.3 KiB
🔴 agents/chat#settleInterruptedReply +1.9 KiB (+120.19%) 3.5 KiB
🔴 agents/chat#repairTranscriptBeforeTurn +1.9 KiB (+121.7%) 3.5 KiB
How this works

Each 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 861fa46d → 0fed73f7 · workflow run · reported by agent-think[bot]

…t, an empty reply answered again, stored or pinned body, a signal) (rv-6)
@mattzcarey

Copy link
Copy Markdown
Member Author

Closed to drain open PRs (COMMON, 27 Nov). This PR's commits are commits of #3361 (the switch), which now sits directly on #3298. The branch is kept.

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