docs: add metadata field to context compaction event contracts#14
docs: add metadata field to context compaction event contracts#14colombod wants to merge 2 commits intomicrosoft:mainfrom
Conversation
Include the optional `metadata: dict | null` property bag in context manager event emissions: - Added metadata to context:pre_compact and context:post_compact examples - Added context:compaction to the standard events list - Documented the metadata property bag pattern for extensibility - Updated the validation checklist to reference metadata This ensures module authors know to include metadata in their event payloads, enabling implementation-specific data (strategy variant, trigger reason, etc.) without breaking the contract. 🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
bkrabach
left a comment
There was a problem hiding this comment.
Thanks for the contribution — adding metadata as an extensibility point on context events is the right call and aligns with how we use metadata across the ecosystem as a property bag for experimentation and convention.
Two items to address:
1. Example should show the populated case (required)
The current example shows "metadata": None — contract docs are copy-paste targets. Show an exemplar instead, e.g.:
"metadata": {"strategy": "sliding_window", "trigger": "token_limit"}The explanatory text below can note that it's None when no implementation-specific data is available.
2. context:compaction documentation (positive)
Good catch — context:compaction exists as a constant in events.py but wasn't documented in this contract. Worth noting in the PR description that you're documenting an existing-but-unimplemented event.
0315862 to
1ad98b5
Compare
|
Addressed both items: 1. Populated examples — Updated the code samples to show phase-appropriate metadata instead of
The explanatory text below still notes that 2. |
1ad98b5 to
48285fd
Compare
🤖 Generated with [Amplifier](https://github.com/microsoft/amplifier) Co-Authored-By: Amplifier <240397093+microsoft-amplifier@users.noreply.github.com>
48285fd to
7c7d128
Compare
Summary
Contract-only change to
CONTEXT_CONTRACT.md. Adds an optionalmetadata: dict | nullproperty bag to all context compaction event payloads and documents the previously undocumentedcontext:compactionevent.No code changes — this establishes the contract for future implementation in context manager modules.
What this PR does
Adds
metadatafield to compaction event examples — the code samples forcontext:pre_compactandcontext:post_compactnow include ametadatadict showing phase-appropriate exemplars that future implementers can use as copy-paste targets:pre_compact:{"strategy": "sliding_window", "trigger": "token_limit", "budget": 195000}— reports why compaction is happening and under what constraintspost_compact:{"budget_remaining": 97500, "storage_quota_pct": 0.42}— reports what is left after compaction, including persistence-aware info like remaining storage quotaDocuments
context:compactionwith a concrete example — this event already exists as a constant inamplifier_core/events.py(line 41:CONTEXT_COMPACTION = "context:compaction") but was missing from the contract doc. This PR adds it to the "Standard events to emit" list along with a full payload example showing before/after stats and metadata with compaction trigger reason and strategy (e.g.,"compaction_trigger": "topic_drift","strategy": "semantic_pruning").Adds metadata property bag explanation — describes the
metadatafield as an extensible property bag for implementation-specific data (compaction strategy, trigger reason, remaining budget, storage quota). Consumers that do not need metadata ignore it; set tonullwhen no implementation-specific data is available.Updates validation checklist — the "Recommended" checklist now mentions the metadata field.
Motivation
Context compaction event payloads currently have no extensibility mechanism. Different context manager implementations (in-memory, persistent, quota-aware) will want to surface implementation-specific data without changing the top-level event shape. An optional
metadataproperty bag is the lightest-weight way to enable this.Current state of implementations
amplifier-module-context-simplecurrently emits onlycontext:compaction(notpre_compact/post_compact) with a flat stats dict and nometadatafield.amplifier-module-context-persistentinherits fromcontext-simpleand emits no additional events.Backward compatibility
Contract change only. The
metadatafield is optional (dict | null, defaults tonull), so existing context managers remain compliant without modification.