Skip to content

Preserve raw JSON in tool result compaction - #1088

Merged
Quim Muntal (qmuntal) merged 1 commit into
microsoft:mainfrom
gabisonia:fix/tool-result-compaction-json
Sep 16, 2026
Merged

Quim Muntal (qmuntal) merged 1 commit into
microsoft:mainfrom
gabisonia:fix/tool-result-compaction-json

Conversation

@gabisonia

Copy link
Copy Markdown
Contributor

Fixes #1087

ToolResultStrategy currently formats json.RawMessage results as byte numbers. Preserve the JSON text in the summary by converting raw messages directly to strings, while keeping the existing formatting for other result types.

Added regression coverage in the existing compaction test file for raw JSON objects, arrays, null, empty/nil values, and ordinary string and number results. The raw JSON cases fail before the fix and pass afterward.

Validation: go test -race -shuffle=on ./..., golangci-lint (zero issues), and the local reproduction sample against the fix.

Copilot AI lite review requested due to automatic review settings September 16, 2026 14:04
@github-actions github-actions Bot added area:agent Changes files in the agent area size:medium At most 100 changed lines across at most 5 files labels Sep 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved review comments remain, and regression coverage is included.

Pull request overview

Preserves raw JSON text in tool-result compaction summaries while retaining existing formatting for other result types.

Changes:

  • Formats json.RawMessage results directly as strings.
  • Adds regression coverage for JSON and scalar result types.
File summaries
File Description
agent/compaction/toolresult.go Preserves raw JSON formatting.
agent/compaction/compaction_test.go Adds formatter regression coverage.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@github-actions github-actions Bot added kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure labels Sep 16, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Scope: user-visible behavior
Changed Go contract: DefaultToolCallFormatter (agent/compaction/toolresult.go) — internal call-result stringification for *message.FunctionResultContent.Result now special-cases json.RawMessage, converting it to its raw string form instead of fmt.Sprint, which previously rendered json.RawMessage (a []byte alias) as a numeric byte-slice literal (e.g. [123 34 ...]). No exported signature changed.
Upstream evidence reviewed:

  • Python python/packages/core/agent_framework/_compaction.py::_tool_result_text — converts Mapping results via json.dumps(...) and falls through to str(value) for everything else, i.e. it never renders JSON-like payloads as raw byte/character-code sequences.
  • .NET dotnet/src/Microsoft.Agents.AI/Compaction/ToolResultCompactionStrategy.cs::DefaultToolCallFormatter (line ~195) — resultsByCallId[frc.CallId] = frc.Result?.ToString() ?? string.Empty;, which for a JsonElement/string result yields the readable JSON text, not a numeric array.
    Result: aligned — this fixes a Go-specific bug where fmt.Sprint on json.RawMessage ([]byte) rendered byte-code arrays instead of JSON text, which was a divergence from both upstream implementations' behavior of preserving readable text/JSON in the tool-result summary. The fix restores parity rather than introducing new divergence. No exported API surface changed (signature of DefaultToolCallFormatter and ToolResultStrategy unchanged), so public-api-change is not applicable. Test coverage (TestDefaultToolCallFormatter_ResultTypes) matches the categories of inputs handled by the upstream formatters (objects, arrays, null, empty, plain string/number).

Generated by Go API Consistency Review Agent · copilot · auto · 27.8 AIC · ⌖ 5.38 AIC · ⊞ 9.6K ·

@qmuntal Quim Muntal (qmuntal) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@qmuntal
Quim Muntal (qmuntal) added this pull request to the merge queue Sep 16, 2026
Merged via the queue into microsoft:main with commit 41870d7 Sep 16, 2026
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:agent Changes files in the agent area kind:code Changes production behavior or code kind:tests Changes tests, fixtures, or test infrastructure size:medium At most 100 changed lines across at most 5 files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tool result compaction converts raw JSON into byte numbers

3 participants