Skip to content

feat: add a Vertex AI-backed SessionService#211

Open
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_947644188
Open

feat: add a Vertex AI-backed SessionService#211
copybara-service[bot] wants to merge 1 commit into
mainfrom
test_947644188

Conversation

@copybara-service

Copy link
Copy Markdown

feat: add a Vertex AI-backed SessionService

Implement SessionService against the managed Vertex AI Session Service so agent sessions and events persist in Vertex AI. This ports the Java ADK VertexAiSessionService and preserves its observable behavior, so callers can switch session backends without code changes.

  • Transport: use a small custom OkHttp-based client instead of a generated SDK client. The service needs only a few REST calls (create/get/list/delete session, list/append events) plus long-running-operation polling on create, so a dedicated client keeps the dependency surface small and the request/response mapping explicit.
  • Wire format: map payloads with @Serializable DTOs and mapper extensions rather than serializing the domain Event/Content directly, keeping the domain model decoupled from the wire. The mappers flatten streaming/turn signaling onto Event and encode the State.REMOVED sentinel as JSON null, which is the state-delta representation the service expects.
  • Encode byte fields (Part.thoughtSignature, Blob.data) as base64 strings to match the proto3-JSON representation of bytes. The kotlinx default serializes a ByteArray as an array of ints, which the service rejects ("Proto field is not repeating, cannot start list."); that silently dropped model events carrying a thought signature and corrupted session history.
  • Follow the Java ADK's semantics: update the in-memory session before the remote append, persist every event (including partial ones), and return list results in server order. Append failures are logged and skipped so one bad event does not abort a run, while read errors (5xx) are surfaced instead of masked as empty results.
  • Add unit tests for the service (mocked client) and the mappers (including a base64 wire-format regression test), plus transport tests driving a real client against a MockWebServer.

Implement `SessionService` against the managed Vertex AI Session Service so agent sessions and events persist in Vertex AI. This ports the Java ADK `VertexAiSessionService` and preserves its observable behavior, so callers can switch session backends without code changes.

- Transport: use a small custom OkHttp-based client instead of a generated SDK client. The service needs only a few REST calls (create/get/list/delete session, list/append events) plus long-running-operation polling on create, so a dedicated client keeps the dependency surface small and the request/response mapping explicit.
- Wire format: map payloads with `@Serializable` DTOs and mapper extensions rather than serializing the domain `Event`/`Content` directly, keeping the domain model decoupled from the wire. The mappers flatten streaming/turn signaling onto `Event` and encode the `State.REMOVED` sentinel as JSON null, which is the state-delta representation the service expects.
- Encode byte fields (`Part.thoughtSignature`, `Blob.data`) as base64 strings to match the proto3-JSON representation of `bytes`. The kotlinx default serializes a `ByteArray` as an array of ints, which the service rejects ("Proto field is not repeating, cannot start list."); that silently dropped model events carrying a thought signature and corrupted session history.
- Follow the Java ADK's semantics: update the in-memory session before the remote append, persist every event (including partial ones), and return list results in server order. Append failures are logged and skipped so one bad event does not abort a run, while read errors (5xx) are surfaced instead of masked as empty results.
- Add unit tests for the service (mocked client) and the mappers (including a base64 wire-format regression test), plus transport tests driving a real client against a `MockWebServer`.

PiperOrigin-RevId: 947644188
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.

1 participant