[dotnet-port-fixes] Aggregate loop usage across iterations - #862
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the loop harness’s non-streaming “return last response only” behavior so token usage is accumulated across all loop iterations, while still surfacing only the final iteration’s response content. It aligns Go behavior with the referenced upstream LoopAgent change and adds a regression test to prevent usage undercounting.
Changes:
- Accumulate
UsageDetailsacross loop iterations whenNonStreamingReturnsLastResponseOnlyis enabled. - Strip per-iteration
UsageContentfrom the buffered final iteration updates, then attach the aggregated usage to the surfaced final response. - Add a regression test asserting summed token counts and merged
AdditionalCounts.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| agent/harness/loop/loop.go | Aggregates usage across iterations and reattaches it to the final surfaced response update. |
| agent/harness/loop/loop_test.go | Adds regression coverage ensuring usage totals are summed across iterations in last-response-only mode. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Parity Review — ✅ ApprovedThis PR ports the loop-agent usage aggregation behavior from upstream microsoft/agent-framework#7539 into the Go loop harness. Scope: Internal implementation only — all new functions ( Parity finding: The fix aligns Go behavior with the .NET Label actions:
|
|
I don't like how this PR ported the .NET implementation. Closing, will port it manually. |
Summary
Align the Go loop harness with the LoopAgent portion of microsoft/agent-framework#7539 so
NonStreamingReturnsLastResponseOnlystill reports usage from every loop iteration. The loop middleware now accumulates usage across all iterations, removes per-iteration usage from the buffered final response, and reattaches the aggregated usage to the surfaced last response. I also added a regression test that exercises summed token counts and mergedAdditionalCounts.Ported .NET PRs
Upstream commit referenced:
ec32e86646469585bf6d7be83b343c88bf606950from microsoft/agent-framework. This PR ports only the LoopAgent behavior that maps toagent/harness/loop.Breaking Changes
No. This corrects internal usage accounting for existing loop runs without changing exported Go API.
Tests and Examples
go test ./agent/harness/loopagent/harness/loop/loop_test.gofor aggregated usage in last-response-only non-streaming runsNotes
This intentionally scopes the upstream port to the Go loop harness slice of microsoft/agent-framework#7539. The broader .NET PR also updated other looping components that do not map to this narrow Go change set.
Closes #847