Skip to content

feat(agui): carry the next-step suggestion on the AG-UI run state - #1712

Merged
edenreich merged 3 commits into
mainfrom
fix/issue-1710
Nov 6, 2026
Merged

edenreich merged 3 commits into
mainfrom
fix/issue-1710

Conversation

@inference-gateway-maintainer

Copy link
Copy Markdown
Contributor

Resolves #1710

Summary

AG-UI runs in --serve mode now carry the same one-line next-step suggestion the chat TUI shows as ghost text after an assistant turn (the feature of #1546). The serve run patches a new nextStepSuggestion state key just before its terminal event, so an AG-UI client such as the desktop app (tracked in inference-gateway/desktop#439) can offer the same suggestion. ChatSuggestionGenerator is reused as-is through a headless Services accessor, so disabled, failed, timed-out and discarded suggestions stay silent-fail, the daemon-thread nil case stays a no-op, and the suggestion call's tokens land in the session totals the run already reports in its usage state and RUN_FINISHED result.

Changes

  • internal/protocols/agui/run.go: new nextStepSuggestion state key seeded "" in seedState, so every STATE_SNAPSHOT always carries it
  • internal/presentation/headless/run_encoder.go: RunEncoder takes an optional SuggestNextStep source and patches its suggestion into the run state before the terminal event, with Finish ordering the patch ahead of RUN_FINISHED/RUN_ERROR. A failed or cancelled run, an unwired source and an empty suggestion publish nothing (same silent-fail semantics as the TUI)
  • internal/presentation/headless/serve.go: the serve run wires the generator in via svc.GetNextStepSuggestionRunner().GenerateNextStepSuggestion
  • internal/presentation/headless/headless.go: the headless Services interface gains the accessor, returning the concrete generator
  • internal/container/container.go: GetNextStepSuggestionRunner returns *conversation.ChatSuggestionGenerator so the TUI contract and the headless Services contract share the one accessor, with the daemon-thread nil case unchanged
  • Tests in internal/presentation/headless cover the published patch before the terminal event, the disabled/unwired/empty cases (no patch) and a failed run (the generator is never even asked). The internal/protocols/agui seeded-state tests now check the new key
  • docs/ag-ui-output.md lists the state key in the event mapping and State sections

No downstream schema change: the key is the CLI's own run state, so only AG-UI clients read it. The desktop side is tracked in inference-gateway/desktop#439.

The serve worker seeds a nextStepSuggestion state key on every AG-UI run and patches it with the ChatSuggestionGenerator line before the terminal event, so AG-UI clients such as the desktop app get the after-turn suggestion the chat TUI shows as ghost text.

The generator is reused through a headless Services accessor with the same silent-fail semantics as the TUI, and the suggestion call's tokens land in the session usage the run already reports.
…cellable

The serve run asked for a suggestion under context.Background, so worker
shutdown could not stop it. It now runs under the turn's context, and a turn
with a queued message or a subagent's worker asks for none.

The chat TUI got a typed nil pointer as its suggestion runner on a daemon
thread, which defeated its nil check. It gets a nil interface again.
The run encoder kept its own failure field next to the error the AG-UI run
already holds. The run now exposes Err and the encoder asks it, so the
suggestion follows the outcome of the run that ends.

The suggestion tests no longer share a counter across rows, and a row pins
that a container building no generator suggests nothing.
@edenreich
edenreich merged commit 62f0913 into main Nov 6, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-1710 branch November 6, 2026 16:41
@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.

[FEATURE] Provide the next-steps suggestions via AG-UI so it could be used it in the desktop app

1 participant