Skip to content

Cerebras API rejects reasoning_content on multi-turn replay (HTTP 400) #45655

Closed as not planned

Description

@ruslanlap

Bug Description

When using Cerebras as a custom provider, multi-turn agent sessions with tool calling fail with HTTP 400 after the first retry:

messages.2.assistant.reasoning_content: property 'reasoning_content' is unsupported

Root Cause

In agent/agent_runtime_helpers.py → copy_reasoning_content_for_api() (line ~2093):

existing = source_msg.get("reasoning_content")
if isinstance(existing, str):
    if existing == "" and agent._needs_thinking_reasoning_pad():
        api_msg["reasoning_content"] = " "
    else:
        api_msg["reasoning_content"] = existing  # ← Always copies!
    return

When reasoning_content is a non-empty string, it's always copied to the API message, regardless of whether the current provider supports it. The _needs_thinking_reasoning_pad() check only applies to the empty-string upgrade case.

Cerebras returns reasoning_tokens in responses (via the OpenAI-compatible API), which Hermes stores as reasoning_content. On replay (e.g., after a 429 rate-limit retry), this reasoning_content is included in the messages array, and Cerebras rejects it because their API doesn't accept that field in input messages.

To Reproduce

  1. Configure Cerebras as a custom provider:

    providers:
      custom:cerebras:
        base_url: https://api.cerebras.ai/v1
        api_key: csk-...
        models: ["gpt-oss-120b", "zai-glm-4.7"]
  2. Run an agent task with tool calling:

    hermes chat -q "Create a file /tmp/test.txt and read it back" --provider custom:cerebras --model gpt-oss-120b
    
  3. Observe:

    • First tool call succeeds (write_file)
    • Second call hits rate limit (429)
    • Retry sends reasoning_content in messages → Cerebras returns 400

Expected Behavior

reasoning_content should be stripped from API messages when the provider doesn't support it. Only providers that explicitly require it (DeepSeek, Kimi, MiMo — per _needs_thinking_reasoning_pad()) should receive it.

Proposed Fix

In copy_reasoning_content_for_api(), add a provider check before copying non-empty reasoning_content:

existing = source_msg.get("reasoning_content")
if isinstance(existing, str):
    if existing == "" and agent._needs_thinking_reasoning_pad():
        api_msg["reasoning_content"] = " "
    elif agent._needs_thinking_reasoning_pad():
        api_msg["reasoning_content"] = existing
    # else: strip reasoning_content for providers that don't support it
    return

Or alternatively, add a _strips_reasoning_content() method for providers like Cerebras that reject the field.

Environment

  • Hermes version: 0.16.0
  • Provider: custom:cerebras (https://api.cerebras.ai/v1)
  • Models: gpt-oss-120b, zai-glm-4.7
  • Cerebras API returns reasoning_tokens but rejects reasoning_content in input messages

Workaround

None available via config — this requires a code fix.

Activity

  1. added
    type/bugSomething isn't working
    P2Medium — degraded but workaround exists
    comp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint
    on Jun 13, 2026
  2. teknium1 commented on Jul 14, 2026

    @teknium1
    Collaborator

    Implemented on current main — automated hermes-sweeper review.

    • Commit 2b3a4f0 (fix(agent): strip stale reasoning_content when falling back to a strict provider (#50480)) explicitly covers Cerebras API rejects reasoning_content on multi-turn replay (HTTP 400) #45655 and Cerebras.
    • agent/agent_runtime_helpers.py:2821-2838 now removes reasoning_content for providers that do not require echo-back, including non-empty values.
    • agent/agent_runtime_helpers.py:2920-2938 also strips stale fields from already-built retry/fallback API messages.
    • tests/run_agent/test_run_agent.py:7300-7337 verifies replayed strict-provider requests omit the field.

    The fix is contained in release tag v2026.7.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Medium — degraded but workaround existscomp/agentCore agent runtime: loop, agent_init, prompt builder, context-compression, responses endpointsweeper:implemented-on-mainSweeper: behavior already present on current maintype/bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions