[Engine] String tool-call arguments are emitted with \uXXXX escapes (ensure_ascii=True in OutputParser._scan)

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

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

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

評価

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

調査の方向性

terminal/serve/frontend.py を開き、OutputParser._scan() を読んでください。文字列パラメータの内容を出力する4つの json.dumps 呼び出しに注目してください。近くにある _close_scan() はすでに ensure_ascii=False を渡しており、意図したパターンを示しています。この4箇所に ensure_ascii=False を追加し、文字列パラメータにキリル文字やCJKテキストを受け取るツール(例:path = "Папка")を、ストリーミングモードと非ストリーミングモードの両方で実行してください。両方のレスポンスの arguments に \uXXXX エスケープがなく、読める文字が表示され、既存のパーサーテストがすべて通れば完了です。

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

説明

Area

[Engine] (the server and API)

Environment
  • Strata: 0.2.17
  • OS: Windows 10
  • GPU: RTX A4000 16 GB
  • RAM: 64 GB
Related

Follow-up to the second observation in #4630 (escaped Unicode in string arguments).
The newline/array fix from 0.2.8 does not cover this.

What happens

When a tool parameter is declared as "type": "string" and contains non-ASCII text (Cyrillic, CJK, emoji, etc.), the arguments field in both streaming and non-streaming responses contains escaped Unicode:

"arguments": "{\"path\":\"\\u041f\\u0430\\u043f\\u043a\\u0430\"}"

instead of the readable form:

"arguments": "{\"path\":\"Папка\"}"

Array/object parameters and ordinary assistant text are fine.

Where

terminal/serve/frontend.py, method OutputParser._scan() — the four places that emit string parameter content via json.dumps without ensure_ascii=False.

Nearby _close_scan() already does it correctly:

json.dumps(v, ensure_ascii=False)

The streamed fragments are later concatenated for non-stream responses as well, so the escapes appear in both modes.

Suggested fix
--- a/terminal/serve/frontend.py
+++ b/terminal/serve/frontend.py
@@ -2253,7 +2253,8 @@ class OutputParser:
                         declared = self.sdeclared.get(pname) if pname else None
                         v = coerce_value(inline, declared) if pname else _SKIP
                         if v is not _SKIP and declared == "string":
-                            args(("" if self.sfirst else ",") + json.dumps(pname) + ":" + json.dumps(v))
+                            args(("" if self.sfirst else ",") + json.dumps(pname, ensure_ascii=False)
+                                 + ":" + json.dumps(v, ensure_ascii=False))
                             self.sfirst = False
                             self.sset.add(pname)
                         elif v is not _SKIP:
@@ -2263,7 +2264,7 @@ class OutputParser:
                     if pname is not None and self.sdeclared.get(pname) == "string":
                         self.sset.add(pname)
-                        args(("" if self.sfirst else ",") + json.dumps(pname) + ':"')
+                        args(("" if self.sfirst else ",") + json.dumps(pname, ensure_ascii=False) + ':"')
                         self.sfirst = False
                         self.ss, self.sval_started = "str", False
                     else:
@@ -2291,7 +2292,7 @@ class OutputParser:
                     value = rest[:end]
                     if value.endswith("\n"):
                         value = value[:-1]
-                    args(json.dumps(value)[1:-1] + '"')
+                    args(json.dumps(value, ensure_ascii=False)[1:-1] + '"')
                     self.sp += end + close_len(rest, end, self.scloser)
                     self.ss = "between"
                     continue
@@ -2301,7 +2302,7 @@ class OutputParser:
                 if safe > 0 and rest[safe - 1] == "\n":   # may be the trailing newline before </parameter>
                     safe -= 1
                 if safe > 0:
-                    args(json.dumps(rest[:safe])[1:-1])
+                    args(json.dumps(rest[:safe], ensure_ascii=False)[1:-1])
                     self.sp += safe
                 return out

I applied this locally and confirmed that string arguments with Cyrillic now appear unescaped.

How to reproduce

Any tool with a string parameter that receives non-ASCII text (e.g. path = "Папка" or "Отчёт.md").

Note

Root cause and the exact locations were identified with the help of an AI coding assistant; the fix was verified manually.

主要言語
C++
スター
11.6k
フォーク
1k
平均マージ
18日 13時間
マージ済み PR(30日)
4

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

Niko1221/Strata のほかの issue

Niko1221/Strata の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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