Skip to content

feat(firestore): add builder API to FirestoreDatabaseRunner - #1957

Open
mohan-ganesh wants to merge 1 commit into
google:mainfrom
mohan-ganesh:firestore-builder-pattern
Open

mohan-ganesh wants to merge 1 commit into
google:mainfrom
mohan-ganesh:firestore-builder-pattern

Conversation

@mohan-ganesh

@mohan-ganesh mohan-ganesh commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

FirestoreDatabaseRunner previously required gcs.adk.bucket.name at start up and offered no way to inject services without subclassing. All changes here are confined to the firestore-session-service contrib module and are bundled because they share the same migration path: the builder API, constructor deprecation, the property key rename and documentation all need to land together to give a coherent upgrade experience from constructor-based API.

  • Add FirestoreDatabaseRunner.newBuilder() and create(...) factory methods that aligned to core ADK Runner.builder() pattern.
  • Default to InMemoryArtifactService when no GCS bucket or artifact service is set.
  • Preserve backward compatibility with legacy constructors using safe fallback.
  • Standardize root collection property to firestore.root.collection.name with legacy fallback.
  • Add unit tests and also increased test coverage for FireStoreSession and update documentation.

Problem

FirestoreDatabaseRunner required gcs.adk.bucket.name to be set in a properties file at startup. If the property was missing, the constructor threw a RuntimeException — even for text-only agents that never produce file artifacts. This made development and testing unnecessarily difficult.

Additionally, the constructor-only API had three overloads with no way to inject custom session, memory, or artifact services without subclassing, making it hard to test and impossible to extend cleanly.

Solution

Adds a builder API to FirestoreDatabaseRunner, mirroring the pattern already established by Runner.builder() in core ADK — where the Runner constructors are themselves deprecated in favour of Runner.Builder.

New API

// Minimal — no GCS bucket required for text agents
Runner runner = FirestoreDatabaseRunner.newBuilder()
.agent(agent)
.firestore(FirestoreOptions.getDefaultInstance().getService())
.build();

// With explicit GCS artifact storage
Runner runner = FirestoreDatabaseRunner.newBuilder()
.agent(agent)
.firestore(firestore)
.withGcsArtifacts("my-bucket")
.build();

// Full control — inject any service
Runner runner = FirestoreDatabaseRunner.newBuilder()
.agent(agent)
.firestore(firestore)
.sessionService(customSessionService)
.artifactService(new InMemoryArtifactService())
.instantSource(fixedClock)
.build();

Key design decisions

Artifact service resolution (builder path)

  1. Explicit .artifactService(...) — used as-is
  2. .withGcsArtifacts("bucket") — creates GcsArtifactService
  3. gcs.adk.bucket.name in properties — creates GcsArtifactService
  4. Nothing configured — defaults to InMemoryArtifactService (zero-config for text agents)

Legacy constructors — deprecated, not removed

The three existing constructors are marked @Deprecated with @deprecated Use {@link #newBuilder()} javadoc, consistent with how Runner deprecated its own constructors. The @SuppressWarnings("deprecation") annotations areplaced correctly:

  • One-arg / two-arg constructors: suppress warning for delegating to the deprecated three-arg via
  • Three-arg constructor: suppress warning for calling the deprecated Runner(BaseAgent, String, BaseArtifactService, ...) super constructor

The legacy constructors no longer throw when no GCS bucket is configured — they fall back to InMemoryArtifactService and emit a logger.warn(...) so operators are aware that artifacts will be ephemeral. This is a deliberate behaviour change from the previous fail-fast approach.

  • FirestoreProperties: property key renamed from firebase.root.collection.name to firestore.root.collection.name. The old key is still read as a fallback for backward compatibility. getFirebaseRootCollectionName() is retained but marked @deprecated.

Testing

  • 99 tests, 0 failures (mvn -pl contrib/firestore-session-service test)
  • Branch coverage: 89% — new tests targeting previously uncovered branches across all four packages in this module
  • Checkstyle : 0 violations
  • Format drift check (git diff --exit-code after build): clean

Documentation

contrib/firestore-session-service/README.md updated with:

  • Quick Start — minimal 15-line runnable snippet (no GCS, no properties file)
  • Example 1 — conversational agent with explicit InMemoryArtifactService
  • Example 2 — agent with GCS artifact storage
  • Builder API reference table — all builder methods with descriptions
  • Legacy constructor migration guide — before/after showing the deprecation path
  • Optional configuration — adk-firestore.properties keys

Added unit test for all the incremental changes and here is the test coverage snapshot.

image

Testing Plan

Ran mvn -pl contrib/firestore-session-service test (with JaCoCo report generation):

Tests run: 99, Failures: 0, Errors: 0, Skipped: 0

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Please include a summary of passed java test results.

image

Checklist

  • I have read the CONTRIBUTING.md document.
  • My pull request contains a single commit.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

@mohan-ganesh
mohan-ganesh force-pushed the firestore-builder-pattern branch 2 times, most recently from 9b459ba to b6b4d76 Compare November 29, 2026 23:26
@mohan-ganesh
mohan-ganesh force-pushed the firestore-builder-pattern branch from b6b4d76 to 395f3b0 Compare November 30, 2026 15:56
- Add FirestoreDatabaseRunner.newBuilder() and create(...) factory methods,
  mirroring the Runner.builder() pattern already established in core ADK
- Deprecate legacy constructors (@deprecated + @SuppressWarnings placed to
  match how Runner deprecated its own constructors)
- Default to InMemoryArtifactService with logger.warn when no GCS bucket is
  configured, replacing the previous startup RuntimeException
- Rename property key firebase->firestore with legacy fallback
- Improve branch coverage 83%->89% with 99 tests passing
- Update README with Quick Start, builder API reference, and migration guide
@mohan-ganesh
mohan-ganesh force-pushed the firestore-builder-pattern branch from 395f3b0 to 5cf5c3a Compare November 30, 2026 22:57
@mohan-ganesh

Copy link
Copy Markdown
Contributor Author

Hey @glaforge @hemasekhar-p I have had PR#1957 open (adds a builder API to FirestoreDatabaseRunner, mirroring the pattern from Runner.builder()). I would appreciate your help getting the right reviewer's attention. Thanks

@hemasekhar-p hemasekhar-p self-assigned this Dec 3, 2026
@hemasekhar-p

Copy link
Copy Markdown
Contributor

Hi @mohan-ganesh, We greatly appreciate your contribution and the effort you put into this pull request. It is currently under review by our team. We will notify you if any additional details are needed.

@mohan-ganesh
mohan-ganesh force-pushed the firestore-builder-pattern branch 2 times, most recently from fd27da8 to 5cf5c3a Compare December 4, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants