Skip to content

fix: DeepSeek V3 parser drops tool calls when model returns multiple (#989)#1015

Closed
Bartok9 wants to merge 1 commit intoNousResearch:mainfrom
Bartok9:fix/deepseek-v3-multiple-tool-calls
Closed

fix: DeepSeek V3 parser drops tool calls when model returns multiple (#989)#1015
Bartok9 wants to merge 1 commit intoNousResearch:mainfrom
Bartok9:fix/deepseek-v3-multiple-tool-calls

Conversation

@Bartok9
Copy link
Contributor

@Bartok9 Bartok9 commented Mar 12, 2026

Problem

The regex in DeepSeekV3ToolCallParser.PATTERN used greedy .* with re.DOTALL. When the model returned multiple tool calls, findall() merged them into a single match — silently dropping all but the last one.

Repro: Any DeepSeek V3 response with 2+ tool calls → only the last tool call was parsed.

Root Cause

(?P<type>.*) consumed across <|tool▁sep|> delimiters until the last occurrence.

Fix

Changed .* to .*? (non-greedy) in all three capture groups.

Before: 1 match found for 2 tool calls
After: 2 matches found for 2 tool calls

Tests Added

Closes #989

…ousResearch#989)

The regex in DeepSeekV3ToolCallParser.PATTERN used greedy `.*` with
re.DOTALL. When the model returned multiple tool calls, findall()
merged them into a single match — silently dropping all but the last.

Root cause: `(?P<type>.*)` consumed across <|tool▁sep|> delimiters
until the last occurrence.

Fix: Changed `.*` to `.*?` (non-greedy) in all three capture groups.

Added comprehensive tests for single, multiple (2+), and 3+ tool calls.

Closes NousResearch#989
@imadreamerboy
Copy link

duplicate #992

@Bartok9
Copy link
Contributor Author

Bartok9 commented Mar 13, 2026

Closing as duplicate of #992 - thanks for pointing that out @imadreamerboy!

@Bartok9 Bartok9 closed this Mar 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DeepSeek V3 parser drops tool calls when model returns multiple

2 participants