Skip to content

fix(agent): prevent empty tool_calls arrays after dedup for DeepSeek V4 - #65211

Closed
ajzrva-sys wants to merge 1 commit into
NousResearch:mainfrom
ajzrva-sys:fix/deepseek-empty-tool-calls-dedup
Closed

fix(agent): prevent empty tool_calls arrays after dedup for DeepSeek V4#65211
ajzrva-sys wants to merge 1 commit into
NousResearch:mainfrom
ajzrva-sys:fix/deepseek-empty-tool-calls-dedup

Conversation

@ajzrva-sys

Copy link
Copy Markdown
Contributor

Problem

DeepSeek V4 (and other strict OpenAI-compatible providers) reject API requests with HTTP 400 when any message contains tool_calls: [] (empty array).

The existing sanitize_api_messages already strips tool_calls: [] from assistant messages (lines 2508-2541), but the deduplication block at lines 2652-2666 can re-introduce an empty array: if every tool call in an assistant message is identified as a duplicate and removed, kept_tcs ends up empty but the code still does msg = {**msg, "tool_calls": kept_tcs} which produces [].

This hits long-running sessions where history corruption, retry artifacts, or compression re-emits cause duplicate tool_call_ids.

Fix

In the dedup block: when kept_tcs is empty after removing duplicates, delete the tool_calls key from the message dict instead of setting it to [].

Changed file

  • agent/agent_runtime_helpers.py — 4 lines added, 1 removed

Related

Verification

  • Manual: ran hermes chat with DeepSeek V4 after a long session with Ctrl+C interruptions — no more 400 errors

When deduplicating tool_call_ids, if all tool calls in an assistant
message are removed as duplicates, the code previously reassigned
msg['tool_calls'] = [] — which DeepSeek V4 (and other strict
OpenAI-compatible providers) reject with HTTP 400 'empty array'.

Now if kept_tcs is empty after dedup, the tool_calls key is removed
entirely instead of being set to [].

Fixes the 'empty array' 400 error seen during long DeepSeek sessions
with history corruption / retry artifacts.

Ref: NousResearch#64843
@alt-glitch alt-glitch added type/bug Something isn't working P2 Medium — degraded but workaround exists comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint provider/deepseek DeepSeek API sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state duplicate This issue or pull request already exists labels Jul 15, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

This was generated by AI during triage.

Duplicate of #64843: both PRs fix the same dedup-output tool_calls: [] path in agent_runtime_helpers.py by dropping the key when no calls remain. #64843 is the earlier open implementation.

@ajzrva-sys

Copy link
Copy Markdown
Contributor Author

Duplicate of #64843 by rommy2017 — same fix, already open.

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

Labels

comp/agent Core agent runtime: loop, agent_init, prompt builder, context-compression, responses endpoint duplicate This issue or pull request already exists P2 Medium — degraded but workaround exists provider/deepseek DeepSeek API sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants