microsoft / microsoft/agent-framework

.NET: [Bug]: Token Count Discrepancy

Open
#5,803 3 comments 0 reactions 1 assignee Claimed by @westey-m View on GitHub
.NET bug compaction reproduced
Dominant language
Python
Stars
13.6k
Forks
2.3k
Avg merge
2d 45m
Merged PRs (30d)
358

Description

### Description

Token counts passed to compaction strategies through the `index` parameter of `CompactCoreAsync` function and `UsageContent` object the `RunStreamingAsync` returns when an agent is called differs even though the compaction is not engaged at all. The token count reported by compaction strategy is less than the count reported in `UsageContent`.

I am comparing `CompactionMessageIndex.IncludedTokenCount` and `UsageContent.Details.InputTokenCount`

The difference usually big enough so it can't be ignored (e.g. Compaction reports: 2435 input tokens vs 12202 input tokens by UsageContent)

### Code Sample

```markdown

```

### Error Messages / Stack Traces

```markdown

```

### Package Versions

Microsoft.Agents.AI 1.4.0

### .NET Version

.NET10

### Additional Context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.