Files
Shahin Saadati 9bca69d530 Add Kotlin snippet for the CallbackContext memory-write helpers (#2121)
* Add Kotlin snippet for the CallbackContext memory-write helpers

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.

* docs: clarify CallbackContext memory methods and their default behavior
2026-08-18 11:13:48 -07:00
..