Repository navigation
feat(agui): split the AG-UI encoder into a per-run type shared by stdout and the WebSocket binding - #1407
Merged
Conversation
…nsports RunEncoder (Start/Handle/Finish) is now the one AG-UI encoder shared by stdout and the WebSocket binding. RunEncoder.emit writes each event with exactly one Write, so a transport can map one Write to one frame without a line splitter, and the extension bridge chat mirror drops its line splitter. headless --format ag-ui --session-id on an existing conversation emits the MESSAGES_SNAPSHOT the docs already promise right after RUN_STARTED, built by one snapshotMessages helper from the conversation entries (id, role, text content, assistant toolCalls, tool toolCallId, error when the execution failed). A cancelled turn ends with RUN_FINISHED outcome cancelled instead of RUN_ERROR, and a later computer-use resume keeps it one successful run. render.ApprovalAction is now the single mapping from an IPC approval response to a decision, and the encoder gained EmitApprovalResolved for the CUSTOM approval_resolved event keyed by tool_call_id.
inference-gateway-maintainer
Bot
marked this pull request as ready for review
September 29, 2026 01:34
inference-gateway-maintainer
Bot
requested a review
from a team
as a code owner
September 29, 2026 01:34
This was referenced Sep 29, 2026
…cancelled outcome from the run error snapshotMessages mapped every conversation entry, so a resumed run's MESSAGES_SNAPSHOT carried hidden system reminders, resume prompts and compaction prompts as user turns. It now skips hidden entries like every other history reader. The cancelled flag latched until a computer-use resume, so a failure after a cancelled turn still finished as RUN_FINISHED cancelled. Finish now derives the outcome from the run error itself. The run encoder tests drop the cases already covered by agui_test.go and gain a table for the terminal event.
Contributor
|
🎉 This PR is included in version 0.219.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #1397
Summary
agui.Renderwas the one AG-UI encoder, but it only ran as a whole-stream loop with oneRUN_STARTEDat the start and one terminal event when the channel closed. This splits the encoder into a small per-runRunEncodertype (Start/Handle/Finish) that the stdout transport and the WebSocket binding share. It uses the split to close the stdout contract gaps thatdocs/ag-ui-output.mdalready promised but nothing delivered: the resumeMESSAGES_SNAPSHOTand the AG-UIcancelledrun outcome.Changes
internal/protocols/aguiexposes the per-runRunEncoder:Start(threadID, runID),Handle(event),Finish() error.Renderstays as the whole-stream composition of start, range and finish. Its Go signature is unchanged, so existing consumers keep working, and the daemon binding and session worker from [FEATURE] EPIC - Consolidate events and external communication behind infer daemon #1396 can now drive one run per turn.RunEncoder.emitwrites every event with exactly oneWrite(one JSON event plus newline), so a transport can map oneWriteto one frame. The extension bridgechatEventWriterdropped its line splitter and now maps each write to onechat_eventframe.headless --format ag-ui --session-id <id>on an existing conversation now emits theMESSAGES_SNAPSHOTthatdocs/ag-ui-output.mdalready promised, right afterRUN_STARTED. The newsnapshotMessageshelper builds it from the conversation entries:id,role, textcontent, assistanttoolCalls, tooltoolCallId, anderrorwhen the tool execution failed. Hidden entries (system reminders, resume and compaction prompts) are skipped. Fresh runs pass no history and stay byte-identical.ChatCompleteEvent{Cancelled: true}now ends the run withRUN_FINISHEDcarrying outcomecancelled. The Go SDK has no constant yet, soRunFinishedOutcome{Type: "cancelled"}passes throughWithOutcome.Finishderives the outcome from the run error, so a laterComputerUseResumedEventkeeps a computer-use pause and resume one successful run, and a failure after a cancelled turn still ends inRUN_ERROR.TestRender_ComputerUsePauseResumeand all existingagui_test.goexpectations pass unedited.render.ApprovalAction(ipc.ApprovalResponse)is now the single mapping from a response to a decision (approvedwithscope: "always"auto-accepts, plainapprovedapproves, anything else rejects), andrender.AnswerApprovaluses it.EmitApprovalResolved(toolCallID)for the CUSTOMapproval_resolved{tool_call_id}event that the per-tool_call_idapproval contract needs. Stdout keeps emitting onlyapproval_request, so the documented wire bytes stay limited to the two contract changes.docs/ag-ui-output.mddocuments thecancelledoutcome and the resume snapshot behaviour.Notes
New behaviour coverage lives in
internal/protocols/agui/run_encoder_test.go(terminal event table covering success, cancelled, resume and error after cancel, snapshot ordering and mapping including hidden entries, oneWriteper event,approval_resolved) plusTestApprovalActionininternal/platform/render.Taskfile.ymlneeds no new mocks since no domain interface changed.