Skip to content

fix(agui): use unique message IDs for discontinuous text segments - #3010

Merged
jujn merged 4 commits into
agentscope-ai:mainfrom
ZHCHJ888:fix/agui-text-segment-ids
Sep 9, 2026
Merged

jujn merged 4 commits into
agentscope-ai:mainfrom
ZHCHJ888:fix/agui-text-segment-ids

Conversation

@ZHCHJ888

@ZHCHJ888 ZHCHJ888 commented Sep 6, 2026 •

Copy link
Copy Markdown
Contributor

AgentScope-Java Version

2.0.3-SNAPSHOT

Description

Fixes #2988.

当单次模型调用先输出文本、后输出工具调用、接着再输出文本(或推理内容)时,核心层之前对所有片段重用了相同的块 ID ("text" / "thinking")。AG-UI 适配器随后也重用了相同的消息 ID,导致在对应的 TEXT_MESSAGE_END 之后发出了第二个 TEXT_MESSAGE_CONTENT / REASONING_MESSAGE_CONTENT,且缺少匹配的 TEXT_MESSAGE_START / REASONING_MESSAGE_START,从而引发了客户端错误:"No active text message found with ID"。

此更改:

  • 在 ModelCallBlockLifecycle 内部为每个连续的文本或推理片段分配一个不同的块 ID ("text", "text-2", ... / "thinking", "thinking-2", ...)。通过 AtomicLong 计数器跟踪的片段序列在每次 startText / startThinking 时(在之前的 flushText / flushThinking 关闭当前片段后)都会递增;
  • 在 AG-UI 适配器中统一推导消息 ID,作为 replyId + "-" + blockId —— 一个没有特殊情况或后缀的纯函数。第一段文本片段变为 replyId-text,第一段推理片段变为 replyId-thinking,后续片段变为 replyId-text-2 / replyId-thinking-2 等;
  • 移除了 REASONING_MESSAGE_ID_SUFFIX ("-reasoning") 常量和 withReasoningSuffix 方法。文本和推理消息天然具有不同的 ID,因为它们的块 ID 不同 ("text" 与 "thinking"),这使得后缀变得多余;
  • 为 text → tool call → text 和 thinking → tool call → thinking 序列添加了核心和 AG-UI 回归测试,并更新了现有的 AG-UI 测试以符合新的消息 ID 方案。

测试

  • ReActAgentNewLoopReplyTest: 14 通过,0 失败。
  • AG-UI 模块测试套件:500 通过,0 失败。

Checklist

  • Code passes Spotless checks.
  • Relevant core and AG-UI tests pass.
  • Javadoc is complete and clear.
  • Documentation changes are not required for this internal lifecycle fix.
  • The pull request is ready for review.

@jujn

jujn commented Sep 6, 2026

Copy link
Copy Markdown
Collaborator

不只是 text,reasoning 也有同样的问题哈

@ZHCHJ888

ZHCHJ888 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

不只是 text,reasoning 也有同样的问题哈

收到老师,那我按相同思路为连续 reasoning 段生成独立的 blockId,并补充回归测试,预计改动量不大,感谢您审阅和提醒

@codecov

codecov Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 92.85714% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
.../core/agui/adapter/strategy/AguiStreamContext.java 70.00% 0 Missing and 3 partials ⚠️

📢 Thoughts on this report? Let us know!

@ZHCHJ888

ZHCHJ888 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

@jujn 老师,我补齐 reasoning 场景并增加了相关回归测试了,等您有空能麻烦再帮忙看一下吗

@jujn jujn left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jujn
jujn merged commit 2b378e1 into agentscope-ai:main Sep 9, 2026
6 checks passed
dargoner added a commit to dargoner/agentscope-java that referenced this pull request Sep 12, 2026
上游 agentscope-ai#3010 之后文本消息 ID 为 replyId-blockId(如 reply-1-text-1),本分支的 AguiStreamContext 仍把传入值当 replyId 再拼 :text:N,导致处置事件 messageIds 与流式消息 ID 不一致。

改为直接复用官方 messageId,并从段 ID 反推所属 replyId 维持处置分组;同步更新预留段 ID 判定、AG-UI 测试期望与 README 说明。
dargoner added a commit to dargoner/agentscope-java that referenced this pull request Sep 12, 2026
上游 agentscope-ai#3010 之后文本消息 ID 为 replyId-blockId(如 reply-1-text-1),本分支的 AguiStreamContext 仍把传入值当 replyId 再拼 :text:N,导致处置事件 messageIds 与流式消息 ID 不一致。

改为直接复用官方 messageId,并从段 ID 反推所属 replyId 维持处置分组;保留按本轮实际生成段判定快照排除的语义,同步更新测试期望与 README 说明。
dargoner added a commit to dargoner/agentscope-java that referenced this pull request Sep 12, 2026
上游 agentscope-ai#3010 之后文本消息 ID 为 replyId-blockId(如 reply-1-text-1),本分支的 AguiStreamContext 仍把传入值当 replyId 再拼 :text:N,导致处置事件 messageIds 与流式消息 ID 不一致。

改为直接复用官方 messageId,并从段 ID 反推所属 replyId 维持处置分组;保留按本轮实际生成段判定快照排除的语义,同步更新测试期望与 README 说明。

(cherry picked from commit 42ad838)
dargoner added a commit to dargoner/agentscope-java that referenced this pull request Sep 12, 2026
把本地流式文本处置分支与 PR 分支对齐,避免两条线各自漂移:

- AG-UI:最终快照排除的文本段改为按本轮实际启动的文本消息集合(startedTextMessages)判定,不再用消息 ID 正则反推,并同步适配器测试;

- harness:子代理结束前补发权威 AGENT_RESULT 事件,并补充事件顺序断言;

- core:补回上游 agentscope-ai#3010、agentscope-ai#2757 覆盖的不连续文本段唯一块 ID 与摘要失败终止状态用例(此前本地合并时遗漏)。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]:模型在工具调用前后夹带文本时,TEXT_MESSAGE_START/END 配对错乱,客户端报 "No active text message found with ID"

2 participants