feat(streaming): add semantic text output disposition events - #3013
Open
dargoner wants to merge 20 commits into
Open
feat(streaming): add semantic text output disposition events#3013dargoner wants to merge 20 commits into
dargoner wants to merge 20 commits into
Conversation
按来源和任务关闭最后模型回复,并区分子代理成功、失败与取消结束。 补齐协议、AG-UI、前端和数据面的回归验证与最终修复报告。
透传子智能体生命周期、思考、文本处置、工具参数结果及任务标识。 修正 acting 中间件事件发布位置,避免事件遗漏或重复。
补齐本地子智能体的 AgentResultEvent 转发,避免只收到结束事件而缺少权威结果。 AG-UI 仅按当前运行实际生成的分段消息清理临时文本,避免误删合法历史消息。 Web 预览总线不再重放订阅前事件,并串行化并发发送以避免丢帧。
dargoner
force-pushed
the
codex/pr-stream-events-text-disposition
branch
from
September 6, 2026 13:20
f0f2f08 to
76413d6
Compare
dargoner
marked this pull request as ready for review
September 6, 2026 13:51
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.
AgentScope-Java Version
2.0.3-SNAPSHOT
Description
Background
TextDeltaEventpreserves provider-level token streaming, but it does not tell a consumer whether a text segment belongs to an intermediate model turn that will invoke tools or to the last user-visible reply. Today, adapters have to infer that intent from neighboring tool and lifecycle events. That inference is easy to implement differently across AG-UI, Agent Protocol, Web UI, and custom consumers, especially when subagents or concurrent tasks are involved.Waiting for
AgentResultEventand then emitting the whole answer is simpler, but it removes the real-time preview that streaming consumers expect.This PR introduces an opt-in semantic layer that keeps the existing token stream intact while classifying each completed text lifecycle:
The wrapper emits
TextOutputDispositionEventwith one of two dispositions:INTERMEDIATE: the referenced text belongs to a non-terminal model turn and can be presented as progress or commentary.TERMINAL: the last user-visible reply candidate has completed its streaming lifecycle.The disposition event classifies text that has already been streamed; it does not replace or delay the original
TextDeltaEvent.TERMINALis also not the authoritative answer.AgentResultEventremains the authoritative invocation result and can reconcile the preview with the final message, structured output, or an empty result.For a normally completed invocation, the closing order is:
This ordering lets consumers keep token-level preview latency while committing only the authoritative result.
Correlation and isolation
replyIdassociates a disposition with the text lifecycle it classifies.sourceandmetadata.taskIdisolate top-level, subagent, and concurrent invocations, including concurrent calls from the same source.Compatibility
ReActAgent#streamEvents()keeps its existing default event sequence.TextOutputDispositionEventcan ignore it without changing their current behavior.Adapter behavior
AG-UI can opt in with:
When enabled, intermediate text is exposed as a semantic custom event rather than being presented as model reasoning. On completion, the authoritative
AgentResultEventproduces a standardMESSAGES_SNAPSHOTto reconcile provisional text. When disabled, the legacy AG-UI sequence and message IDs are preserved.The managed Web flow treats text deltas as non-persistent preview updates.
INTERMEDIATEcan downgrade a preview to commentary,TERMINALcloses the preview lifecycle, andAgentEndEventcommits the message derived from the buffered authoritative result. Empty authoritative results can therefore remove stale preview text, and late subscribers do not receive obsolete preview frames.Local and remote subagents preserve the same semantics. Remote transport continues using
AGENT_EVENTwith its JSON string payload, while local subagent forwarding now includes the authoritativeAgentResultEventbeforeAgentEndEvent.Why this shape
The framework is the only layer that reliably knows the model-turn and invocation lifecycle. Publishing a small semantic envelope there avoids duplicating heuristics in every protocol adapter, while keeping provider events available for observability and leaving presentation policy to consumers. It also allows consumers to choose either a full-trace projection or a final-answer projection without forcing buffering into the core token stream.
Verification
mvn spotless:checkandgit diff --checkare clean.A complete Windows test run is not marked as passing because the repository contains symlink tests that require Windows symlink privileges and an existing order-sensitive baseline test. These are unrelated to this change; the affected streaming suites pass independently.
Related to #2872.
Related to #2975.
Checklist
mvn spotless:checkmvn test)