Skip to content

[Bug] deepseek-v4-flash lacks multi-turn reasoning_content handling — fails after tool calls #4842

Description

@nevgenov

[Bug] deepseek-v4-flash lacks multi-turn reasoning_content handling — fails after tool calls

Summary

deepseek-v4-flash defaults to thinking mode enabled. When the agent performs tool calls, DeepSeek returns reasoning_content that MUST be preserved in subsequent requests. LibreFang's OpenAI driver does NOT preserve it for V4 Flash — only for deepseek-reasoner/R1 and Kimi.

Result: agent works for simple messages, but as soon as a tool is called, subsequent requests fail with 400/500 errors. Agent becomes unusable until session reset.

Reproduce

  1. Configure an agent with model deepseek-v4-flash
  2. Send simple messages → ✅ works
  3. Send a message that triggers a tool call (e.g., memory_search, ask_agent, shell_exec)
  4. All subsequent messages → ❌ 500 / "Sorry, something went wrong"

Switching to deepseek-chat (V3, no thinking mode) or deepseek-reasoner (R1, handled) works fine.

Root cause

In crates/librefang-llm-drivers/src/drivers/openai.rs:

1. is_deepseek_reasoner() — only matches R1, not V4 Flash:

fn is_deepseek_reasoner(&self, model: &str) -> bool {
    let m = model.to_lowercase();
    m.contains("deepseek-reasoner") || m.contains("deepseek-r1")
    // deepseek-v4-flash is NOT matched
}

2. reasoning_content is set to None for V4 Flash:

reasoning_content: if is_deepseek_r {
    None                                    // R1: strips it (correct)
} else if has_tool_calls
    && self.kimi_needs_reasoning_content(...) {
    Some(String::new())                     // Kimi: empty string (correct)
} else {
    None                                    // V4 Flash: ignored → BUG
},

3. thinking mode is never disabled for V4 Flash:

thinking: if self.kimi_needs_reasoning_content(&request.model) {
    Some(serde_json::json!({"type": "disabled"})) // only Kimi
} else {
    None                                          // V4 Flash: thinking ON → BUG
},

Per DeepSeek API docs:

"for turns that do perform tool calls, the reasoning_content must be fully passed back to the API in all subsequent requests. If your code does not correctly pass back reasoning_content, the API will return a 400 error."

Expected behavior

Either:

  • Pass reasoning_content back to DeepSeek API after tool calls (like Kimi does)
  • Or disable thinking mode via thinking: {"type": "disabled"} for V4 Flash

Workaround

Use deepseek-chat (V3) which has no thinking mode, or deepseek-v4-pro.

Environment

  • LibreFang: v2026.5.8-beta.10
  • Model: deepseek-v4-flash

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/runtimeAgent loop, LLM drivers, WASM sandboxhas-prA pull request has been linked to this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions