Skip to content

[TASK] Refactor the chat TUI to render its agent runs through the AG-UI protocol #1713

Closed

Description

@inference-gateway-maintainer

Summary

The chat TUI does not render its own agent runs through the AG-UI protocol. This came up while exposing the next-step suggestion on the AG-UI run state (#1710, PR #1712): the serve worker, the daemon binding and any AG-UI client share one event model, but the in-process TUI maps agentdomain.ChatEvents through its own handlers in internal/presentation/tui/handlers, a second mapping the two views have to keep in sync by hand.

What the code shows today:

  • The chat TUI's in-process runs are rendered event by event by the handlers under internal/presentation/tui/handlers (for example chat_handler.go). None of those packages imports internal/protocols/agui.
  • The TUI only touches AG-UI as a wire client when it follows a daemon thread: internal/presentation/tui/daemonthread/thread.go uses agui.Conn and frames as raw payloads it never decodes into the run model.
  • The headless side renders the same agent events with internal/presentation/headless/run_encoder.go on top of internal/protocols/agui/run.go, which is already a complete mapping: text, reasoning, tool calls and results, usage, todos, background tasks, interrupts and activities.

The refactor would make the TUI consume the AG-UI event stream for its own runs (or at least share the single mapping in internal/presentation/headless and internal/protocols/agui), so a feature like the next-step suggestion lands for every view at once, instead of once in the TUI handlers and once in the AG-UI encoder.

Acceptance Criteria

  • The chat TUI's in-process rendering shares one event mapping with the serve worker and the daemon binding, driven by internal/protocols/agui/run.go (or the RunEncoder), instead of a parallel switch over agentdomain.ChatEvent in the TUI handlers
  • Client-only consumption (the daemon thread following the binding) is preserved, including its framing and reconnect behavior
  • The TUI's per-view extras that have no AG-UI event (focus, input state, theme) stay in the TUI - the refactor moves the run rendering, not the chat UI itself
  • The AG-UI output docs (docs/ag-ui-output.md) stay accurate after the change

Metadata

Metadata

Assignees

No one assigned

    Labels

    refactor

    Type

    No type

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions