adk-artifact
Binary artifact storage for Rust Agent Development Kit (ADK-Rust) agents.
Stability: Stable — follows semantic versioning, so breaking changes wait for the next major release. See STABILITY.md.
Overview
adk-artifact provides versioned binary data storage for the Rust Agent Development Kit (ADK-Rust). Artifacts are useful for storing images, documents, audio, and other binary data that agents produce or consume.
Three storage backends are included:
| Backend | Type | Persistence | Use case |
|---|---|---|---|
InMemoryArtifactService |
In-memory HashMap |
Process lifetime only | Development, testing |
FileArtifactService |
Local filesystem | Durable | Single-node production, local dev |
GcsArtifactService (feature gcs) |
Google Cloud Storage | Durable | Deployed agents, Gemini Enterprise |
All implement the ArtifactService trait, so you can swap backends without changing application code.
The GCS backend keeps byte-for-byte blob-name parity with adk-python's GcsArtifactService, so Rust agents, Python agents, and the Gemini Enterprise console read the same objects:
- Session-scoped:
{app_name}/{user_id}/{session_id}/{filename}/{version} - User-namespaced (filename starts with
user:):{app_name}/{user_id}/user/{filename}/{version}
Auto-assigned versions start at 0 (matching adk-python; the in-memory and file backends start at 1). Authentication uses Application Default Credentials via google-cloud-auth.
Important: save and load must resolve the same
app_name— the engine ID when deployed. adk-python had a save/load path mismatch (googleapis/python-aiplatform#6521); this implementation takesapp_nameverbatim from each request and never rewrites it.
[]
= { = "3.0.0", = ["gcs"] }
# or via the umbrella crate:
= { = "3.0.0", = ["minimal", "gcs-artifacts"] }
use GcsArtifactService;
Installation
[]
= "3.0.0"
Or via the umbrella crate:
[]
= { = "3.0.0", = ["artifacts"] }
Quick Start
use ;
use Part;
async
Storage Backends
InMemoryArtifactService
Stores artifacts in a thread-safe HashMap behind RwLock. Data is lost when the process exits.
use InMemoryArtifactService;
FileArtifactService
Persists artifacts to the local filesystem. Each version is stored as a JSON-serialized file under a directory hierarchy:
<base_dir>/<app_name>/<user_id>/<session_id>/<name>/v1.json
v2.json
<base_dir>/<app_name>/<user_id>/user/<name>/v1.json (user: names)
<name> is the artifact name with %, :, the other characters Windows forbids in file names, and the second _ of every __ written as %XX escapes, so a:b and a__b are stored apart. A save writes the version to a temporary file, flushes it, and links it into place without replacing an existing file, so a crash never leaves a partial version. Artifacts written in the earlier layout (: stored as __, user scope under _user_scoped_) stay loadable.
use FileArtifactService;
FileArtifactService includes a health_check() method that verifies the base directory is writable.
ArtifactService Trait
All backends implement the full ArtifactService trait:
| Method | Description |
|---|---|
save(SaveRequest) |
Store an artifact. Auto-increments version when version: None. |
load(LoadRequest) |
Retrieve an artifact. Loads latest version when version: None. |
delete(DeleteRequest) |
Delete a specific version, or all versions when version: None. |
list(ListRequest) |
List all artifact filenames in a session (includes user-scoped artifacts). |
versions(VersionsRequest) |
List all available version numbers for a specific artifact. |
health_check() |
Verify backend connectivity. Default impl returns Ok(()). |
Versioning
Every artifact supports multiple versions. When saving with version: None, the version auto-increments starting from 1. You can also write to an explicit version that does not exist yet:
use ;
use ;
async
Every backend keeps the same contract:
| Rule | Behaviour |
|---|---|
| Versions are immutable | A save never replaces a stored version; an explicit existing version fails with ErrorCategory::Conflict (artifact.version_exists). |
| Concurrent saves each get a version | Simultaneous saves without a version return distinct versions, and all are stored. |
| Distinct names are distinct artifacts | No two file names share storage. |
user is not a session id |
It names the user scope; every operation rejects it with ErrorCategory::InvalidInput (artifact.reserved_session_id). |
Scoping
Artifacts are scoped by three dimensions: app_name, user_id, and session_id. This means two sessions for the same user can each have a report.pdf without conflict.
User-Scoped Artifacts
Prefix a filename with user: to make it accessible across all sessions for that user:
use ;
use Part;
async
Internally, user-scoped artifacts are stored under the reserved session segment user (USER_SCOPE_SESSION_ID) in every backend, so they're visible regardless of which session ID is used. Because the segment is reserved, every backend rejects user as a session id.
Deleting Artifacts
use ;
async
Deleting a non-existent artifact or version is a no-op (no error returned).
Deleting and Listing a User's Artifacts
delete_user(app, user) deletes every version of every artifact of the user in the app — in
every session and in the user: scope — and returns how many versions it deleted;
list_user(app, user) lists those versions with their MIME type and size. The in-memory, file,
and GCS backends implement both; the defaults return subject.unsupported.
ArtifactSubjectData adapts any ArtifactService to adk_core::subject::SubjectDataStore
for SubjectRights. A GCS bucket with object versioning or soft delete keeps noncurrent copies
for its retention period; declare it with
ArtifactSubjectData::with_support(StoreSupport::Eventual { within }).
ScopedArtifacts
ScopedArtifacts wraps an ArtifactService and implements the simpler adk_core::Artifacts trait by automatically injecting app_name, user_id, and session_id into every request. This is the interface agents use at runtime.
use Arc;
use ;
use ;
async
File Name Validation
Every backend validates artifact file names to prevent path traversal:
| Backend | Rejected names |
|---|---|
InMemoryArtifactService, FileArtifactService |
Empty; containing / or \; equal to . or ..; containing .. anywhere |
GcsArtifactService |
Empty; starting or ending with /; containing \; with an empty, ., or .. path component |
FileArtifactService also rejects an app name, user id, or session id that is empty or contains a separator or traversal pattern.
Use with LoadArtifactsTool
Artifacts integrate with agents via LoadArtifactsTool from adk-tool:
use Arc;
use ;
use ;
use LoadArtifactsTool;
The LLM can then call this tool to load artifacts by name into the conversation.
Changes in 3.0
| Change | Migration |
|---|---|
A save naming an existing version fails with artifact.version_exists (Conflict) on every backend |
Save with version: None to append |
The session id user (USER_SCOPE_SESSION_ID) is rejected with artifact.reserved_session_id |
Use another session id; artifacts saved earlier under session user are no longer reachable |
FileArtifactService encodes names injectively and stores user-scoped artifacts under {app}/{user}/user/ |
Tools reading the directory tree directly need the new paths; the earlier layout stays readable |
| Concurrent saves each keep their own version; file writes are crash-safe | — |
adk-gcp, google-cloud-auth, reqwest, serde, and tracing are no longer implicit features |
Enable gcs |
See the 2.x to 3.0 migration guide and the changelog for the full list.
Related Crates
License
Apache-2.0
Part of ADK-Rust
This crate is part of the ADK-Rust framework for building AI agents in Rust.