Skip to content

fix(agent): emit ThinkingBlockEnd before TextBlockStart at reasoning→answer boundary#1887

Open
qbc2016 wants to merge 1 commit into
agentscope-ai:mainfrom
qbc2016:bc/agent_event
Open

fix(agent): emit ThinkingBlockEnd before TextBlockStart at reasoning→answer boundary#1887
qbc2016 wants to merge 1 commit into
agentscope-ai:mainfrom
qbc2016:bc/agent_event

Conversation

@qbc2016

@qbc2016 qbc2016 commented Jun 17, 2026

Copy link
Copy Markdown
Member

AgentScope Version

2.0.2

Description

In _convert_chat_response_to_event, text blocks were processed before thinking blocks, causing ThinkingBlockEndEvent to be emitted after TextBlockDeltaEvent at the reasoning→answer boundary. This trapped the
first answer token(s) inside the <think> block for any downstream renderer.

Fix the ordering by splitting the logic into three explicit steps per chunk:

  1. Close any open blocks absent from the current chunk (thinking first, then text)
  2. Open/continue the thinking stream
  3. Open/continue the text stream

This ensures ThinkingBlockEnd → TextBlockStart → TextBlockDelta at the boundary, and also fixes the edge case where a single chunk carries both a ThinkingBlock and a TextBlock.

Fixes #1885.

Checklist

Please check the following items before code is ready to be reviewed.

  • An issue has been created for this PR
  • I have read the CONTRIBUTING.md
  • Docstrings are in Google style
  • Related documentation has been updated (e.g. links, examples, etc.) in documentation repository
  • Code is ready for review

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]: Streaming events out of order — TextBlockDelta emitted before ThinkingBlockEnd at the reasoning→answer boundary

1 participant