bug(backends): tool-call JSON nested under a non-first dict key is silently dropped by find_func

オープン 初心者向け
#1,867 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 3 日以内に返信

まだ誰も着手していません。

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
82/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
backend

調査の方向性

バグは mellea/backends/tools.py の 510〜511 行付近の find_func にあります。d.values() をループする処理が最初の値で return してしまいます。issue に示されているとおり、ツール呼び出しが最初のキーではない dict を用いて parse_tools で再現してください。完了条件は、後のキーの下にあるエンベロープされた呼び出しが返されること、最初のキーの場合も引き続き動作すること、そして両方のキー順序をカバーするテストが通ることです。

索引モデルが issue の本文から書いたものです。

説明

What happened?

find_func in mellea/backends/tools.py searches a parsed JSON object for a {name, arguments} tool call. When the top-level object has no name/arguments of its own, it recurses into the object's values — but returns inside the loop, so only the first value is ever searched:

# mellea/backends/tools.py:510-511
for v in d.values():
    return find_func(v)
return None, None

If a model wraps its tool call in an envelope where the call is not the first value — e.g. {"meta": 1, "call": {"name": "f", "arguments": {...}}} — parse_tools returns [] and the tool call is silently dropped. The identical envelope with keys in the other order works, so extraction depends on arbitrary key ordering in the model's output.

This feeds to_tool_calls (mellea/backends/utils.py), which is used by LocalHFBackend.post_processing — so a local-HF model emitting an enveloped tool call loses the call entirely (no error, the reply just has no tool_calls).

What did you expect to happen?

All values of the envelope dict should be searched, and {"meta": 1, "call": {...}} should yield the same tool call as {"call": {...}, "meta": 1}.

How can we reproduce it?
from mellea.backends.tools import parse_tools

# call is the first value -> found
print(parse_tools('{"call": {"name": "f", "arguments": {"x": 1}}, "meta": 1}'))
# [('f', {'x': 1})]

# same call under a later key -> dropped
print(parse_tools('{"meta": 1, "call": {"name": "f", "arguments": {"x": 1}}}'))
# []   <-- expected [('f', {'x': 1})]

The nested object is never reached by the fix-up scan either: json_extraction advances index to the end of the outer object after raw_decode, so the inner { is not re-scanned.

Mellea version
0.10.0.dev0
Any environmental details we need to know?

Affects the local HF path (LocalHFBackend.post_processing -> to_tool_calls -> _parse_tool_calls -> find_func); any caller of parse_tools/to_tool_calls is affected. No model needed to reproduce — pure parsing bug.

Additional context

Suggested fix is small — search all values and return the first hit:

for v in d.values():
    result = find_func(v)
    if result != (None, None):
        return result
return None, None
主要言語
Python
スター
1.8k
フォーク
161
平均マージ
4日 4時間
マージ済み PR(30日)
47

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

generative-computing/mellea のほかの issue

generative-computing/mellea の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。