Repository navigation
Description
What happened?
When an assistant Msg contains both a ThinkingBlock (with METADATA_REASONING_DETAILS in its metadata) and tool call blocks, OpenAIMessageConverter.convertToMessage builds the outgoing reasoningDetails field twice — and the second assignment silently overwrites the first. The reasoning details restored from the ThinkingBlock are dropped whenever the message also contains tool calls.
OpenAIMessage.reasoningDetails is a single list (default null), so the last builder.reasoningDetails(...) call wins.
Code path
convertAssistantMessage in
agentscope-extensions/agentscope-extensions-model/agentscope-extensions-model-openai/src/main/java/io/agentscope/extensions/model/openai/formatter/OpenAIMessageConverter.java (current main, f96cdc7):
Site 1 — ThinkingBlock path (~line 349):
if (detailsObj instanceof List<?> list && !list.isEmpty()) {
List<OpenAIReasoningDetail> details = new ArrayList<>();
for (Object item : list) {
if (item instanceof OpenAIReasoningDetail rd) {
details.add(rd);
}
}
if (!details.isEmpty()) {
builder.reasoningDetails(details); // <-- set #1
}
}Site 2 — tool-call path (~line 430):
builder.toolCalls(toolCalls);
if (!reasoningDetails.isEmpty()) {
builder.reasoningDetails(reasoningDetails); // <-- set #2 overwrites set #1
}Site 2 uses a locally-declared list (List<OpenAIReasoningDetail> reasoningDetails = new ArrayList<>(); at ~line 363) that is never seeded with the details collected at site 1, so any tool call carrying a reasoningDetail in its metadata replaces the whole thinking-side list.
Reproduction
OpenAIReasoningDetail thinkingDetail = new OpenAIReasoningDetail();
thinkingDetail.setId("rs_thinking");
thinkingDetail.setData("thinking-side-signature");
Map<String, Object> thinkingMeta = new HashMap<>();
thinkingMeta.put(ThinkingBlock.METADATA_REASONING_DETAILS,
new ArrayList<>(List.of(thinkingDetail)));
ThinkingBlock thinking =
ThinkingBlock.builder().thinking("thinking...").metadata(thinkingMeta).build();
OpenAIReasoningDetail toolDetail = new OpenAIReasoningDetail();
toolDetail.setId("rs_tool");
toolDetail.setData("tool-side-signature");
Map<String, Object> toolMeta = new HashMap<>();
toolMeta.put("reasoningDetail", toolDetail);
ToolUseBlock toolUse =
ToolUseBlock.builder().id("call_1").name("search").metadata(toolMeta).build();
Msg msg = Msg.builder()
.name("assistant")
.content(List.of(thinking, toolUse))
.role(MsgRole.ASSISTANT)
.build();
OpenAIMessage result = new OpenAIMessageConverter(m -> "", b -> "").convertToMessage(msg, false);
System.out.println(result.getReasoningDetails());
// prints: [rs_tool] -- rs_thinking is goneActual: reasoningDetails = [rs_tool]
Expected: both details present, e.g. [rs_thinking, rs_tool]
Impact
This is the standard shape of an assistant turn from reasoning models behind OpenAI-compatible endpoints (e.g. Gemini 3 via OpenRouter): one assistant message carries the reasoning/thinking block and the tool calls it decided on. For such providers the reasoning details carry thought signatures that the API requires to be replayed with subsequent turns — dropping the thinking-side entries silently degrades or breaks multi-turn tool-calling with interleaved thinking (the same class of failure as missing thought signatures on tool calls, which can surface as 400 INVALID_ARGUMENT on replay).
Note the asymmetry: a message with only a ThinkingBlock keeps its details, and a message with only tool calls keeps its details — the loss only happens when both appear together, which is exactly the normal tool-calling turn.
Suggested fix
Accumulate both sources into a single list and call builder.reasoningDetails(...) exactly once, after the tool-call section (falling back to the thinking-only list when there are no tool calls). Happy to submit a PR.
Environment
- agentscope-java
main(f96cdc7), moduleagentscope-extensions-model-openai - Found while investigating Thought signatures lost after JSON persistence round-trip cause 400 INVALID_ARGUMENT on Gemini 3 tool calls #2909 (related converter area, independent defect)
Activity
fix(openai): remove redundant reasoningDetail from ToolUseBlock metad…