Skip to content

feat: add metadata property bag to context:compaction event#6

Open
colombod wants to merge 1 commit intomicrosoft:mainfrom
colombod:feat/compaction-event-metadata
Open

feat: add metadata property bag to context:compaction event#6
colombod wants to merge 1 commit intomicrosoft:mainfrom
colombod:feat/compaction-event-metadata

Conversation

@colombod
Copy link
Contributor

Summary

Adds a metadata property bag to the context:compaction event payload, providing implementation-specific context about why compaction was triggered and the conditions at the time.

Changes

Added metadata dict to the stats payload in _finalize_compaction_with_stats():

"metadata": {
    "reason": "token_threshold_exceeded",
    "threshold": self.compact_threshold,
    "usage_ratio": old_tokens / budget if budget > 0 else 0,
}
  • reason — why compaction was triggered (currently always "token_threshold_exceeded" since that's the only trigger path)
  • threshold — the configured compaction threshold (default 0.92)
  • usage_ratio — the actual token usage ratio that exceeded the threshold

Motivation

The context:compaction event had 14 flat scalar keys with no extensibility mechanism. This follows the metadata property bag pattern documented in CONTEXT_CONTRACT.md (see microsoft/amplifier-core#14), giving consumers structured context about compaction triggers without changing the existing top-level payload shape.

Backward Compatibility

Purely additive — one new key (metadata) added to the existing stats dict. All existing consumers serialize the payload generically (hooks-logging) and will pass through the new field without issue.

Testing

  • 21 module-specific tests pass
  • 11 errors and 1 failure are pre-existing on main (missing fixture wiring and an unrelated assertion)
  • Lint and format checks pass

🤖 Generated with Amplifier

Add a metadata dict to the stats payload in _finalize_compaction_with_stats()
containing reason, threshold, and usage_ratio. This provides structured context
about why compaction was triggered without changing the existing top-level
payload shape.

🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier)

Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant