Skip to content

Add Kotlin snippet for token-threshold context compaction - #2107

Merged
happyhuman merged 3 commits into
mainfrom
docs-kotlin-compaction-token-threshold
Aug 17, 2026
Merged

Add Kotlin snippet for token-threshold context compaction#2107
happyhuman merged 3 commits into
mainfrom
docs-kotlin-compaction-token-threshold

Conversation

@happyhuman

@happyhuman happyhuman commented Aug 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

docs/context/compaction.md had no Kotlin content at all. EventsCompactionConfig
gained tokenThreshold and eventRetentionSize in adk-kotlin 0.6.0, so this
adds a Kotlin tab to the "Configure context compaction" group and Kotlin to the
page badge.

One tab, +22/−3.

Notes for reviewers

  • Kotlin straddles the two groupings the prose already draws. The config
    attaches to App like Python and Java, but supports the token-threshold pair
    like TypeScript. I updated both parentheticals — (Python/Java/Kotlin) and
    (TypeScript/Kotlin) — rather than adding a sentence.
  • The pairing rule is a runtime require, not a compile error, so it's easy
    to hit. Setting tokenThreshold without eventRetentionSize throws
    tokenThreshold and eventRetentionSize must be set together or both null. The
    snippet says so in one line. The same rule governs compactionInterval /
    overlapSize, which Kotlin also supports — this tab shows the token pair
    because that's the newer capability and it mirrors the TypeScript tab.
  • Why this page's badge is v0.7.0 while Add Kotlin snippet for DebugLoggingPlugin #2105 left logging.md at v0.1.0:
    logging.md already carried a Kotlin badge and Kotlin snippets that work from
    0.1.0, so raising it would have implied a floor that doesn't apply to them.
    This page had no Kotlin badge at all, so the value is set to what a reader
    needs to run what's shown.
  • The comment notes Kotlin accepts the compactionInterval/overlapSize pair
    too.
    Showing only the token pair, while Python and Java show only the other,
    would otherwise suggest the strategy is fixed per language — it isn't.
  • Badged Kotlin v0.7.0, not 0.6.0 — the fields landed in 0.6.0, but
    appName = "my-agent" matches the sibling tabs and hyphens in app names were
    only permitted from 0.7.0 (App's regex was [a-zA-Z_][a-zA-Z0-9_]* at
    v0.6.0). Same reasoning as Add Kotlin snippet for context caching configuration #2091.
  • Inline, matching the page's other three tabs, so CI will not compile it.

Verification

Because inline snippets never reach Gradle, I extracted this one, compiled and
ran it against the 0.7.0 pin in a throwaway project — and checked the claim the
comment makes:

OK app=my-agent tokenThreshold=1000 retention=1 paired=true

and with eventRetentionSize removed:

IllegalArgumentException: tokenThreshold and eventRetentionSize must be set
together or both null (got tokenThreshold=1000, eventRetentionSize=null)

verify_snippets.py passes L0/L1/L2/L3/L5/L6. API surface read from the
adk-kotlin v0.7.0 sources.

The compaction page had no Kotlin at all. EventsCompactionConfig gained
tokenThreshold and eventRetentionSize in adk-kotlin 0.6.0, so the Kotlin tab
shows that pair, matching the TypeScript tab's strategy.

Kotlin sits across the two groupings the prose already draws: the config
attaches to App, as in Python and Java, but supports the token-threshold pair
like TypeScript. Both parentheticals are updated to say so rather than adding
new prose.

The snippet notes that tokenThreshold and eventRetentionSize must be set
together. That is a runtime require, not a compile error, so it is easy to hit:
setting one alone throws "tokenThreshold and eventRetentionSize must be set
together or both null". The same rule applies to compactionInterval and
overlapSize, which Kotlin also supports.

Badged Kotlin v0.7.0 rather than 0.6.0, when the fields landed: appName is
"my-agent" to match the sibling tabs, and hyphens in app names were only
allowed from 0.7.0.

Inline to match the page's other tabs, so CI will not compile it. Extracted,
compiled and ran it against the 0.7.0 pin in a throwaway project:
OK app=my-agent tokenThreshold=1000 retention=1 paired=true.
@netlify

netlify Bot commented Aug 10, 2026

Copy link
Copy Markdown

Deploy Preview for adk-docs-preview ready!

Name Link
🔨 Latest commit d0ce93f
🔍 Latest deploy log https://app.netlify.com/projects/adk-docs-preview/deploys/6a83876ccd1da100084d2a3a
😎 Deploy Preview https://deploy-preview-2107--adk-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@happyhuman happyhuman self-assigned this Aug 10, 2026
@happyhuman
happyhuman force-pushed the docs-kotlin-compaction-token-threshold branch from 975e216 to fadd5bf Compare August 10, 2026 21:57
Self-review finding. The Kotlin tab shows tokenThreshold/eventRetentionSize
while Python and Java show compactionInterval/overlapSize, so a reader
comparing tabs could conclude the strategy is fixed per language. It is not:
EventsCompactionConfig accepts either pair, and exposes hasTokenThresholdConfig
and hasSlidingWindowConfig for each.
@happyhuman
happyhuman force-pushed the docs-kotlin-compaction-token-threshold branch from fadd5bf to 81001b9 Compare August 10, 2026 22:13
@happyhuman
happyhuman merged commit 772a063 into main Aug 17, 2026
6 of 8 checks passed
@happyhuman
happyhuman deleted the docs-kotlin-compaction-token-threshold branch August 17, 2026 22:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants