Skip to content

[Bug]: openAI request error : [The reasoning_content in the thinking mode must be passed back to the API.] #3246

Closed

Description

@joman-jiang

Describe the bug
经过很多轮对话后,偶发出现如下错误,可能是和subagent有关。

Image

附件为裁剪的OpenAIRequest内容,仍可复现失败场景,使用模型为deepseek v4,1 flash.

openai_error_request_be6d678b-3831-4584-aaf2-539239d866fd.json

Activity

  1. added
    bug
    on Sep 22, 2026
  2. jujn commented on Sep 22, 2026

    @jujn
    Collaborator

    as-java 哪个版本呢?

  3. joman-jiang commented on Sep 22, 2026

    @joman-jiang
    Author

    as-java 哪个版本呢?

    我用的开发版,正式版不超过2.0.3

  4. oss-maintainer commented on Sep 22, 2026

    @oss-maintainer
    Collaborator

    Issue Evaluation

    Category: bug | Module: agentscope-extensions-model-openai | Status: Needs info (verified against main @ ed77530a4)

    What we checked, and what we found

    The report implies the framework replays history without the reasoning_content that thinking mode requires. That specific mechanism does not hold in the current code:

    • OpenAIMessageConverter.convertAssistantMessage(...) (formatter/OpenAIMessageConverter.java:314-345) takes the message's first ThinkingBlock and sets builder.reasoningContent(...), plus reasoning_details from block metadata, and serializes tool_calls independently (:363+). So a thinking + tool-call assistant message does emit both fields on replay.
    • Thinking is retained where replay needs it: OpenAIResponseParser maps inbound reasoning_content/reasoning_details into ThinkingBlock, ReasoningContext.buildFinalMessage() keeps thinking + text + tool calls in one assistant Msg, and AgentState.toJson()/fromJsonString() persist polymorphic content blocks including ThinkingBlock.
    • Sub-agent output does not create parent assistant messages (it is flattened into tool results), so the sub-agent suspicion does not point at an obvious serialization hole.
    • DeepSeekFormatter.applyDeepSeekFixes(...) (formatter/DeepSeekFormatter.java:97+) is the component that implements exactly the rule the error message cites — keep reasoning_content for segments with tool calls, strip it otherwise.

    One real code gap found while verifying (separate from your error, worth a maintainer look)

    OpenAIChatModel formats the request through the options-aware entry point — formatter.format(messages, effectiveOptions) (OpenAIChatModel.java:129) → AbstractBaseFormatter.format(msgs, options) → doFormat(msgs, options). But OpenAIChatFormatter overrides doFormat(List<Msg>, GenerateOptions) with its own body (formatter/OpenAIChatFormatter.java:68) instead of delegating to doFormat(List<Msg>), and DeepSeekFormatter overrides only the single-argument version (formatter/DeepSeekFormatter.java:68). Result: on the HTTP chat-completions path the DeepSeek post-processing (applyDeepSeekFixes, which is precisely the "keep reasoning_content for tool-call segments / drop it elsewhere" rule, plus name stripping and the empty-user tail fix) is never applied. Note this gap would produce the opposite symptom (stale reasoning_content sent where it should be removed), so it is unlikely to be the direct cause of your error message — but it means provider-specific shaping is silently skipped on the main request path, which is its own defect. Two identically named DeepSeekFormatter classes exist (formatter/ and compat/deepseek/, the latter wired by DeepSeekModelProvider), which makes this easy to miss.

    What we need to pin your intermittent failure (please attach)

    • Exact io.agentscope:* version, and whether it predates fix(ollama): surface thinking output as a ThinkingBlock #3146 (that PR changed how thinking is surfaced as a ThinkingBlock).
    • Model name + base URL + the thinking/reasoning parameters being sent.
    • Whether context compaction (or a sub-agent) had already run in that session before the failing turn — compaction rewrites history and is the remaining candidate for an assistant message losing its ThinkingBlock while keeping tool_calls.
    • From the attached request JSON, the index of the offending message: a non-first assistant message that has tool_calls (or plain content) but no reasoning_content, and whether a content: "" field is present. That one message distinguishes "history rewriting dropped the thinking block" from "the endpoint expects stricter semantics than the OpenAI-compatible DTO models".

    Your trimmed OpenAIRequest attachment is precisely what is needed; the code evidence alone is not enough to close this as a framework defect, which is why this is marked needs info rather than confirmed.


    Automated evaluation by github-manager-bot

  5. added
    area/core/model
    wait-for-response
    on Sep 22, 2026
  6. amyaxy commented on Sep 22, 2026

    @amyaxy
    Contributor

    @joman-jiang 可以提供一个可以复现的案例代码吗

  7. joman-jiang commented on Sep 22, 2026

    @joman-jiang
    Author

    @joman-jiang 可以提供一个可以复现的案例代码吗

        String savePath = "C:\\Users\\joman.jiang\\Downloads\\logs";
        String requestPath = String.format("%s/openai_error_request_%s.json", savePath, logUid);
        OpenAIRequest request = JSONN.parseObject(FileUtil.readUtf8String(requestPath), OpenAIRequest.class);
        Flux<OpenAIResponse> stream = client.stream(API_KEY,
                API_URL, request, GenerateOptions.builder().build());
        stream.doOnNext(System.out::println).blockLast();
    
  8. oss-maintainer commented on Sep 22, 2026

    @oss-maintainer
  9. amyaxy commented on Sep 23, 2026

    @amyaxy
    Contributor

    @jujn 我来跟下这个问题

  10. added a commit that references this issue on Sep 29, 2026
    9343ff0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area/core/modelbugwait-for-response

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions