From 990c86c636458742d31a0a4662f270c0164c8269 Mon Sep 17 00:00:00 2001 From: Shahin Saadati Date: Thu, 20 Aug 2026 09:28:00 -0700 Subject: [PATCH] Extend the compaction summarizer section to Kotlin The Define a Summarizer group showed Python, Java and TypeScript but not Kotlin, and two lines of surrounding prose understated Kotlin as a result: one attributed LlmEventSummarizer to Python and Java only, the other said only Python and Java can customize the prompt template. Kotlin has had LlmEventSummarizer since v0.3.0 and exposes promptTemplate as a constructor parameter. This is partial coverage rather than an untouched page - the page is already Kotlin-badged and has a Kotlin tab for the token-threshold config. That tab is inline, as are all four siblings in this group, so the new tab is inline too rather than the new .kt file the backlog suggested; mixing forms between two Kotlin tabs on one page would be worse than either choice on its own. --- docs/context/compaction.md | 39 +++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/docs/context/compaction.md b/docs/context/compaction.md index 655be3db08..a78af95554 100644 --- a/docs/context/compaction.md +++ b/docs/context/compaction.md @@ -196,8 +196,8 @@ a compactor object ### Define a Summarizer {#define-summarizer} You can customize the process of context compression by defining a summarizer. -The `LlmEventSummarizer` (Python/Java) or `LlmSummarizer` (TypeScript) class allows -you to specify a particular model for summarization. +The `LlmEventSummarizer` (Python, Java and Kotlin) or `LlmSummarizer` (TypeScript) +class allows you to specify a particular model for summarization. The following code example demonstrates how to define and configure a custom summarizer: === "Python" @@ -278,8 +278,37 @@ The following code example demonstrates how to define and configure a custom sum }); ``` -You can further refine the compactor by modifying its summarizer. In Python and Java, -customize the `prompt_template` on `LlmEventSummarizer`. In TypeScript, customize -the `prompt` on `LlmSummarizer`. For more details, see the +=== "Kotlin" + + ```kotlin + import com.google.adk.kt.apps.App + import com.google.adk.kt.models.Gemini + import com.google.adk.kt.summarizer.EventsCompactionConfig + import com.google.adk.kt.summarizer.LlmEventSummarizer + + // Define the AI model to be used for summarization: + val summarizationLlm = Gemini(name = "gemini-flash-latest") + + // Create the summarizer with the custom model: + val mySummarizer = LlmEventSummarizer(model = summarizationLlm) + + // Configure the App with the custom summarizer and compaction settings: + val app = + App( + appName = "my-agent", + rootAgent = rootAgent, + eventsCompactionConfig = + EventsCompactionConfig( + compactionInterval = 3, + overlapSize = 1, + summarizer = mySummarizer, + ), + ) + ``` + +You can further refine the compactor by modifying its summarizer. In Python, Java +and Kotlin, customize the prompt template on `LlmEventSummarizer` — the property is +`prompt_template` in Python and Java, and `promptTemplate` in Kotlin. In TypeScript, +customize the `prompt` on `LlmSummarizer`. For more details, see the [`LlmEventSummarizer` code](https://github.com/google/adk-python/blob/main/src/google/adk/apps/llm_event_summarizer.py#L60) or [`LlmSummarizer` code](https://github.com/google/adk-js/blob/main/core/src/context/summarizers/llm_summarizer.ts).