Python: Empty tool results lose correlation and fail serialization
メンテナーはふだん 4 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 88/100
調査の方向性
semantic_kernel/contents/chat_history.py の ChatHistory._prepare_for_add() から始め、その後、issue にある空の結果のケースを再現します。FunctionResultContent のフィールドと message.to_dict() を対象とする、焦点を絞った回帰テストを追加します。空のツール結果が呼び出し ID を保持し、例外を発生させずにシリアライズされれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the bug
ChatHistory.add_tool_message() drops an empty-string tool result instead of preserving it as FunctionResultContent. The appended message still has role tool, but its items list is empty and the supplied tool_call_id is lost. Serializing that otherwise ordinary history message then raises IndexError because ChatMessageContent.to_dict() expects a tool message to contain a function result.
An empty string is a valid tool result for cases such as a successful command with no stdout or a no-op tool. The helper documents content as a string and requires tool_call_id; it should retain both even when the string is empty.
To reproduce
from semantic_kernel.contents.chat_history import ChatHistory
history = ChatHistory()
history.add_tool_message("", tool_call_id="call_123")
message = history.messages[-1]
print(message.role.value, len(message.items))
print(message.to_dict())
On current main (3438d882):
tool 0
IndexError: list index out of range
No model, provider, credentials, or network request is involved.
Root cause and proposed scope
ChatHistory._prepare_for_add() currently constructs FunctionResultContent only when content is truthy:
if role == AuthorRole.TOOL and content and not items:
Changing that predicate to content is not None preserves the existing behavior while allowing a valid empty result to retain result="", id, and call_id. A focused regression should assert both the FunctionResultContent fields and the serialized tool-message dictionary.
This is related to, but distinct from, #13678: that PR improves an Azure adapter's error for manually constructed tool messages with no items. This issue is about preventing the public ChatHistory.add_tool_message() helper from creating that invalid shape when its documented string input is empty.
Expected behavior
The helper should append one FunctionResultContent with the empty result and supplied call ID, and message.to_dict() should produce a valid tool message instead of raising.
Platform
- Language: Python
- Source: current repository
mainat3438d882 - AI model: not applicable
- OS: macOS; provider-free reproduction
I can submit the focused predicate change and regression once maintainers confirm this contract.
- 主要言語
- C#
- スター
- 28.6k
- フォーク
- 4.8k
- 平均マージ
- 1日 3時間
- マージ済み PR(30日)
- 16
環境構築
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
microsoft/semantic-kernel のほかの issue
-
python triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
microsoft/semantic-kernel#14512 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
.NET python triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
microsoft/semantic-kernel#14511 ·
メンテナーはふだん 4 日以内に返信
-
python triage
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
microsoft/semantic-kernel#14491 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
python triage
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
microsoft/semantic-kernel#14490 · コメント 1 件 ·
メンテナーはふだん 4 日以内に返信
-
Python: [Python] structured_outputs_transform reuses ChatHistory across calls (prompt pollution)オープンpython triage
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
microsoft/semantic-kernel#14483 · コメント 2 件 ·
メンテナーはふだん 4 日以内に返信
microsoft/semantic-kernel の issue をすべて見る
似ている issue
-
:watch: Not Triaged dotnet-target-version
難易度 1/5 1時間未満 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
copilot documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
メンテナーはふだん 2 日以内に返信
-
untriaged
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
dotnet/dotnet-api-docs#13124 ·
メンテナーはふだん 1 日以内に返信
-
agentic-workflows
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
メンテナーはふだん 1 日以内に返信
-
type:bug
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
BHoM/MidasCivil_Toolkit#441 ·