Skip to content

[Bug]: DeepSeek V3 tool call parser silently drops multi-line JSON arguments #443

@PercyDikec

Description

@PercyDikec

Bug Description

The DeepSeek V3 tool call parser regex is missing the re.DOTALL flag, so .* doesn't match newlines. Since tool call arguments are almost always multi-line JSON, the parser silently fails to extract them and returns the raw text instead of parsed tool calls.

Steps to Reproduce

  1. Set TOOL_CALL_PARSER=deepseek_v3 in config
  2. Use a DeepSeek V3 model that produces tool calls
  3. The model outputs a tool call with multi-line JSON arguments (the normal case)
  4. The parser returns (text, None) instead of extracted tool calls
  5. The agent treats the tool call as plain text

Expected Behavior

The parser should extract tool calls regardless of whether the JSON arguments are single-line or multi-line.

Actual Behavior

The parser only works when JSON arguments fit on a single line (e.g. {"query": "hello"}). Any multi-line JSON causes the regex to fail silently, and tool calls are dropped.

Affected Component

Agent Core (conversation loop, context compression, memory)

Messaging Platform (if gateway-related)

N/A (CLI only)

Operating System

Ubuntu 24.04

Python Version

3.11.9

Hermes Version

1.0.0

Relevant Logs / Traceback

Root Cause Analysis (optional)

In environments/tool_call_parsers/deepseek_v3_parser.py, the regex at line 40-42:

PATTERN = re.compile(
    r"<|tool▁call▁begin|>(?P<type>.*)<|tool▁sep|>(?P<function_name>.*)\n```json\n(?P<function_arguments>.*)\n```<|tool▁call▁end|>"
)

Without re.DOTALL, .* does not match \n. The function_arguments group needs to match multi-line JSON between the json code fence markers, but stops at the first newline.

Every other parser in the codebase that needs to match across lines uses re.DOTALL:

  • hermes_parser.py - uses re.DOTALL
  • mistral_parser.py - uses re.DOTALL
  • glm45_parser.py - uses re.DOTALL
  • glm47_parser.py - uses re.DOTALL
  • qwen3_coder_parser.py - uses re.DOTALL
  • kimi_k2_parser.py - uses re.DOTALL
  • longcat_parser.py - uses re.DOTALL

Proposed Fix (optional)

Add re.DOTALL flag to the regex compilation.

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

    type/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