Skip to content

feat(agui): report a cancelled tool call and conversation optimization - #1722

Merged
edenreich merged 2 commits into
mainfrom
feat/issue-1713-wire-gaps
Nov 6, 2026
Merged

edenreich merged 2 commits into
mainfrom
feat/issue-1713-wire-gaps

Conversation

@edenreich

@edenreich edenreich commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

Part of #1713

Summary

Two agent events the chat TUI renders had no AG-UI form, so the serve worker dropped them and no client of the stream could show them. Both are now activities, the form the protocol already uses for transient progress.

Changes

  • ToolCancelledEvent -> ACTIVITY_SNAPSHOT tool_progress keyed tool:<toolCallId> with the new status cancelled. It reuses the existing activity, so a client that tracks a tool by that key sees its last status.
  • OptimizationStatusEvent -> ACTIVITY_SNAPSHOT optimization_status keyed optimization, content message, originalCount and optimizedCount. The event's IsActive flag is left off the wire: the agent loop only ever reports the finished optimization, so the field would always be false.
  • docs/ag-ui-output.md lists both in the event table and the Activity table.
  • Tests: two cases added to the encoder's activity table.

Compatibility

  • Additive. The chat TUI's current decoder ignores an unknown activity type, and its tool progress handling has no case for cancelled, so daemon chats render as before until the TUI moves onto AG-UI events.

What the audit found was not missing

  • Chat start is RUN_STARTED.
  • Screen recording, screen control and computer-use actions already ride the screenRecording and screenControl state keys and the computer_use activity.

Downstream

  • The browser extension and the desktop app can show both activities. They ignore unknown activity types today, so optimization_status needs no coordinated release.
  • cancelled is a new status on the known tool_progress activity, so ignoring unknown activity types does not cover it. Org code search found no tool_progress consumer outside this repo, so check how the extension and the desktop app treat an unknown status.
  • Docs follow-up: [DOCS] AG-UI: cancelled tool status and optimization_status activity docs#1110

@edenreich
edenreich requested a review from a team as a code owner November 6, 2026 18:20
@github-project-automation github-project-automation Bot moved this to Todo in 2026 Nov 6, 2026
@edenreich
edenreich changed the base branch from main to refactor/issue-1713-dead-computer-events November 6, 2026 18:36
@edenreich
edenreich added this pull request to stack #1726 November 6, 2026 19:03
@edenreich
edenreich force-pushed the feat/issue-1713-wire-gaps branch from b0b6c20 to 7ff03a6 Compare November 6, 2026 19:37
@edenreich
edenreich force-pushed the feat/issue-1713-wire-gaps branch from 19fae5b to 7bfc446 Compare November 6, 2026 22:30
Base automatically changed from refactor/issue-1713-dead-computer-events to main November 6, 2026 22:30
Two agent events the chat TUI renders had no AG-UI form, so no client of the
stream could show them. A tool call stopped before it ran is now a
tool_progress activity with the status cancelled, and a finished conversation
optimization is an optimization_status activity with the message counts.
@edenreich
edenreich force-pushed the feat/issue-1713-wire-gaps branch from 7bfc446 to c79ef8a Compare November 6, 2026 22:31
@edenreich
edenreich merged commit 68756dd into main Nov 6, 2026
@edenreich
edenreich deleted the feat/issue-1713-wire-gaps branch November 6, 2026 22:31
edenreich added a commit that referenced this pull request Nov 6, 2026
Part of #1713. Stacked on #1722 (which stacks on #1721 and #1719).

## Summary

Phase 3 of the plan: the client side of the AG-UI stream moves into the
TUI and onto typed events. `headless.RunDecoder` is gone.
`tui/runview.Reducer` replaces it, built on `agui.Decode`, and the
daemon chat uses it.

## Changes

- `internal/presentation/tui/runview` (new): `Reducer` folds a thread's
AG-UI events into the chat events the TUI handlers render. `Reduce`
takes a typed `agui.Event`, `Decode` takes a raw frame. The step
reconstruction, the held completion and the mid-run attach tolerance are
unchanged.
- The hand-written frame structs (`decodedFrame`, `decodedPatch`) are
deleted. The reducer switches on the SDK's event types through the
`agui` aliases.
- `internal/presentation/headless/run_decoder.go` and its test are
deleted from `headless`, which now only writes the protocol.
- `agui.InterruptPlanApproval` joins the other interrupt reasons in
`agui`, replacing the unexported `headless` constant both sides needed.
- The reducer reads the two activities #1722 added, so a daemon chat now
shows a cancelled tool call and a conversation optimization.
- `tui/daemonthread.Agent` uses the reducer. Nothing else in the TUI
changes.

## Deviation from the plan

The plan had the reducer return `tui.*` messages directly and bypass the
handlers for daemon chats. That would leave two run renderers in the TUI
(handlers for local chats, reducer for daemon chats) until the last
phase. The reducer keeps returning the chat events the handlers already
take, so there is one renderer at every step. The handlers stop
depending on agent-owned event types in the last phase, once local chats
also arrive as frames.

## Verification

- The reducer's round-trip tests against `RunEncoder` moved with it and
pass, with one new case for the two activities.
- `go test ./...`, `task precommit:run` (0 issues) and the e2e suite
with `-race` (`ok tests/e2e 168s`), which covers a daemon chat turn,
reattach, direct commands and teleport.

## Downstream

- no docs ticket: internal-only refactor
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.246.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant