.NET: [Issue]: Function invocation middleware receives tool results as JsonElement, which the docs do not mention
维护者通常 1 天内回复
@LHB0317 已经在做这个了。
开始于 2026年11月2日。
评估
- 难度
- 1/5
- 预计耗时
- 1 小时以内
- 新手友好度
- 72/100
- Issue 类型
- 文档
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- csharp
调研方向
缺口在于 FunctionInvocationDelegatingAgentBuilderExtensions.Use 的 XML 文档注释,它只说明委托返回一个表示函数调用结果的任务。阅读该注释和 FunctionInvocationContext 类型,确认不存在 Result 属性,然后添加一句话,说明延续会产生一个 JsonElement,其中包含序列化后的工具结果,并且返回可序列化的值会替换模型看到的内容。当文档注释说明运行时类型,且生成的 API 文档体现了这一点时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
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.Harness1.27.0 - How:
dotnet runon a console project that registers one tool per shape, runs a scriptedIChatClient, and prints the runtime type of the middleware's continuation result - Output:
JsonElementfor all four shapes, as tabulated above
- 主要语言
- Python
- 星标
- 14.5k
- 派生
- 2.6k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 343
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/agent-framework 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 66/100
microsoft/agent-framework#9946 · 1 条评论 ·
维护者通常 1 天内回复
-
.NET triage
难度 2/5 1-3 小时 新手友好度 66/100
microsoft/agent-framework#9704 · 2 条评论 ·
维护者通常 1 天内回复
-
Python: FileSessionStore.set fails on Windows for long session IDs because its temp file name is 38 characters longer than the snapshot可能已有人在做 @Sonica-B 于 8 天前认领。 未关闭python ready-for-implementation
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/agent-framework#9682 · 已指派 2 人 ·
维护者通常 1 天内回复
-
Python: foundry-hosting drops request `metadata` from the stored response — `_create_response_event_stream` never passes `request` to `ResponseEventStream`可能已有人在做 @its-amann 于 7 天前认领。 未关闭python triage
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/agent-framework#9529 · 3 条评论 ·
维护者通常 1 天内回复
-
Python: raw-data content mappings lose annotations and attachment metadata可能重新可做 @moonbox3 于 34 天前认领,目前没有进行中的 PR。 未关闭python triage
难度 2/5 1-3 小时 新手友好度 78/100
microsoft/agent-framework#8632 · 2 条评论 ·
维护者通常 1 天内回复
查看 microsoft/agent-framework 的全部 Issue
相似的 Issue
-
ci-rerun: collect.py fails a whole pr-babysit cycle on one transient GitHub 5xx and never retries未关闭follow-up
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 70/100
-
Built-in QUBO fallback applies bitwise xor to floating binary states可能已有人在做 @iloveeyjafjalla 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
qboson/kaiwu-pytorch-plugin#1702 ·
维护者通常 3 天内回复
-
bug v2
难度 2/5 1-3 小时 新手友好度 76/100
modelcontextprotocol/python-sdk#3811 ·
维护者通常 1 天内回复
-
cost:cheap practicality:seen-in-the-wild severity:medium
难度 2/5 1-3 小时 新手友好度 72/100
fairagro/m4.2_advanced_middleware_api#620 ·
维护者通常 1 天内回复