feat(adk): Go runtime conversation-history compaction#2025
Draft
QuentinBisson wants to merge 2 commits into
Draft
feat(adk): Go runtime conversation-history compaction#2025QuentinBisson wants to merge 2 commits into
QuentinBisson wants to merge 2 commits into
Conversation
Port adk-python's sliding-window + token-threshold compaction to the Go runtime, bringing it to full feature parity with spec.declarative.context.compaction. Changes: - New go/adk/pkg/compaction package: watermark-based invocation counting, longestSelfContainedPrefix safety, token-threshold mode, and LLM summarization wired through existing model adapters. - go/adk/pkg/runner/adapter.go: buildCompactionConfig translates AgentCompressionConfig into a Compactor, wiring SummarizerLLM from AgentCompressionConfig.SummarizerModel (or falling back to agent model). - go/adk/pkg/a2a/executor.go: MaybeCompact called post-invocation (step 11), best-effort, never fails the request. - go/adk/pkg/session/local_session.go: ReplaceEvents for forward compat. - go/core/internal/controller/reconciler/reconciler.go: remove UnsupportedFeatures guard for context compaction. - go/go.mod: replace directive pins google.golang.org/adk to github.com/QuentinBisson/adk-go feat/event-compaction (adds EventCompaction type, EventActions.Compaction field, and applyCompaction pass in buildContentsDefault). Summary events are persisted as compaction marker events in the session backend (idempotent / resumable), not as in-memory req.Content mutations. The Anthropic null-system 400 (adk-python#5318) is structurally avoided: the summarizer request carries no SystemInstruction. Signed-off-by: QuentinBisson <quentin@giantswarm.io>
763cc6c to
16fe1c1
Compare
…nvocationID Replace the personal adk-go fork (`github.com/QuentinBisson/adk-go`) with the canonical `google.golang.org/adk` module at v1.4.0. The fork added `EventActions.Compaction` and `EventCompaction` types to persist compaction summaries. Those types do not exist in upstream v1.4.0, so the approach is changed: compaction marker events are encoded entirely within the existing `Event` fields — `Author = "compaction"` and `InvocationID = "compaction_<startNano>_<endNano>"` — with the summary in `Event.Content`. Key changes: - compaction.go: rewritten to use InvocationID encoding; adds `buildCompactionEvent`, `parseCompactionInvocationID`, `findWatermark`, `filterCompactionMarkers`, and exported `BuildCompactedEventList` - session_wrapper.go: new `compactingService` wrapper that applies `BuildCompactedEventList` on `Get` so the runner receives a compacted view while the raw marker events remain in storage for `MaybeCompact` - adapter.go: wraps the session service with `NewCompactingService` when compaction is configured; unwrapping is transparent to the executor - local_session.go: remove `ReplaceEvents` (no callers) - go.mod: drop `replace google.golang.org/adk => …` directive; upgrade to `google.golang.org/adk v1.4.0` Signed-off-by: QuentinBisson <quentin@giantswarm.io>
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.
What
Implement conversation-history compaction for the Go ADK runtime, bringing it to functional parity with the Python runtime's
spec.declarative.context.compactionfeature.The Go runtime previously silently dropped the
contextConfig.compactionfield and raisedUnsupportedFeaturesonruntime: godeclarative agents. This PR fixes that.Approach
The compaction algorithm is ported from adk-python and runs entirely within the kagent
adk/pkg/compactionpackage — no fork ofgoogle.golang.org/adkis required.Because
google.golang.org/adkv1.4.0 has no compaction event types, compaction markers are encoded in existingEventfields:Author = "compaction"InvocationID = "compaction_<startNano>_<endNano>"Contentholds the LLM-generated summaryA
compactingServicewrapper (session_wrapper.go) interceptsGetto replace the raw marker events with synthetic summary events before the runner sees them. The underlying storage keeps the markers intact soMaybeCompactcan parse the watermark on subsequent invocations.Algorithm
Mirrors adk-python's invocation-based sliding window:
InvocationID; parse the watermark from the most recent compaction marker'sInvocationID≥ compactionIntervalmax(0, firstNewIdx - overlapSize)(overlap reaches back into already-compacted invocations)Supports both sliding-window and token-threshold modes. All model adapters (Anthropic, OpenAI, Bedrock, Ollama) are reused for summarization via the existing
CreateLLMpath.Files changed
go/adk/pkg/compaction/compaction.goBuildCompactedEventList, watermark parsing,filterCompactionMarkers,MaybeCompactgo/adk/pkg/compaction/session_wrapper.gocompactingService+compactedSessionwrapper; applies compacted view onGet, unwraps onAppendEventgo/adk/pkg/compaction/compaction_test.gomakeCompactionMarkerEventusing the new encodinggo/adk/pkg/runner/adapter.goNewCompactingServicewhen compaction is configuredgo/adk/pkg/session/local_session.goReplaceEvents(no callers)go/core/internal/controller/reconciler/reconciler.goUnsupportedFeaturesguard forcontext.compactiononruntime: gogo/go.mod/go/go.sumgoogle.golang.org/adkto v1.4.0; no replace directiveCloses
#1173