.NET: [Issue]: Function invocation middleware receives tool results as JsonElement, which the docs do not mention

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

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

@LHB0317 がすでに取り組んでいます。

2026年11月2日 から。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
72/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
documentation

調査の方向性

不足しているのは FunctionInvocationDelegatingAgentBuilderExtensions.Use の XML ドキュメントコメントで、そこではデリゲートが関数呼び出しの結果を表すタスクを返すことしか書かれていません。そのコメントと FunctionInvocationContext 型を読み、Result プロパティが存在しないことを確認してください。そのうえで、継続処理が、ツールの結果をシリアル化した JsonElement を生成すること、そしてシリアル化可能な値を返すと、モデルが見る内容が置き換わることを述べる文を1つ追加してください。ドキュメントコメントに実行時の型が記載され、生成された API ドキュメントにもそれが反映されていれば完了です。

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

説明

.NET triage
Category

Documentation

Problem

AIAgentBuilder.Use(...) function-invocation middleware receives every tool result as a JsonElement, whatever the tool declares, and no documentation says so. The only statement is on FunctionInvocationDelegatingAgentBuilderExtensions.Use: the delegate "returns a task representing the result of the function invocation". The runtime type is not mentioned anywhere, so the natural implementation of a middleware that inspects or rewrites a result silently does nothing.

Evidence

Measured with Microsoft.Agents.AI.Harness 1.27.0, one tool per shape, reading result.GetType().Name inside the middleware:

tool returns middleware receives
string JsonElement containing "a plain string"
int JsonElement containing 42
a record Poco(string Name, int Value) JsonElement containing {"name":"x","value":1}
int[] JsonElement containing [1,2,3]

The guard a developer writes first therefore never fires:

.Use((AIAgent _, FunctionInvocationContext ctx,
       Func<FunctionInvocationContext, CancellationToken, ValueTask<object?>> next,
       CancellationToken ct) =>
{
    var result = await next(ctx, ct);
    if (result is not string text || text.Length <= cap) return result;  // never truncates
    return Truncate(text);
})

Rewriting does work once the type is known: returning a string from the middleware reached the provider as 22 characters instead of 868,893, on both the streaming and non-streaming paths. FunctionInvocationContext also exposes no Result property, so the value exists only as the continuation's return value.

The underlying behaviour looks deliberate, serialising once instead of deserialising and re-serialising, so this is reported as a documentation gap rather than a defect in the pipeline.

Desired Outcome

The Use documentation should state what the continuation returns: a JsonElement holding the serialized tool result, and that returning a serializable value from the middleware replaces what the model sees. One sentence is enough; a typed helper such as ctx.GetResult<T>() would be nicer but is not what this issue asks for.

Language

.NET

Acknowledgements
  • I searched existing issues and did not find a duplicate.
  • I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.

AI assistance. The analysis, the probe program and this report were prepared with an AI coding assistant. The type table above was produced by running the probe against the published package; nothing is inferred. API names and versions were checked against the package and the repository's main branch.

Verification. Measured locally before filing:

  • OS: Windows 10.0.26300.9711
  • SDK: .NET SDK 10.0.402, runtime 10.0.9
  • Package: Microsoft.Agents.AI.Harness 1.27.0
  • How: dotnet run on a console project that registers one tool per shape, runs a scripted IChatClient, and prints the runtime type of the middleware's continuation result
  • Output: JsonElement for all four shapes, as tabulated above
主要言語
Python
スター
14.5k
フォーク
2.6k
平均マージ
2日 13時間
マージ済み PR(30日)
335

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

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

microsoft/agent-framework のほかの issue

microsoft/agent-framework の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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