Repository navigation
feat(agents): opt-in terminal-only event delivery for runAgentTool - #2364
Conversation
🦋 Changeset detectedLatest commit: d8b75dc The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 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 import sizes: no significant changes ( |
agents
@cloudflare/ai-chat
@cloudflare/codemode
hono-agents
@cloudflare/shell
@cloudflare/think
@cloudflare/voice
@cloudflare/worker-bundler
commit: |
1c06f3f to
79e30d9
Compare
| body: JSON.stringify({ | ||
| type: AGENT_TOOL_MILESTONE_PART, | ||
| data: { | ||
| name: milestone.name, | ||
| sequence: milestone.sequence, | ||
| at: milestone.at, | ||
| ...(milestone.data !== undefined ? { data: milestone.data } : {}) | ||
| } |
There was a problem hiding this comment.
🟡 Replayed milestones lose progress details
When a milestone reports a fraction, phase, or message, _broadcastAgentToolMilestones replays it without those fields. Fresh clients show an incomplete progress snapshot after reconnect.
Learn more
AgentToolProgressEmitter.report sends fraction, message, and phase with a live milestone. The child milestone ledger stores name, sequence, time, and optional custom data only. Synthesizing a replay frame from that ledger therefore discards the live progress fields; applyToRun reconstructs progress from fields in the frame.
Example: A child reports { milestone: 'indexed', fraction: 0.7, phase: 'indexing' }. The live parent shows 70% and 'indexing', but a new client replaying the milestone only sees its name.
Recommended fix: Persist the milestone's progress fields alongside its durable record and include them in replay frames, or restore the latest child progress snapshot separately when replaying.
Was this helpful? React with 👍 or 👎 to provide feedback.
cf94a0e to
d8b75dc
Compare
| ### Deliver only progress and the final result | ||
|
|
||
| By default, the parent forwards every chunk of the child's stream to its | ||
| clients, and the child broadcasts the same chunks to its own connections. When | ||
| nobody watches the child's text as it streams (for example, a server-side | ||
| pipeline that only reads the result), pass `eventDelivery: "terminal"`: | ||
|
|
||
| ```ts | ||
| const result = await this.runAgentTool(ResearchAgent, { | ||
| input: { query: "Durable Objects" }, | ||
| eventDelivery: "terminal" | ||
| }); | ||
| ``` | ||
|
|
||
| The run still produces `started`, progress, milestone, and terminal | ||
| (`finished`, `error`, `aborted`, or `interrupted`) events, and the result, | ||
| summary, and output are unchanged. Ordinary child chunks are not forwarded to the | ||
| parent's clients, are not replayed on reconnect, and are not broadcast by the | ||
| child. The child still stores its own conversation, so `getAgentToolChunks()` | ||
| and drill-in continue to work. Detached runs do not support | ||
| `eventDelivery: "terminal"` and reject it. |
## pnpm-workspace.yaml (default) ## Dependency Updates | Package | From | To | Type | | --- | --- | --- | --- | | `agents` | 0.24.0 | 0.25.0 | minor | ## Release Notes <details> <summary><b>agents</b> (0.24.0 → 0.25.0)</summary> ### Minor Changes - [#2005](cloudflare/agents#2005) [`c2f7672`](cloudflare/agents@c2f7672) Thanks [@<!---->cjol](https://github.com/cjol)! - Native RPC calls to async Agent and Think methods now start lifecycle initialization first; address Agents by name because raw IDs from `newUniqueId()` and `idFromString()` now fail their first async RPC. See [Lifecycle](https://github.com/cloudflare/agents/blob/main/docs/agents/lifecycle.md). ### Patch Changes - [#2390](cloudflare/agents#2390) [`c55ec80`](cloudflare/agents@c55ec80) Thanks [@<!---->threepointone](https://github.com/threepointone)! - Report a failed agent-tool child as failed even when it was evicted before recording the failure. See [Agent tools](https://github.com/cloudflare/agents/blob/main/docs/agents/agent-tools.md). - [#2384](cloudflare/agents#2384) [`f904999`](cloudflare/agents@f904999) Thanks [@<!---->threepointone](https://github.com/threepointone)! - Fix agent-tool chunks being duplicated or dropped on reconnect, child re-attach, and fiber recovery. See [Agent tools](https://github.com/cloudflare/agents/blob/main/docs/agents/agent-tools.md). - [#2364](cloudflare/agents#2364) [`5e0507e`](cloudflare/agents@5e0507e) Thanks [@<!---->threepointone](https://github.com/threepointone)! - Add `eventDelivery: "terminal"` to `runAgentTool` to forward only lifecycle, progress, and milestone events for a run. See [Agent tools](https://github.com/cloudflare/agents/blob/main/docs/agents/agent-tools.md). - [#2448](cloudflare/agents#2448) [`54f9ca7`](cloudflare/agents@54f9ca7) Thanks [@<!---->aron-cf](https://github.com/aron-cf)! …[full notes](https://github.com/cloudflare/agents/releases/tag/agents%400.25.0) </details> --- *This PR was auto-generated by [catalog-update-action](https://github.com/brandhaug/catalog-update-action).* Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
## pnpm-workspace.yaml (default) ## Dependency Updates | Package | From | To | Type | | --- | --- | --- | --- | | `@cloudflare/ai-chat` | 0.12.0 | 0.12.1 | patch | ## Release Notes <details> <summary><b>@<!---->cloudflare/ai-chat</b> (0.12.0 → 0.12.1)</summary> ### Patch Changes - [#2390](cloudflare/agents#2390) [`c55ec80`](cloudflare/agents@c55ec80) Thanks [@<!---->threepointone](https://github.com/threepointone)! - Report a failed agent-tool child as failed even when it was evicted before recording the failure. See [Agent tools](https://github.com/cloudflare/agents/blob/main/docs/agents/agent-tools.md). - [#2384](cloudflare/agents#2384) [`f904999`](cloudflare/agents@f904999) Thanks [@<!---->threepointone](https://github.com/threepointone)! - Fix agent-tool chunks being duplicated or dropped on reconnect, child re-attach, and fiber recovery. See [Agent tools](https://github.com/cloudflare/agents/blob/main/docs/agents/agent-tools.md). - [#2364](cloudflare/agents#2364) [`5e0507e`](cloudflare/agents@5e0507e) Thanks [@<!---->threepointone](https://github.com/threepointone)! - Add `eventDelivery: "terminal"` to `runAgentTool` to forward only lifecycle, progress, and milestone events for a run. See [Agent tools](https://github.com/cloudflare/agents/blob/main/docs/agents/agent-tools.md). - [#2334](cloudflare/agents#2334) [`7f564e7`](cloudflare/agents@7f564e7) Thanks [@<!---->threepointone](https://github.com/threepointone)! - AI Chat and Think send the terminal `done` frame after persisting and broadcasting the assistant reply, so later sends are not overwritten. See [Chat agents](https://github.com/cloudflare/agents/blob/main/docs/agents/chat-agents.md). - [#2352](cloudflare/agents#2352) [`449ac27`](cloudflare/agents@449ac27) Thanks [@<!---->threepointone](https://github.com/threepointone)! - Do not start an automatic continuation after an …[full notes](https://github.com/cloudflare/agents/releases/tag/%40cloudflare/ai-chat%400.12.1) </details> --- *This PR was auto-generated by [catalog-update-action](https://github.com/brandhaug/catalog-update-action).* Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Ports three upstream changes to the legacy AIChatAgent's agent-tool child adapter onto AGUIChatAgent: - cloudflare#2364: opt-in terminal-only event delivery. Runs started with eventDelivery: "terminal" are tracked (and persisted on the run row) so their chunks are stored but not broadcast, including after a restart. - cloudflare#2384: seed a cold live sequence from the stored backlog before a tail attaches (replacing the post-drain realign), and inspectAgentToolRun(runId, { reconcile: false }). - cloudflare#2390: record a run's stream error on its open row so a stale-row reconcile after eviction reports error. The engine sends no error frame for an in-band RUN_ERROR, so that path records it directly. The test worker's unported() casts for _agentToolTerminalOnlyRuns and the inspectAgentToolRun options are replaced with the real members, and its finalize gate moves to _saveAGUIMessages, which is what the engine's agent-tool lifecycle calls.
Fixes #2298.
Summary
Adds
eventDelivery: "terminal"torunAgentTool. It is for headless parents that only need a child's result:AIChatAgent) stops broadcasting its own stream chunks to its connections. It still stores its conversation, sogetAgentToolChunks()and drill-in still work.cf_agent_tool_runsgains anevent_deliverycolumn (schema version 12). #2305 also bumps to 12, so whichever merges second takes 13.interceptAgentToolBroadcastnow returns the run id for content chunks, so the chat hosts can drop them.Tests
packages/think/src/tests/agent-tools.test.ts, "eventDelivery: terminal (#2298)":The three terminal-mode tests fail against
main. The agents, Think and ai-chat suites pass. Docs:docs/agents/agent-tools.md.