feat(session): add EventCompaction type and compaction filtering in contents_processor#1044
Open
QuentinBisson wants to merge 4 commits into
Open
feat(session): add EventCompaction type and compaction filtering in contents_processor#1044QuentinBisson wants to merge 4 commits into
QuentinBisson wants to merge 4 commits into
Conversation
Add EventCompaction struct to EventActions. When non-nil, the event is a compaction marker: StartTimestamp/EndTimestamp delimit the range of raw events that were summarized, and CompactedContent carries the replacement summary. Add applyCompaction pass in buildContentsDefault (after transcription aggregation, before async-function-response rearrangement). The pass: - skips all compaction marker events - for each non-subsumed compaction, replaces events in [start,end] with one synthetic event carrying CompactedContent - detects subsumed compactions (a later, wider compaction covers the same range) and hides them, so only the widest covering summary is injected Port of adk-python actions.compaction / _replace_events_with_compaction_events.
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
… storage - Preserve compaction marker events through the content-presence filter in buildContentsDefault so applyCompaction actually sees them (markers have no LLM content and were silently dropped before reaching the compaction pass). - Add Compaction to the field-by-field EventActions copy in inMemoryService.AppendEvent so compaction markers survive in-memory session storage. - Exclude ranges with nil CompactedContent from active instead of silently dropping the events they cover; original events are preserved when the summarizer has not yet written a result. - De-duplicate identical [startTS, endTS] ranges via a seen-map so a retry that writes a second marker for the same window no longer causes both markers to mutually subsume each other and both be dropped. - Strengthen the subsumption condition to exclude the case where two ranges share identical timestamps, preventing identical ranges from being incorrectly treated as subsumed by each other. - Pin function-call events whose paired function-response falls outside every active range so rearrangeEventsForLatestFunctionResponse does not see an orphaned response and return a hard error.
Replace inline ev.Actions.Compaction != nil checks in applyCompaction with ev.IsCompactionMarker() so the exported method is the single authoritative check point. Drop the call-site reference to buildContentsDefault from the method doc.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ports the compaction persistence and content-assembly model from adk-python to adk-go. Fixes #1001.
What's missing today
EventActionshas noCompactionfield andbuildContentsDefaulthas no filtering step for compaction markers. This means raw events are never replaced by their summaries when building the LLM context — compaction runs but has no visible effect on what gets sent to the model.Changes
session/session.goAdded
Compaction *EventCompactiontoEventActions. The summary lives here, not inEvent.Content, so compaction markers are excluded from normal content rendering and distinguishable from real model output.internal/llminternal/contents_processor.goNew
applyCompactionpass called insidebuildContentsDefault, after transcription aggregation and before the async-function-response rearrangement step:Actions.Compaction != nil).StartTimestamp.CompactedContent; compaction marker events themselves are always removed from the output.This mirrors
_apply_compactionin adk-python'sflows/llm_flows/contents.py.Downstream reference
kagent PR kagent-dev/kagent#2025 uses this via a
replacedirective and exercises both sliding-window and token-threshold compaction modes against Anthropic and OpenAI adapters. The downstream compaction driver (watermark-based invocation counting,longestSelfContainedPrefixsafety, summarizer LLM) lives in kagent — out of scope for this PR, which only adds the session primitives and content-assembly filtering that the driver depends on.