Google Cloud Storage Service

Purpose

The Google Cloud Storage (GCS) Service provides a scalable, durable, and versioned backend implementation of the artifact storage interface within the broader Artifact Management topic. It addresses the need to persist and retrieve artifacts—binary blobs or files—across sessions and users using Google Cloud's object storage infrastructure. Unlike the in-memory backend, which is ephemeral and suitable for testing, the GCS Service enables persistent, multi-versioned artifact storage with scoped naming conventions that organize artifacts by application, user, session, and filename.

This subtopic ensures that artifacts are reliably stored with explicit versioning, allowing agents and workflows to load specific or the latest versions, list available artifacts, and delete them either individually or in bulk. The versioning and naming semantics are critical for maintaining data integrity and enabling multi-user, multi-session support within the system.

Functionality

Scoped Naming and Versioning

Artifacts are stored in GCS buckets using a hierarchical naming convention that scopes blobs by:

The naming logic distinguishes between session-scoped and user-scoped artifacts. For example:

This ensures that user-global artifacts are separated from session-specific ones, supporting flexible artifact lifecycles.

Version Management

Core Methods

Client Abstraction and Testing

The service uses interface abstractions (gcsClient, gcsBucket, gcsObject, etc.) to wrap the real GCS client, enabling mocking for unit tests. The gcs_test.go file demonstrates an in-memory fake client implementation that mimics the GCS interfaces, supporting thorough testing without external dependencies.

Example snippet showing version-aware save logic:

response, err := s.versions(ctx, &artifact.VersionsRequest{
    AppName: req.AppName, UserID: req.UserID, SessionID: req.SessionID, FileName: req.FileName,
})
nextVersion := int64(1)
if len(response.Versions) > 0 {
    nextVersion = slices.Max(response.Versions) + 1
}
blobName := buildBlobName(appName, userID, sessionID, fileName, nextVersion)
writer := s.bucket.object(blobName).newWriter(ctx)
// Write data...

This snippet highlights how the service determines the next version and writes a new artifact blob.

Integration

The GCS Service implements the artifact.Service interface defined in the Artifact Management topic, seamlessly substituting or complementing the in-memory backend. Agents, tools, and session components interact with this service for artifact persistence when durable storage is required.

By enforcing scoped naming and versioning, the GCS Service supports multi-user, multi-session workflows, enabling agents to reliably load the correct artifact versions for their context. It integrates with tooling such as the LoadArtifactsTool (referenced in the project overview) that dynamically injects artifact content into LLM prompts.

Testing and development workflows benefit from the mocked client abstraction, ensuring reliability without requiring actual GCS access during local builds or CI runs.

Diagram

flowchart TD
UserAgent -->|Save Artifact| GCSService[Google Cloud Storage Service]
GCSService --> GCSBucket[GCS Bucket]
GCSBucket --> GCSObject[Blob Object with Version]
UserAgent -->|Load Artifact| GCSService
GCSService -->|List / Versions| GCSBucket
GCSService -->|Delete Artifact| GCSBucket
Note[Blob Naming: app/user/session/filename/version]
GCSService --- Note

This flowchart illustrates the interaction between user agents and the GCS Service, showing how artifact save, load, list, and delete operations map to the underlying GCS bucket and versioned blob objects with scoped naming conventions.