Skip to content

[dotnet-code] Consolidate compaction group predicates #821

Description

@github-actions

Summary

Consolidated repeated compaction group predicates into unexported MessageGroup helpers. This keeps the Go MessageIndex aggregation paths closer to the .NET CompactionMessageIndex predicate shape while preserving existing behavior and avoiding public API changes.

.NET Reference

  • dotnet/src/Microsoft.Agents.AI/Compaction/CompactionMessageGroup.cs - group state such as IsExcluded and summary classification metadata.
  • dotnet/src/Microsoft.Agents.AI/Compaction/CompactionMessageIndex.cs - index aggregation predicates over included and raw/non-summary groups.

Public API and Behavior

No public Go API changed. No intentional behavior change was made.

Tests

  • go test ./agent/compaction

Notes

Rejected candidates from the random .NET sample:

  • dotnet/src/Microsoft.Agents.AI.Workflows/ProtocolBuilder.cs maps to public Go protocol builder behavior, so cleanup risked API-facing churn.
  • dotnet/src/Microsoft.Agents.AI.Workflows/Checkpointing/EdgeInfo.cs maps to public Go checkpoint edge metadata with different serialization constraints, so no safe tiny internal-only change was obvious.
  • dotnet/src/Microsoft.Agents.AI.Workflows/RequestInfoEvent.cs already has a minimal direct Go counterpart, so there was no meaningful structural cleanup to make.

Generated by .NET-to-Go Code Portability Refactoring Agent · gpt55 · 89.3 AIC · ⌖ 16.9 AIC · ⊞ 23.2K ·


Note

This was originally intended as a pull request, but GitHub Actions is not permitted to create or approve pull requests in this repository.
The changes have been pushed to branch dotnet-code/compaction-group-predicates-8f07de7294789c4f.

Click here to create the pull request

To fix the permissions issue, go to SettingsActionsGeneral and enable Allow GitHub Actions to create and approve pull requests. See also: gh-aw FAQ

Show patch preview (113 of 113 lines)
From 1dcc3e763eb074beb84f368ad72bce66d6962dfd Mon Sep 17 00:00:00 2001
From: "github-actions[bot]" <github-actions[bot]@users.noreply.github.com>
Date: Mon, 10 Aug 2026 22:35:43 +0000
Subject: [PATCH] Consolidate compaction group predicates

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---
 agent/compaction/group.go | 10 +++++++++-
 agent/compaction/index.go | 16 ++++++++--------
 2 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/agent/compaction/group.go b/agent/compaction/group.go
index 6b0584f0a..c1f2f8261 100644
--- a/agent/compaction/group.go
+++ b/agent/compaction/group.go
@@ -67,8 +67,16 @@ func newMessageGroup(kind GroupKind, messages []*message.Message, byteCount, tok
 	}
 }
 
+func (group *MessageGroup) isIncluded() bool {
+	return !group.IsExcluded
+}
+
 func (group *MessageGroup) isIncludedNonSystem() bool {
-	return !group.IsExcluded && group.Kind != GroupKindSystem
+	return group.isIncluded() && group.Kind != GroupKindSystem
+}
+
+func (group *MessageGroup) isRaw() bool {
+	return group.Kind != GroupKindSummary
 }
 
 func cloneTurnIndex(turnIndex *int) *int {
diff --git a/agent/compaction/index.go b/agent/compaction/index.go
index 4b2f6e6d5..b69b60d1b 100644
--- a/agent/compaction/index.go
+++ b/agent/compaction/index.go
@@ -182,7 +182,7 @@ func (index *MessageIndex) AddGroup(kind GroupKind, messages []*message.Message,
 func (index *MessageIndex) IncludedMessages() []*message.Message {
 	var messages []*message.Message
 	for _, group := range index.Groups {
-		if !group.IsExcluded {
+		if group.isIncluded() {
 			messages = append(messages, group.Messages...)
 		}
 	}
@@ -232,7 +232,7 @@ func (index *MessageIndex) TotalTokenCount() int {
 func (index *MessageIndex) IncludedGroupCount() int {
 	var total int
 	for _, group := range index.Groups {
-		if !group.IsExcluded {
+		if group.isIncluded() {
 			total++
 		}
 	}
@@ -243,7 +243,7 @@ func (index *MessageIndex) IncludedGroupCount() int {
 func (index *MessageIn
... (truncated)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions