Repository navigation
Description
Describe the bug
In the published AgentScope Java 2.0.5 artifact, ConversationCompactor.SummaryCollection rejects a valid text summary when the same response stream also contains a normal ThinkingBlock.
The maintenance-line implementation marks every non-TextBlock as invalid. This includes reasoning blocks even when the final text is nonempty, ends with stop, and the replacement would reduce context.
Because a rejected candidate leaves the original history in place, a caller checking that same above-threshold history on later rounds can attempt compaction repeatedly.
To Reproduce (no provider/API key required)
Using io.agentscope:agentscope-harness:2.0.5, run the following with the normal AgentScope message/model imports and Reactor Flux:
for (boolean thinking : List.of(false, true)) {
Model model = new Model() {
@Override
public String getModelName() {
return "synthetic-summary";
}
@Override
public Flux<ChatResponse> stream(
List<Msg> messages, List<ToolSchema> tools, GenerateOptions options) {
var text = TextBlock.builder().text("FACT=retained").build();
var reason = ThinkingBlock.builder().thinking("summarizing").build();
return Flux.just(ChatResponse.builder()
.content(thinking ? List.of(reason, text) : List.of(text))
.finishReason("stop")
.build());
}
};
var history = List.of(
Msg.builder().role(MsgRole.USER)
.textContent("old context ".repeat(1_000)).build(),
Msg.builder().role(MsgRole.USER).textContent("continue").build());
var config = CompactionConfig.builder()
.triggerTokens(1).triggerMessages(0)
.keepTokens(0).keepMessages(1)
.prune(null).truncateArgs(null)
.flushBeforeCompact(false).offloadBeforeCompact(false).build();
var result = new ConversationCompactor(model, new MemoryFlushManager(null, null))
.compactIfNeeded(
RuntimeContext.builder().build(), history, config, "agent", "session")
.block(Duration.ofSeconds(10));
System.out.println(
"thinking=" + thinking + ", summaryAccepted=" + result.isPresent());
}Executed locally on Java 21 with the published 2.0.5 artifacts:
thinking=false, summaryAccepted=true
thinking=true, summaryAccepted=false
A separate stream chunk containing only reasoning before the text response has the same issue.
Error messages
Rejected summary: model returned non-text content or tool calls
Environment
- AgentScope Java: published 2.0.5 artifacts
- Java: 21
- OS: macOS
- Reproduction uses a synthetic Model, with no external service.
Additional context: source of the regression
The original PR #3855, merged as 616ab47, only marks ToolUseBlock as invalid; reasoning blocks are ignored.
Its 2.0.x backport, 98f7736, broadens this to every non-text block. The published v2.0.5 implementation contains that broader check.
Expected behavior / suggested fix
Ignore only ThinkingBlock while collecting summary text. Keep all other validation, including rejection of tool calls, images/other unsupported blocks, empty or reasoning-only output, provider output-limit termination, and non-reducing candidates.
For example, retain sawNonText but narrow the branch:
if (block instanceof TextBlock tb) {
text.append(tb.getText());
} else if (!(block instanceof ThinkingBlock)) {
sawNonText = true;
}Continue preserving finish reason/metadata, cancellation, errors, lightweight reductions, and history-commit checks.
Validation scope
The reproduction above was compiled and executed locally on Java 21 against the published 2.0.5 artifacts, with a synthetic Model and no provider or API credentials. The two cases differ only in the presence of ThinkingBlock.
Please add coverage for reasoning and text in the same chunk and in separate chunks. Ignoring a reasoning block must not turn reasoning-only output into an accepted summary or weaken the other existing rejection checks.
AI assistance was used for investigation; the SDK-only reproduction was executed locally.
Activity
lishibin commentedon Nov 17, 2026
Hi, I’d like to work on this issue.
I can reproduce it locally on macOS with Java 21.
I plan to add regression tests for ThinkingBlock and TextBlock
in the same and separate stream chunks, then narrow the summary
validation so ThinkingBlock is ignored while unsupported blocks
remain rejected.
littlebird69 commentedon Nov 17, 2026
Confirming this against a real provider — it is not synthetic-only.
Reproduced in production wiring with DeepSeek
deepseek-v4-flash(a thinking model): every compaction attempt logsand the history is never replaced, on every reasoning round above the threshold — the wasted-summary-call loop the report describes.
Two additions from our side:
The overflow-recovery path breaks the same way.
CompactionMiddleware.reasonWithRecovery→emergencyCompact(and any caller-sideforceCompactbuilt onConversationCompactor.compactIfNeeded) goes through the samesummarizePrefix; with a thinking summary model the candidate is rejected, compaction returns empty, and context-overflow recovery degrades back to the original error. So on 2.0.5 a thinking model loses both regular compaction and the overflow safety net.What the rejection seems intended for. Per the javadoc the rule guards against the model returning tool calls / no usable text.
ThinkingBlockis neither: it is the normal streaming shape of every reasoning model, and 2.0.4's accumulator simply skipped non-text blocks (if (block instanceof TextBlock tb ...)) while keeping the text. Rejecting on it turns "strict about malformed summaries" into "never compacts with reasoning models".Our interim workaround (restores the 2.0.4 semantics without touching the framework): wrap the summary model at the wiring seam with a delegating
Modelwhosestreamfilters non-TextBlockcontent blocks (id / finishReason / usage / metadata preserved). Happy to PR a framework-side fix instead if maintainers prefer — e.g. haveSummaryCollectiononly setsawNonTextfor blocks that actually indicate a unusable summary (tool calls), or dropThinkingBlockbefore validation.