Add Kotlin snippet for the CallbackContext memory-write helpers - #2121
Open
happyhuman wants to merge 2 commits into
Open
Add Kotlin snippet for the CallbackContext memory-write helpers#2121happyhuman wants to merge 2 commits into
happyhuman wants to merge 2 commits into
Conversation
adk-kotlin 0.7.0 added addEventsToMemory and addMemory to CallbackContext, alongside the addSessionToMemory the page already shows in Kotlin. They cover the cases addSessionToMemory cannot: a chosen subset of events, and facts you construct yourself rather than letting the service derive them. Compiling changed the shape of this snippet. The obvious version read the current turn's events off context.invocationContext, but that property is internal -- CallbackContext exposes no way to reach the session. So addEventsToMemory takes events the caller already holds, and the snippet says so rather than quietly implying otherwise. Both helpers, and addSessionToMemory, throw IllegalStateException when the runner has no memory service. That is a runtime failure with nothing at compile time to warn you, so the page states it. Verified by running both paths: "Cannot add events to memory: memory service is not available." and "Cannot add memory: memory service is not available." Badged Kotlin v0.7.0, verified rather than assumed: neither helper exists on CallbackContext at v0.6.0. Appended to the existing MemoryExample.kt, already registered, so CI compiles and lints it.
✅ Deploy Preview for adk-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
wikaaaaa
approved these changes
Aug 14, 2026
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.
Summary
adk-kotlin 0.7.0 added
addEventsToMemoryandaddMemorytoCallbackContext,alongside the
addSessionToMemorythatdocs/sessions/memory.mdalready showsin Kotlin. This adds a subsection covering the two cases the existing snippet
can't: a chosen subset of events, and facts you construct yourself.
Compiling changed the snippet's shape
The obvious version read the current turn's events off the context:
That doesn't compile —
CallbackContext.invocationContextisinternal, andthe class exposes no other route to the session. So
addEventsToMemorytakesevents the caller already holds, and the snippet's KDoc says so plainly rather
than leaving a reader to discover it. Worth knowing when reviewing: the ergonomic
gap is real, not a documentation choice.
Notes for reviewers
IllegalStateExceptionwhen the runner has nomemory service — a runtime failure with nothing at compile time to warn you, so
the page states it. Verified both messages by running them:
Cannot add events to memory: memory service is not available.andCannot add memory: memory service is not available.Kotlin v0.7.0, verified not assumed — neither helper exists onCallbackContextat v0.6.0 (0 of 2 present).under Extend memory capabilities; these are the callback-side convenience
wrappers, which only Kotlin has.
MemoryExample.kt, already registered, so CIcompiles and lints it.
Verification
verify_snippets.pypasses all six levels.