Skip to content

feat(agui): resume active runs from the session log - #4026

Draft
chcodex wants to merge 4 commits into
agentscope-ai:mainfrom
chcodex:feat/agui-session-log-hydrate
Draft

chcodex wants to merge 4 commits into
agentscope-ai:mainfrom
chcodex:feat/agui-session-log-hydrate

Conversation

@chcodex

@chcodex chcodex commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor

What

Adds a reconnect path for an AG-UI run: when the browser refreshes or the connection drops, the client can reattach to a run that is still executing and keep receiving its events, without starting a new run.

attach is a read-only observer. It never starts, resumes or interrupts an agent, never calls a model, and never writes to the session log. The same cursor always produces the same events, so retrying a reconnect is safe.

API

  • AguiRequestProcessor.attach(AguiRuntimeContextRequest) — cursor and execution run id both resolved from the request (Last-Event-ID or forwardedProps.agentscope.*).
  • AguiSessionLogReplay.attach(input, log, after, executionRunId, config) — for applications that resolve the SessionLog themselves.
  • AguiFramedEvent carries the AG-UI event plus the native SessionEvent.seq(), exposed as the SSE id.

How it works

  1. The application supplies its history and a cursor that is a presentation boundary.
  2. attach replays committed events after the cursor, projecting each SessionEvent into AG-UI events (text, reasoning, tool calls/results, interactions, interrupts).
  3. While the run is active it follows the session log by polling until run/end; when the run has already ended it drains the remaining events and finishes with RUN_FINISHED or RUN_ERROR.
  4. Failures are reported as RUN_ERROR frames rather than transport errors, so the caller can decide how to degrade.
  5. A reconnect whose cursor already passed run/start still opens with a synthetic, uncursored RUN_STARTED, so official AG-UI clients accept the stream.

Cursors are native SessionEvent.seq() values; they are not AG-UI fields and must not be mixed with another session or the Service SSE cursor.

Message ids

Replayed assistant messages use the committed turn identity instead of the per-model-call id:

  • assistant text messageId = SessionEvent.turnId();
  • reasoning messageId = SessionEvent.turnId() + ":reasoning", so reasoning never shares the text id;
  • modelCallId remains only for tool-call attribution (lastToolCallByModelCall), never for text or reasoning ids.

One turn can span several model calls. The first text segment opens the turn id with TEXT_MESSAGE_START, model/end closes it with TEXT_MESSAGE_END, and text after a tool call reopens the same id with a new TEXT_MESSAGE_START. A chunk that arrives while the id is still open does not emit another TEXT_MESSAGE_START. Reasoning follows the same lifecycle under its :reasoning namespace, so streamed and replayed SessionLog projections produce the same ids for the same committed events.

Relation to #4068

#4068 pins one live assistant text message id per assistant reply in AguiStreamContext / TextBlockEventConverter; this PR applies the same one-id-per-turn rule to the SessionLog replay projection and does not touch those live-path files. The changes are complementary and can land independently: #4068 removes per-model-call ids from the live stream, and this PR removes them from replay. #4068 currently pins the outer AgentStartEvent.replyId; if it later switches to event.getExecution().turnId(), live and replay will also share the exact id value, not only the rule.

Tests

  • AguiSessionLogAttachTest — replay, cursor-ahead waiting, uncommitted boundaries, error frames, terminal status, run isolation, synthetic RUN_STARTED.
  • AguiSessionPresentationTest — projection of text/reasoning/tool/interaction events, turn-scoped text and reasoning ids, reopen-without-duplicate-START, streamed/replayed id parity.
  • AguiSessionCursorTest, AguiRequestProcessorSessionLogTest.

agentscope-extensions-agui: 546 passing. agentscope-core is unchanged.

Known limitations

  • Following a live run is poll-based (commit granularity is the recorder heartbeat), so text arrives in batches rather than per token.
  • SSE id is emitted on completed events (model/end, interactions) so a reconnect resumes at a message boundary; a follow-up will also cover tool results and run lifecycle frames.
  • The recovery path requires a HarnessAgent with SessionHistoryMode.EVENT_LOG.

Merge order

@mintlify

mintlify Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Preview approval required

This pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit 78818d4.

Approve preview

@chcodex
chcodex marked this pull request as draft November 6, 2026 09:44
@chcodex
chcodex force-pushed the feat/agui-session-log-hydrate branch 2 times, most recently from 32102ac to 4318a50 Compare November 6, 2026 14:13
@jujn jujn added the P2 重要不紧急 label Nov 7, 2026
@chcodex
chcodex force-pushed the feat/agui-session-log-hydrate branch from c21d7e9 to 78818d4 Compare November 8, 2026 07:12
chcodex added a commit to chcodex/agentscope-java that referenced this pull request Nov 8, 2026

This branch has not been deployed

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

Labels

P2 重要不紧急

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants