Skip to content

[Bug]: DeepSeek thinking mode requires reasoning_content in API replay #16137

@zhangxiao918

Description

@zhangxiao918

Bug Description

When using DeepSeek model with thinking mode enabled (e.g., deepseek-v4-pro), the Hermes agent returns a 400 error from the DeepSeek API after the model performs a tool call:
⚠️ Error code: 400 - {'error': {'message': 'The reasoning_content in the thinking mode must be passed back to the API.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}

Steps to Reproduce

  1. Configure Hermes with DeepSeek model (e.g., deepseek-v4-pro)
  2. Enable thinking/reasoning mode
  3. Send a message that triggers a tool call
  4. Continue the conversation - API returns 400 error

Expected Behavior

The agent should automatically include reasoning_content when replaying messages to the DeepSeek API after tool calls, similar to how it handles Kimi/Moonshot.

Actual Behavior

The _copy_reasoning_content_for_api() method in run_agent.py handles Kimi/Moonshot reasoning requirements but is missing the DeepSeek check. The API response correctly extracts and stores reasoning_content, but it's not being replayed to the API on subsequent calls.

Affected Component

Other, Agent Core (conversation loop, context compression, memory)

Messaging Platform (if gateway-related)

Telegram

Debug Report

Error details:
Error code: 400
Message: The reasoning_content in the thinking mode must be passed back to the API.
API Endpoint: api.deepseek.com

Operating System

Ubuntu 24.04.4 LTS (Linux 6.17.0-22-generic)

Python Version

Python 3.12.3

Hermes Version

Latest (commit: 2e735b52 with fix; parent likely 2026-04-26)

Additional Logs / Traceback (optional)

Root Cause Analysis (optional)

The _copy_reasoning_content_for_api() method handles multiple providers:

  • Kimi/Moonshot: checks for api.kimi.com, moonshot.ai, moonshot.cn
  • Missing: DeepSeek (api.deepseek.com)
    When DeepSeek model performs tool calls in thinking mode, subsequent API calls must include the reasoning_content field, but the code doesn't handle this for DeepSeek.

Proposed Fix (optional)

In run_agent.py, method _copy_reasoning_content_for_api(), add DeepSeek check:

# DeepSeek thinking mode fix
if base_url_host_matches(self.base_url, "api.deepseek.com") and source_msg.get("tool_calls"):
    if not api_msg.get("reasoning_content"):
        api_msg["reasoning_content"] = ""
Location: run_agent.py, lines 7510-7512

### Are you willing to submit a PR for this?

- [ ] I'd like to fix this myself and submit a PR

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/agentCore agent loop, run_agent.py, prompt builderprovider/deepseekDeepSeek APItype/bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions