Skip to content

Agent tools (R3-identity): an AIChatAgent agent-tool run is its chat turn's run - #3475

Closed
mattzcarey wants to merge 23 commits into
slim/chat-fn-6s1from
slim/agent-runs-r3
Closed

mattzcarey wants to merge 23 commits into
slim/chat-fn-6s1from
slim/agent-runs-r3

Conversation

@mattzcarey

@mattzcarey mattzcarey commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

An AIChatAgent agent-tool run becomes its chat turn's run: one durable run, agent-tool:<runId>, on the chat module. The child side no longer keeps its own run table, and the seam the switch (#3361) carried for agent tools is deleted. Stacked on #3361 and merges with it.

What changes

  • agents/chat/agent-tool-turns.ts (sibling-package support, @internal) covers the run's whole life:
    • start: a server turn whose metadata holds agentTool;
    • inspect: read off the run;
    • chunks: the turn's stream, read by position. It is kept, completed, once the reply is stored, as the release kept an agent-tool child's reply stream (arch's amended F2 ruling). It is reclaimed when the child's next agent-tool turn starts, and goes with a clear or the facet. A late parent replays the live chunks;
    • tail: follows the turn's stream with Streams.readBatches, which wakes on each append, so nothing polls;
    • progress and milestones: kept in the run's metadata and put on its live reply with LiveTurn.inject;
    • cancel: marked on the run at once, then the lane stops the turn;
    • carry-forward of a released version's tables.
  • AIChatAgent calls those functions. Deleted:
    • its AgentToolRuns;
    • the seam: the AgentToolRunsHost mapping, the turn-start hook, the clear generation, the stream adapter and the settle-on-onResponse block;
    • its old recovery engine's agent-tool hooks (rebind, admitRecoveredTurn, reconcileOwn);
    • the starting status.
  • A terminal-only run's chunks are kept off the child's own tabs, by its run's metadata.
  • A tail that comes before the turn has opened its stream waits for the turn's first frame (or its end), then follows the stream.
  • Upgrade: the released cf_ai_chat_agent_tool_runs and cf_ai_chat_agent_tool_milestones rows are carried onto settled chat-turn runs (Tasks.importRun), and both tables are dropped. A run that was still running is carried as an error. agent-tool-child-upgrade.test.ts is now it.
  • Think's classic class still uses AgentToolRuns until Think's own switch.

Behaviour a parent sees

  • A cancel from the caller's signal shows as aborted, with its reason, at once.
  • A clear still reads as error, "skipped because the chat was cleared".

Also in this PR

  • F25: a parent turn that waits on an agent-tool child counts the child's forwarded chunks as its own progress, at most once per 5 s, as released. AIChatAgent credits its running turn (chat.progressCredit in the run's metadata), and the chat-turn definition counts that credit with what the turn streamed (a chat-host hunk, acked by limits).
  • A facet empties the released tables instead of dropping them; only a root drops them.
  • A run in flight across the upgrade carries on: its carried turn runs under agent-tool:<runId>.

Tests

  • ai-chat agent-tools, child-upgrade and reattach-recovery: 56 of 56.
  • The full ai-chat suite: 850 of 851. The one failure is Chat: AIChatAgent onto the chat module (4.iii 6f switch, draft) #3361's known durable-admission onStart case (Q-SW2).
  • agents chat-host/agent-tool-turns: 7 of 7.
  • Removed with the old implementation: tests of the old store, the tail fan-out and its live counters, the request-id cache, the starting status and the old recovery engine's agent-tool hooks, and agent-tool-rebind-noop.test.ts. The tests whose behaviour still holds now read the public API.

Cost, at rest per finished run, against ai-chat 0.12.3:

  • 0.12.3 kept a run row, one row per milestone, and the reply's stream (its stream row and chunk rows), until the child's next start.
  • Now: one retained Task run (milestones and progress are fields of its metadata, written once each) and the kept stream (its row and its chunk blocks, several chunks to a block), until the child's next agent-tool turn starts.
  • So no more rows than the release, with no run table, milestone table or request index.
  • A milestone or progress report is one metadata write. An F25 credit is at most one metadata write per 5 s per waiting parent turn, as released.

Shipped size (product source, tests excluded, against #3361's head): +1,141 / −210.

@changeset-bot

changeset-bot Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: f903bf4

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 4 packages
Name Type
agents Patch
@cloudflare/ai-chat Patch
@cloudflare/think Patch
@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 27, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

agents

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

@cloudflare/ai-chat

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

@cloudflare/codemode

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

hono-agents

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

@cloudflare/shell

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

@cloudflare/think

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

@cloudflare/voice

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

@cloudflare/worker-bundler

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

commit: f903bf4

@agent-think

agent-think Bot commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

🟢 agents import sizes: 2 entry points changed, no growth

Entry point Exports Largest gzip change Size now
🆕 agents/chat 15 new — 125.8 KiB
🆕 agents/internal 1 new — 153 B
Changed exports (16)
Import Gzip change Size now
🆕 agents/chat#startAgentToolTurn — 125.8 KiB
🆕 agents/chat#carryForwardAgentToolRuns — 125.6 KiB
🆕 agents/chat#cancelAgentToolTurn — 124.7 KiB
🆕 agents/chat#agentToolTurnChunks — 3.1 KiB
🆕 agents/chat#inspectAgentToolTurn — 3.1 KiB
🆕 agents/chat#tailAgentToolTurn — 3 KiB
🆕 agents/chat#reclaimAgentToolStreams — 2.7 KiB
🆕 agents/chat#progressCreditOf — 2.6 KiB
🆕 agents/chat#liveTurnsOf — 2.6 KiB
🆕 agents/chat#releasedAgentToolRunOfRequest — 600 B
🆕 agents/chat#releasedAgentToolRunWaiting — 571 B
🆕 agents/chat#recordAgentToolProgress — 516 B
🆕 agents/chat#agentToolTurnOf — 431 B
🆕 agents/chat#agentToolTurnId — 417 B
🆕 agents/chat#RELEASED_AI_CHAT_AGENT_TOOL_TABLES — 415 B
🆕 agents/internal#FIBER_TASK — 153 B
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 1197fa31 → f903bf45 · workflow run · reported by agent-think[bot]

@mattzcarey
mattzcarey force-pushed the slim/agent-runs-r3 branch 2 times, most recently from daa5893 to e046c98 Compare November 27, 2026 13:57
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 14:34
devin-ai-integration[bot]

This comment was marked as resolved.

mattzcarey added a commit that referenced this pull request Nov 27, 2026
@mattzcarey
mattzcarey marked this pull request as draft November 27, 2026 14:43
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 15:00
devin-ai-integration[bot]

This comment was marked as resolved.

@mattzcarey
mattzcarey marked this pull request as draft November 27, 2026 15:10
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 15:10
@mattzcarey
mattzcarey marked this pull request as draft November 27, 2026 15:23
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 15:23
devin-ai-integration[bot]

This comment was marked as resolved.

@mattzcarey
mattzcarey marked this pull request as draft November 27, 2026 15:37
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 15:37

@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/ai-chat/src/index.ts Resolved
…nt-tool child rows (expected to fail until R3-identity)
… run's metadata; tests on the chat-turn fixture
…turn's run

The child side of an AIChatAgent agent-tool run moves onto the chat module (chat/agent-tool-turns.ts): start, inspect, chunks, a tail that follows the turn's stream, progress and milestones on the run's metadata (and on its live reply), cancel marked at once. The seam the switch carried (AgentToolRunsHost mapping, turn-start hook, clear generation) and AIChatAgent's AgentToolRuns are deleted. The released cf_ai_chat_agent_tool_runs/milestones rows are carried onto chat-turn runs agent-tool:<runId> and the tables dropped; the upgrade test is now 'it'. Tests that pinned the old store, tail fan-out, live counters and the old recovery engine's agent-tool hooks are removed with them; the rest read the public API.
…ild and reports the stop's reason

The chat module stops a turn with a TaskCancellation, which is neither an Error nor serializable: the parent's cancel to the child failed over RPC (and was swallowed), so the child ran on, and the run's error read [object Object]. The parent now turns any stop reason into text before it uses or sends it (facet-probe S1, S2).
…d run carried as interrupted stops its carried turn

The turn writes its last chunks as it stores the reply and drops its stream, in one step a reader cannot see, so a parent following live lost the finish (rv-6). When the stream ends without it, the tail sends the stored reply's finish (with the message's metadata, which a replay's finish now carries too). A released run still running is carried as an error; the chat turn the upgrade carried for it is now stopped, so it calls no model (rv-6's note).
… cleared, with its agent type

The clear deleted the run's task before the awaiting caller read it, so at the root the caller got 'deleted before it finished' with no agent type (rv-6). A clear of a run a caller in this isolate awaits records it, and the caller reports the clear. Also a test of a multi-step child's reply reaching a live parent whole (tool step, pause, milestone, text step).
…e its reply is stored

The turn writes its last chunks in the step that drops its stream, so a parent following it lost whatever came after the last flush (facet-probe F1: a fast reply lost its last text step), and a parent attaching later got a rebuild of the stored reply instead of the chunks a live parent got (F2). The run's metadata asks the chat module to keep the stream (chat.keepStream), as the release kept the child's reply stream: the tail reads every chunk to the end and a late replay equals the live chunks. One kept stream per agent-tool run, on the run's own child.
…eam, and from its stored reply when it has none
… stored reply exactly, and a tail cut short as the turn ended is finished from it

Per arch's F2 ruling the agent-tool turn no longer keeps its stream. The rebuild (chunksOfMessage, per part chunksOfPart) now makes the stored reply exactly through a tab's accumulator: steps opened and closed, reasoning, provider metadata, tool input/output/error/approval/denial, data parts in place (a milestone once), sources, and the finish with the message's metadata. F1 without a kept stream: when a tail's read ends before the reply's finish (the turn writes its last chunks in the step that drops the stream), it sends the chunks that take what it sent to the stored reply (remainingChunks): the rest of an open text or reasoning part under its id, missing tool outputs, unstarted parts, steps, finish. The parent's replay skips a stored milestone the replayed chunks already carried.
…gent-tool run (releasedAgentToolRunOfRequest), and the carry-forward leaves a run whose turn it carried on under the run's id running, with what its row kept
…carries on

When the released turn being carried (a cut-off chat turn, or a recovery the release scheduled) belongs to an open agent-tool child run, it is carried under agent-tool:<runId> with the run's metadata, retained, so that run carries on and its parent gets its result (arch's U2 ruling; limits acked the two methods). The carry-forward keeps such a row until its turn is carried (it runs at start, before the turn is), then puts what the row kept onto the run and drops the tables. Upgrade test red before.
… reads; a released run whose turn is still to be carried reads running

The carry-forward starts in the constructor and its pending-turn check read Tasks before Tasks had started (on an upgraded child its table still had the release's shape: 'no such column: status'), so the promise failed and every inspect that awaited it threw: the parent ended the run interrupted ('could not be inspected', rv-6) or a detached run stayed running (facet-probe U3). It now awaits Tasks first; a failed carry is logged, not thrown at each read; and a released run still waiting for its turn reads running, so a parent that asks first keeps waiting. Test: the in-flight upgrade case inspects before the turn is carried (red before).
…et empties the released tables instead of dropping them

Per arch's amended F2 ruling: an agent-tool turn keeps its stream, completed, once its reply is stored (chat.keepStream), as the release kept an agent-tool child's reply stream; it is reclaimed when the child's next agent-tool turn starts and goes with a clear or the facet. The rebuild path (chunksOfMessage, chunksOfPart, the tail's completion from the stored reply) is deleted: a late parent replays the live chunks by the same positions. rv-6's FIX: a facet must not drop a table an earlier version made, so the carry-forward deletes the rows there and leaves the empty table (only a root drops it); the next start skips an empty one. Tests: the kept stream and its reclaim, the facet carry.
…e child's progress as its own

As released, a parent AIChatAgent turn waiting on an agent-tool child is credited when the child's chunks are forwarded (at most once per 5 s), so its no-progress window does not run out while the child streams and a cut-off parent turn is recovered, not given up. AIChatAgent overrides _onAgentToolStreamProgress to add a credit to the running turn's run metadata (chat.progressCredit); the chat-turn definition counts those credits with the chunks it streamed (chat-host hunk, limits' ack). Tests red before: chat-turn-definition 'counts a credit the host gave the turn as progress', agent-tool-progress-credit.
…ld's own places, so live positions equal a later replay's after a milestone

A child whose stream stores its milestone frames (an AIChatAgent run) gives each a place; the parent numbered a milestone without advancing its count, so the next chunk took the same position live and every later one was one behind the replay (rv-6). The parent now keeps the child's own place for each stored chunk, from where the first one met its numbering; a child that broadcasts its milestones (Think) numbers the same as before. Test with a milestone mid-step, red before.
- A released turn the app declines to recover (or that the conversation moved past) ends its agent-tool run as an error instead of leaving it running.
- A released run too large for run metadata is carried with its summary (capped) and the carry goes on with the rest; carried progress keeps its time (last_signal_at).
- The tail is handed back at once: a turn that has not opened its stream is waited for in the first read, so the parent's deadlines apply.
- A run's output hook gets the messages from its own input on, not replies of turns that ended while it was queued (inputMessageId in its metadata).
- A clear deletes the replies settled agent-tool runs kept; kept streams are found by id over all stream rows, not the newest 100.
- A run carried across the upgrade keeps its stream too; what a recovery declined to keep is not replayed.
- Chunk reads are paged to REPLAY_PAGE_BYTES again.
Tests red before for each behaviour (agent-tool-turn-host, agent-tool-child-upgrade, chat-host/agent-tool-turns, agent-tools facet carry).
…heck: no storage-name literals in ai-chat's index.ts

The parent meets the child's numbering at the first chunk with a place, a leading milestone included (Devin; test red before). The released ai-chat table names are RELEASED_AI_CHAT_AGENT_TOOL_TABLES in the chat module, and a released turn still owed is looked for among Tasks runs (its fiber row carried onto FIBER_TASK) instead of reading cf_agents_runs, so ai-chat's index.ts names no table (instance-names check).
…d whole (in its input); a tail on a settled run reads every page

Devin on 038c38c: the oversized fallback kept only the summary, so a parent could get a completed run with no output; the run's fields now go into its input (up to 16 MiB in parts, more than a released row held), read only for such a run. A tail opened after the run settled closed after one page of chunks; it now reads page after page.
@mattzcarey
mattzcarey marked this pull request as draft November 27, 2026 17:11
@mattzcarey
mattzcarey marked this pull request as ready for review November 27, 2026 17:11
@mattzcarey

Copy link
Copy Markdown
Member Author

Replaced by #3504, which carries this change with the rest of the switch (integrated and tested together).

@mattzcarey mattzcarey closed this Nov 28, 2026
mattzcarey added a commit that referenced this pull request Nov 29, 2026
* Chat: AIChatAgent runs its turns on the chat module, and an agent-tool run is its chat turn's run

One unit, three branches that land together: `slim/chat-fn-6d` (the chat functions, #3298), `slim/chat-fn-6s1` (AIChatAgent onto them, #3361), `slim/agent-runs-r3` (R3-identity, #3475). Review `git diff slim/local-main...slim/agent-runs-r3`; each branch is the one below it plus its own commits.

`AIChatAgent`'s turns now run on the shared chat module: `submitTurn`, `clearChat`, `answerTool` and `chatDispatch` over `ChatDeps`, and one turn definition, `chatTurnDefinition`. Its old turn engine, recovery engine instance and host-interface implementations are deleted, and an agent-tool run on an `AIChatAgent` child is that child's chat turn (`agent-tool:<runId>`), so the child's separate run store and the seam between the two are deleted too.

Why:
- Think's harness and `AIChatAgent` each had their own implementation of a chat turn, its recovery and its socket protocol; this leaves one.
- A turn is one durable Task run across attempts, so a recovered reply keeps its request id and ends once.
- Rows a release left (a cut-off turn, a scheduled recovery, the last terminal, agent-tool child rows, a run in flight) are carried forward once at start, each with an upgrade test.

Kept as before the switch, each with a test: a tool answer's continuation asks the model 50 ms after the answer and a stop inside that window drops it; `tool:result`, `tool:approval`, `message:cancel`, `chat:continuation:dropped` and `chat:request:failed` are published, and a spent recovery budget publishes `chat:recovery:exhausted`; a stop during a recovered attempt turns the recovering status off; an agent-tool run under a stopped turn reports a plain abort.

What a user can see change is exactly the changeset lines (`.changeset/chat-turns.md`, `chat-recovery.md`, `agent-tools.md`); everything else matches main. The deleted tests and their successors are listed in `archive/report-limits-switch-successors.md`. No public API is added: `agents/chat` stays `@internal`, and `ChatHooks.isReplay` and `ChatTurnResult.gaveUp` are internal to it.

Cost (`probes/perf`, local workerd, 60 rows, at 826bcd46a, whose product code is the head's; release values from PERF-BUDGET Table 1, base `slim/local-main` f9564d8). Cells are statements / rows written / rows read:
- **Every `AIChatAgent` row is at or below the release in all three.** turn-short 67 / 20 / 60 (release 102 / 26 / 79); turn-paced-20, a reply of 20 chunks 50 ms apart, 72 / 25 / 65 (release 108 / 28 / 85); queued-3 294 / 91 / 338 (release 423 / 109 / 349); recovery-abort 176 / 70 / 232 (release 411 / 98 / 598); turn-slow-300 101 / 54 / 94 (release 192 / 56 / 169); resume-mid-stream 110 / 55 / 103 (release 196 / 56 / 172); startup-empty 55 / 48 / 91 (release 87 / 88 / 831).
- **Against the base (main), a turn makes more statements and reads more rows, and writes fewer:** turn-short 67 / 20 / 60 against 56 / 25 / 49; queued-3 294 / 91 / 338 against 238 / 102 / 216. A turn is a Task run now: it reads its run and its checkpoint, the stored request context and the transcript at its start, where the old engine held them in memory. I have not attributed each statement.
- A paused model's buffer is written at most every 250 ms, so a reset loses at most 250 ms of what a paused model had sent; with that a paced reply writes fewer rows than the release (25 against 28). A connect makes one more statement than the release (the lane read). `submitTurn` reads each sent message once to compare it with the stored one.
- ThinkHarness, which shares the turn definition: `harness/prompt-*` rows are +8 statements, +1 row written and +7 rows read against the base (prompt-hello 67 / 21 / 86, base 59 / 20 / 79, release 74 statements), except prompt-paced-20, which falls to 72 / 26 / 91 (base 78 / 39 / 98, release 36 rows written). I have not attributed the +8 statements.

Validated on `slim/agent-runs-r3`:
- chat-host, the chat node project, the harness suite, the whole ai-chat suite and Think's class suite pass.
- Think's harness config, test by test against the base run the same way: 16 gained; one timing test (`detached-reconcile-lane`, an alarm that must return within 15 s) failed in the full run beside two other suites and passes alone on the head.
- Each fix folded in after the last review has a test that failed first: the sub-agent count starting again for a chat turn; a given-up turn's end reaches `onChatResponse` after a reset; a `continueLastTurn` with nothing to continue sends no frame; ThinkHarness's `continue` of a finished reply calls the model; a host that runs its own tools may ask again for a call it holds.
- Deployed gate by verify, root and facet, against main and the release: owed on this head.

In a sub-agent the Lifecycle counts a job's attempts that never settled and seals the job at three. A turn is one run now, so that count would have ended a turn cut off by resets before chat recovery's own budget could. A chat attempt that finds the one before it died, mid-reply or before it streamed, counts it in the recovery budget and offers it to `onChatRecovery`, as before; it then tells Tasks, and the Lifecycle's count for that run starts again (two `@internal` members: `Tasks.interruptionsCounted`, `LifecycleJobs.attemptsCounted`).

Unit: slim/agent-runs-r3 @c1c88c257 (group: slim/chat-fn-6d @bdd3c88c8, slim/chat-fn-6s1 @9341dad6a)

* Chat turns: a completed reply that ends in reasoning is kept; the reasoning is left out of the model request (F21)

A stored assistant reply that ends in reasoning is no longer rewritten or removed by the before-turn repair. The turn definition hands the host two lists: `ChatModelCall.messages`, the request view with trailing reasoning left out and a reply left empty dropped, and `ChatModelCall.transcript`, the stored list.

Why:
- Anthropic rejects a request whose assistant message ends in a thinking block, so the repair used to delete that reasoning from storage.
- A model may complete a reply with reasoning only; the user then saw it disappear when they asked again, and the turn had no assistant message.

Applies to `AIChatAgent`, Think's class and the harness-backed Think. The changeset line is in `.changeset/chat-turns.md`; the chat guide and `design/chat-turn-core.md` are updated.

Cost: no extra read or write; the request view is one more pass in memory over the messages the turn already read.

Validated: ai-chat `continue-last-turn` and `chat-turn-races`, Think's `empty-reply` and `client-tools`, and the harness suite pass. Stacked on `slim/agent-runs-r3`; it lands right after that unit.

Unit: slim/inbox-f21-b @640f50be4 (applied by tree: local-main's tree == c1c88c257, the unit's base)

* Chat: step (d), what the switch left alive in ai-chat and the chat module's index

One unit, stacked branches (`slim/switch-d`, `-d2`, `-d3`, `-d4x`, `-d5x`, `slim/switch-mcp-wait-on-d`, top `slim/switch-e`), lands by its top. `packages/ai-chat/src/index.ts` goes from 3,074 to 1,623 lines (904 of code); what a user can see: the two fixes of things the switch dropped (the MCP wait, the memory-limit seal) and the two Tasks fixes below.

**Behaviour:**
- `waitForMcpConnections` is honoured again: a tab's request waits for the agent's MCP connections before `onChatMessage`, with the configured timeout (default 10 s). The switch of AIChatAgent onto the chat module had left the setting with no reader, so a turn that started while connections were restoring saw an incomplete `getAITools()`. As before the switch, `saveMessages`, continuations and tool answers do not wait; a recovered attempt of a tab's request now does.
- A chat turn the alarm's memory-limit breaker seals is given up, not dropped: what it streamed is stored, `onExhausted` is called with `reason: "out_of_memory"`, `chat:recovery:exhausted` is published, every tab gets the terminal message and `onChatResponse` hears `status: "error"`. Before the switch AIChatAgent did this from `onAlarmMemoryLimit`; after it the turn is a Tasks run that Tasks fails and deletes from outside its handler, so the chat said nothing. Tasks gets an `@internal` register option `onSealed(runId)`, called before a sealed run is failed; the chat module's `giveUpSealedTurn` does the give-up. Nothing runs for a turn that is not sealed.
- Tasks starts a cancelled lane head's successor only once the cancelled attempt has returned, so a stopped turn has stored its reply before the next turn stores its question. The chat turn definition's own wait for this is deleted.
- A Task run that a platform failure struck in a live isolate runs at once on the next start.

**Deleted:**
- One read of an agent-tool run per chunk it streams (now one per turn).
- 196 names off `agents/chat`'s index that nothing imports (381 to 185).
- ai-chat's test worker loses 987 lines only the deleted old-engine tests used.
- In `index.ts`: single-caller pass-throughs, a set of resuming tabs nothing added to, an options type nothing passed, comments describing the old engine.

**Moved out of `index.ts`, same code behind small host objects:**
- `ai-chat/src/released-rows.ts`: the carry of rows an ai-chat release left.
- `ai-chat/src/agent-tools.ts`: the agent-tool child's side and detached delivery.
- `ai-chat/src/turn-host.ts`: the class as the chat module's host (`respond`, the turn's end, `onChatResponse` delivery, the wait behind `saveMessages`).
- `agents/src/chat/agent-tool-turns.ts`: the agent-tool progress wiring and the tail asked for before a turn's stream opens.
- `requestContextFromLegacy` and `abortReasonText` out of the old engine's files, so ai-chat imports nothing defined in `chat-turns.ts`, `recovery-engine.ts` or `agent-tool-runs.ts`.

`index.ts` now holds the released API with its docs (627 comment lines), the constructor's wrappers of the app's handlers, and the wiring of the four helper objects. Two `@internal` protected members left the class: `_persistOrphanedStream` and `_orphanStore`.

Not tested with a real memory-limit kill on AIChatAgent (a chat-host test drives the seal); ThinkHarness's chat turns still have that gap.

Not here: the old turn engine's files and the 14 old host interfaces in `agents/src/chat` are still used by Think's class and go when it moves onto the harness.

Validated: ai-chat 949 of 949 at each step, the same tests; agents' chat project 1,482; chat-host, tasks, lifecycle and agent-tool worker tests; Think's class suite on `slim/switch-d`; `tsc`, oxlint, oxfmt, exports, public-API and instance-name checks. The two Tasks changes, the MCP wait, the seal's give-up and the per-chunk read each have a test that fails without them (the old MCP tests only checked that a turn completes). Cost: one promise fewer per turn. No changeset: none of these bugs was released.

Unit: slim/switch-e @a014ec45c (step (d): switch-d..d5x, switch-mcp-wait-on-d, switch-e)

* Chat: PR 2's rulings: a clear that reaches a streaming reply ends its request's frame aborted (as before the switch); AIChatAgent warns once when a subclass overrides continueLastTurn; changeset lines for the kept differences

* fix(ai-chat): the continueLastTurn warning is only for a class that overrides it: the override is looked for before Agent puts its method wrappers on the class's prototype, once per class
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