Skip to content

[BugFix] fix tool call parser#7369

Merged
LiqinruiG merged 4 commits intoPaddlePaddle:developfrom
luukunn:fix_tool_parser_bug
Apr 15, 2026
Merged

[BugFix] fix tool call parser#7369
LiqinruiG merged 4 commits intoPaddlePaddle:developfrom
luukunn:fix_tool_parser_bug

Conversation

@luukunn
Copy link
Copy Markdown
Collaborator

@luukunn luukunn commented Apr 13, 2026

Motivation

  • 修复 extract_tool_callstools_calledtool_calls 为空时仍返回 True 的问题
  • 修复空字典 {} 被误判为无参数的问题
  • 修复流式输出结束处理中 '"}' 检查过于严格导致数字/布尔值结尾的参数无法正确流式传输的问题

Modifications

  • tools_called=True 改为 tools_called=len(tool_calls) > 0
  • if diff: 改为 if diff is not None:,正确处理空字典
  • if '"}' not in delta_text: 改为 if "}" not in delta_text:,并使用 rindex("}") 获取正确位置
  • 将所有 if not cur_arguments 改为 if cur_arguments is None,避免空字典误判
  • 新增回归测试覆盖空参数、数字/布尔值结尾参数、嵌套对象等边界情况

Usage or Command

Accuracy Tests

Checklist

  • Add at least a tag in the PR title.
    • Tag list: [[FDConfig],[APIServer],[Engine], [Scheduler], [PD Disaggregation], [Executor], [Graph Optimization], [Speculative Decoding], [RL], [Models], [Quantization], [Loader], [OP], [KVCache], [DataProcessor], [BugFix], [Docs], [CI], [Optimization], [Feature], [Benchmark], [Others], [XPU], [HPU], [GCU], [DCU], [Iluvatar], [Metax]]
    • You can add new tags based on the PR content, but the semantics must be clear.
  • Format your code, run pre-commit before commit.
  • Add unit tests. Please write the reason in this PR if no unit tests.
  • Provide accuracy results.
  • If the current PR is submitting to the release branch, make sure the PR has been submitted to the develop branch, then cherry-pick it to the release branch with the [Cherry-Pick] PR tag.

Copilot AI review requested due to automatic review settings April 13, 2026 13:04
@paddle-bot
Copy link
Copy Markdown

paddle-bot bot commented Apr 13, 2026

Thanks for your contribution!

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

该 PR 聚焦修复 OpenAI 入口下 ErnieX1 工具调用解析(tool call parser)在流式场景中的边界问题,尤其是 arguments={}(空字典)以及以数字/布尔值/嵌套 } 结尾时的收尾解析与增量输出。

Changes:

  • 调整 ErnieX1ToolParser.extract_tool_calls()tools_called 判定逻辑,避免在未提取到工具调用时仍返回 tools_called=True
  • 修复流式解析 close 分支与参数分支中对 arguments 的判定:由“真假值判断”改为“None 判断”,从而正确处理空字典等 falsy 参数。
  • 增加多组回归/集成测试,覆盖 arguments={}、数字/布尔结尾、嵌套对象结尾等流式边界切分。

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
fastdeploy/entrypoints/openai/tool_parsers/ernie_x1_tool_parser.py 修复流式参数分支与 close 分支对空参数的错误判定,并调整 tools_called 返回逻辑
tests/entrypoints/openai/tool_parsers/test_ernie_x1_tool_parser.py 新增回归/集成测试覆盖空参数与多种 close 结尾场景

Comment on lines 94 to 116
if self.tool_call_start_token not in model_output:
return ExtractedToolCallInformation(tools_called=False, tool_calls=[], content=model_output)
else:
try:
tool_call_json_list = self.tool_call_regex.findall(model_output)
tool_calls = []
for tool_call_json in tool_call_json_list:
tool_call_dict = json.loads(tool_call_json)
args_str = json.dumps(tool_call_dict.get("arguments", {}), ensure_ascii=False)
tool_calls.append(
ToolCall(
type="function",
id=random_tool_call_id(),
function=FunctionCall(
name=tool_call_dict.get("name", ""),
arguments=args_str,
),
)
)
return ExtractedToolCallInformation(
tools_called=True,
tools_called=len(tool_calls) > 0,
tool_calls=tool_calls,
)
Comment on lines 184 to 191
diff = self.prev_tool_call_arr[self.current_tool_id].get("arguments")
if diff:
if '"}' not in delta_text:
if diff is not None:
if "}" not in delta_text:
return None
end_loc = delta_text.rindex("}")
diff = delta_text[:end_loc]
if not diff:
return None
Comment on lines +971 to +976
def test_streaming_empty_arguments_full_flow(self):
"""Integration: streaming tool call with arguments={} must not lose arguments.

Simulates a complete streaming flow where the tool call has empty
arguments. Verifies the name is sent and arguments are streamed.
"""
PaddlePaddle-bot

This comment was marked as outdated.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 77.77778% with 4 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (develop@31e2a8b). Learn more about missing BASE report.

Files with missing lines Patch % Lines
...points/openai/tool_parsers/ernie_x1_tool_parser.py 77.77% 0 Missing and 4 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             develop    #7369   +/-   ##
==========================================
  Coverage           ?   73.57%           
==========================================
  Files              ?      383           
  Lines              ?    53626           
  Branches           ?     8415           
==========================================
  Hits               ?    39456           
  Misses             ?    11483           
  Partials           ?     2687           
Flag Coverage Δ
GPU 73.57% <77.77%> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@luukunn luukunn changed the title fix tool call parser [BugFix] fix tool call parser Apr 14, 2026
PaddlePaddle-bot

This comment was marked as outdated.

Copilot AI review requested due to automatic review settings April 14, 2026 07:47
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

PaddlePaddle-bot

This comment was marked as outdated.

Copy link
Copy Markdown

@PaddlePaddle-bot PaddlePaddle-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review | 2025-04-14

📋 Review 摘要

PR 概述:修复 ErnieX1ToolParser 中空参数判断错误、tools_called 误判、以及流式输出结尾处理过于严格的问题

变更范围entrypoints/openai/tool_parsers/

影响面 Tag[APIServer]

📝 PR 规范检查

问题:PR 标题包含 [BugFix] Tag 且符合格式要求,描述有 Motivation 和 Modifications,但 Checklist 未勾选任何项。

建议

  • 标题格式符合要求,无需修改
  • 建议更新 Checklist,至少勾选格式化和单元测试相关项

问题

级别 文件 概述
🟡 建议 ernie_x1_tool_parser.py:188 rindex('}')delta_text 不包含 } 时会抛出 ValueError

总体评价

PR 修复逻辑正确,测试覆盖全面,但存在一个边界情况未处理。

diff = self.prev_tool_call_arr[self.current_tool_id].get("arguments")
if diff:
if '"}' not in delta_text:
if diff is not None:

This comment was marked as outdated.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

review不对,并不会出现这个问题

Copy link
Copy Markdown
Collaborator

@LiqinruiG LiqinruiG left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@LiqinruiG LiqinruiG merged commit 14d5566 into PaddlePaddle:develop Apr 15, 2026
35 of 37 checks passed
EmmonsCurse pushed a commit to EmmonsCurse/FastDeploy that referenced this pull request Apr 15, 2026
* fix tool call parser

* add unit test

* fix unit test

* add unit test
@EmmonsCurse
Copy link
Copy Markdown
Collaborator

✅ Cherry-pick successful! Created PR: #7417

EmmonsCurse pushed a commit to EmmonsCurse/FastDeploy that referenced this pull request Apr 15, 2026
* fix tool call parser

* add unit test

* fix unit test

* add unit test
@EmmonsCurse
Copy link
Copy Markdown
Collaborator

ℹ️ Cherry-pick PR already exists: #7417

EmmonsCurse pushed a commit to EmmonsCurse/FastDeploy that referenced this pull request Apr 15, 2026
* fix tool call parser

* add unit test

* fix unit test

* add unit test
@EmmonsCurse
Copy link
Copy Markdown
Collaborator

✅ Cherry-pick successful! Created PR: #7418

EmmonsCurse pushed a commit to EmmonsCurse/FastDeploy that referenced this pull request Apr 15, 2026
* fix tool call parser

* add unit test

* fix unit test

* add unit test
@EmmonsCurse
Copy link
Copy Markdown
Collaborator

ℹ️ Cherry-pick PR already exists: #7417

EmmonsCurse pushed a commit to EmmonsCurse/FastDeploy that referenced this pull request Apr 15, 2026
* fix tool call parser

* add unit test

* fix unit test

* add unit test
@EmmonsCurse
Copy link
Copy Markdown
Collaborator

ℹ️ Cherry-pick PR already exists: #7418

EmmonsCurse pushed a commit to EmmonsCurse/FastDeploy that referenced this pull request Apr 15, 2026
* fix tool call parser

* add unit test

* fix unit test

* add unit test
@EmmonsCurse
Copy link
Copy Markdown
Collaborator

✅ Cherry-pick successful! Created PR: #7419

Jiang-Jia-Jun pushed a commit that referenced this pull request Apr 16, 2026
* fix tool call parser

* add unit test

* fix unit test

* add unit test

Co-authored-by: luukunn <981429396@qq.com>
Jiang-Jia-Jun pushed a commit that referenced this pull request Apr 16, 2026
* fix tool call parser

* add unit test

* fix unit test

* add unit test

Co-authored-by: luukunn <981429396@qq.com>
Jiang-Jia-Jun pushed a commit that referenced this pull request Apr 16, 2026
* fix tool call parser

* add unit test

* fix unit test

* add unit test

Co-authored-by: luukunn <981429396@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants