From 0e12653b0b32b6378618743699b77ed0564ea61c Mon Sep 17 00:00:00 2001 From: Diego Colombo Date: Thu, 12 Feb 2026 22:40:10 +0000 Subject: [PATCH] feat: add metadata property bag to context:compaction event MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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> --- amplifier_module_context_simple/__init__.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/amplifier_module_context_simple/__init__.py b/amplifier_module_context_simple/__init__.py index ab57c14..f40ab90 100644 --- a/amplifier_module_context_simple/__init__.py +++ b/amplifier_module_context_simple/__init__.py @@ -1001,6 +1001,11 @@ async def _finalize_compaction_with_stats( "target_tokens": target_tokens, "protected_recent": self.protected_recent, "protected_tool_results": self.protected_tool_results, + "metadata": { + "reason": "token_threshold_exceeded", + "threshold": self.compact_threshold, + "usage_ratio": old_tokens / budget if budget > 0 else 0, + }, } self._last_compaction_stats = stats