Files
Shahin Saadati f9ae6d937c Add Kotlin snippet for VertexAiSessionService (#2102)
* Add Kotlin snippet for VertexAiSessionService

The VertexAiSessionService section showed Python, Go and Java. Kotlin gained
the service in adk-kotlin 0.7.0, so add a Kotlin tab and Kotlin to that
section's language-support badge.

Kotlin addresses the reasoning engine differently from every sibling tab on
the page, so the snippet says so at the point of use:

- The engine is fixed at construction via `reasoningEngineId`. The 0.7.0 KDoc
  is explicit that, unlike the Python and Java ADK, `SessionKey.appName` is
  never parsed to derive the engine -- it is only a label. The Python tab
  above passes the engine through `app_name` on each call.
- `reasoningEngineId` must be the bare numeric id. The constructor rejects a
  full resource name outright (`require(reasoningEngineId.all { it.isDigit() })`),
  while the Python tab passes
  `projects/.../locations/.../reasoningEngines/...`.

A reader copying the adjacent Python idiom would therefore fail twice over.

Written inline to match the two existing Kotlin tabs on this page. Inline
snippets never reach Gradle, so this one was additionally compiled against the
0.7.0 pin in a scratch file that is not part of the commit.

* Address review: JVM-only note, wire the service to a Runner

Five fixes from self-review against the 0.7.0 sources and upstream's own
VertexAiSessionServiceExample.kt, which I should have consulted before writing
the first version:

- State that the service is JVM-only. It lives in core/src/jvmMain, so it does
  not exist on Android. Kotlin is the only language on this page where that
  distinction applies, so if the Kotlin tab omits it, nothing carries it.
- Show the service actually being used. The snippet stopped at an uncalled
  `suspend fun`; it now hands the service to an InMemoryRunner, which is what
  the section is about and what the upstream example does.
- Use `runBlocking` in a `main`, matching upstream, instead of a suspend
  function nothing calls.
- Drop `state = mapOf(...)`. It defaults to null, upstream omits it, and the
  Java tab explicitly notes no initial state is needed, so it introduced a
  concept the sibling tabs deliberately avoid.
- Widen the comparison from "the Python and Java tabs" to all the other tabs.
  The KDoc phrasing names Python and Java, but this page also has a Go tab.

The added LlmAgent needs an explicit `model`; the first draft would not have
compiled without it, which the scratch compile caught.

* Trim the snippet back to parity with the sibling tabs

The previous revision added an LlmAgent, a Gemini model and an InMemoryRunner,
taking the tab to 30 code lines against Python's 5, Go's 8 and Java's 12. No
sibling tab on this page constructs a runner or an agent, and this section's
prose never mentions one -- it is a characteristics list, not a wiring guide.

That change came from misapplying a review finding. On sessions/memory the
equivalent note was right: the prose there says "instantiating the
VertexAiMemoryBankService and passing it to the Runner" and the Python tab
shows exactly that. Neither holds here, so the runner was answering a question
this page does not ask.

Now scoped like the Java tab, the closest analogue: construct the service, then
create one session. That is still enough to demonstrate both divergences -- the
engine pinned at construction as a bare numeric id, and appName being only a
label -- since showing the second requires a SessionKey.

`runBlocking` stays, because createSession is a suspend function; it is the
direct counterpart of the Java tab's `.blockingGet()`, and the comment now says
so. Recompiled against the 0.7.0 pin in a scratch file.

* docs: update experimental annotation placement and refine context caching documentation note
2026-08-17 14:56:57 -07:00
..