Skip to content
GkPy

Memory and Artifacts

Long-term memory (InMemory, Vertex Memory Bank, Vertex RAG) and artifact services (file, GCS, in-memory).

Verified against google-adk 2.13.0 (google/adk/memory/, google/adk/artifacts/), checked 2026-11-19. The examples were run against a stub model that stands in for Gemini; the Vertex AI and Cloud Storage examples need a Google Cloud project and were not run. MongoDbMemoryService was checked against its signature only, not a live MongoDB.

Both memory and artifacts are per-runner services: you pass an instance when constructing the Runner (or rely on InMemoryRunner’s built-in in-memory pair). Memory is for searchable long-term context across sessions; artifacts are versioned file storage tied to sessions or users.

from google.adk.agents import LlmAgent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.adk.memory import InMemoryMemoryService
from google.adk.artifacts import FileArtifactService
from google.adk.tools import load_memory, load_artifacts
agent = LlmAgent(
name="librarian",
model="gemini-3.8-flash",
instruction="Use load_memory for recall and load_artifacts for files.",
tools=[load_memory, load_artifacts],
)
runner = Runner(
app_name="demo",
agent=agent,
session_service=InMemorySessionService(),
memory_service=InMemoryMemoryService(),
artifact_service=FileArtifactService(root_dir="./artifacts"),
)

BaseMemoryService (memory/base_memory_service.py) defines the following operations:

MethodPurpose
add_session_to_memory(session)Ingest the full session’s events
add_events_to_memory(*, app_name, user_id, events, session_id=None, custom_metadata=None)Incremental add — last turn only, for example
add_memory(*, app_name, user_id, memories, custom_metadata=None)Write explicit MemoryEntry items directly
search_memory(*, app_name, user_id, query)Semantic / keyword search — returns SearchMemoryResponse
delete_memory(*, app_name, user_id, memory_id=None)Delete one memory by the MemoryEntry.id that search_memory returned (2.13.0). Also available as delete_memory(memory_id) on ToolContext and CallbackContext

Not every service implements every method; the unsupported ones raise NotImplementedError. delete_memory is implemented only by InMemoryMemoryService in 2.13.0; the SQLite, MongoDB, Memory Bank and RAG services raise NotImplementedError for it.

Serviceadd_session_to_memoryadd_events_to_memoryadd_memorySearch
InMemoryMemoryServiceyesyesnoword overlap
SqliteMemoryServiceyesyesnoSQLite full-text search (FTS5) when available, else word matching
MongoDbMemoryService (experimental, 2.13.0)yesyesnoKeyword match, no embedding model or vector index
VertexAiMemoryBankServiceyesyesyessemantic, server-side
VertexAiRagMemoryServiceyesnonovector similarity
ServiceStorageSearchExtra setup
InMemoryMemoryService()Python dict, keyed by (app_name, user_id)Case-insensitive word overlapNone
SqliteMemoryService(db_path, *, fts="auto", max_event_bytes=262144, max_results=50)Local SQLite file (2.11.0)Full-text searchNone; call close() on shutdown
MongoDbMemoryService(*, database_name, connection_string=None, mongo_client=None, memories_collection="memories", stop_words=None, max_results=50, ensure_indexes=True)MongoDB collection (added in 2.13.0, experimental)Keyword match on extracted keywordspip install "google-adk[mongodb]"; works on any MongoDB deployment, and creates an app_user_keywords index on first use unless ensure_indexes=False; call close() on shutdown
VertexAiMemoryBankService(project, location, agent_engine_id, *, express_mode_api_key=None, credentials=None)GCP Agent Engine Memory BankSemantic (Vertex-side)Enable Agent Engine in your GCP project; pass the engine’s numeric ID (not the full resource path)
VertexAiRagMemoryService(rag_corpus, similarity_top_k=None, vector_distance_threshold=10)Vertex AI RAG corpusVector similarityCreate a RAG corpus in advance; format projects/.../ragCorpora/{id} or just the id

VertexAiRagMemoryService is imported lazily (memory/__init__.py). It uses the agentplatform client that ships with the google-cloud-aiplatform version pinned by pip install "google-adk[gcp]", not the deprecated vertexai.preview.rag. Its full signature is VertexAiRagMemoryService(rag_corpus=None, similarity_top_k=None, vector_distance_threshold=10, project=None, location=None); project/location fall back to GOOGLE_CLOUD_PROJECT/GOOGLE_CLOUD_LOCATION, or are parsed from a full corpus resource name. vector_distance_threshold is a maximum distance, so lower is stricter. Create the corpus with agentplatform.Client(project=..., location=...).rag.create_corpus(rag_corpus=agentplatform.types.RagCorpus(display_name="agent-memory")) and pass its name.

Two built-in tools consume the memory service:

  • load_memory — a regular FunctionTool. The LLM decides when to call it and passes a query string; results come back as a list of MemoryEntry.
  • preload_memory — invisible to the model. Runs automatically each turn, prepends the top-k matches to the system context. Good when the model would forget to call load_memory on its own.
from google.adk.tools import load_memory, preload_memory
agent = LlmAgent(
name="remembering",
model="gemini-3.8-flash",
tools=[load_memory, preload_memory], # both can be used together
)

preload_memory (PreloadMemoryTool) runs automatically before each LLM call (not invoked by the model, and absent from the function declarations, so don’t mention it in instructions as a callable tool). It searches memory with the text of the current user message and, if anything matches, inserts a transient user-role block into that one request (it is never written to the session):

The following content is from your previous conversations with the user.
They may be useful for answering the user's current query.
<PAST_CONVERSATIONS>
Time: <timestamp> (only when the entry has one)
<author>: <text> (author prefix only when set)
</PAST_CONVERSATIONS>

Only text parts of memories are used, and a user message with no text (e.g. audio only) skips the search. It wraps ToolContext.search_memory() in a broad try/except — if no memory_service is configured or search fails, it logs a warning and silently returns. Safe to add without a memory service, but check your logs if recall quietly stops working.

load_memory is a callable tool the model invokes explicitly. It calls ToolContext.search_memory() directly, which raises ValueError('Memory service is not available.') when the Runner has no memory_service. The model receives a tool error instead of an empty result. Always configure a memory_service on the Runner before using load_memory.

Memory is not automatically populated — you decide when to ingest a session:

# End of a chat: add the whole session to memory for future recall
await runner.memory_service.add_session_to_memory(session)
# Or just the latest turn
await runner.memory_service.add_events_to_memory(
app_name="demo",
user_id="u1",
events=session.events[-2:],
)
# Or explicit facts (VertexAiMemoryBankService only; the in-memory and SQLite
# services raise NotImplementedError). content must be a types.Content.
from google.adk.memory.memory_entry import MemoryEntry
from google.genai import types
await runner.memory_service.add_memory(
app_name="demo",
user_id="u1",
memories=[MemoryEntry(content=types.Content(
role="user",
parts=[types.Part(text="User prefers metric units.")],
))],
)

Ingest once per conversation, not per turn. Runner never ingests automatically, and an after_agent_callback fires after every turn. With VertexAiRagMemoryService this matters most: each add_session_to_memory() uploads the whole transcript as a new RAG file, so per-turn calls fill the corpus with duplicates. Call it from whatever ends a conversation in your app (an explicit “end chat”, an idle timeout).

VertexAiMemoryBankService.add_events_to_memory uses memories.ingest_events by default; it switches to memories.generate if custom_metadata includes a key only that API supports, such as ttl, revision_ttl, metadata or wait_for_completion.

Persistent local memory: SqliteMemoryService

Section titled “Persistent local memory: SqliteMemoryService”

For a single-process deployment or local development that should remember across restarts, SqliteMemoryService (2.11.0) keeps memories in a SQLite file. The CLI’s --memory_service_uri sqlite:///memory.db selects it too.

import asyncio
from google.adk.agents import LlmAgent
from google.adk.memory import SqliteMemoryService
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.adk.tools import load_memory
agent = LlmAgent(
name="assistant",
model="gemini-3.8-flash",
instruction="Use load_memory when the user refers to earlier conversations.",
tools=[load_memory],
)
async def main():
memory = SqliteMemoryService("memory.db") # full-text search when SQLite has FTS5
sessions = InMemorySessionService()
runner = Runner(app_name="mem_app", agent=agent, session_service=sessions,
memory_service=memory, auto_create_session=True)
await runner.run_debug("Our office moves to Leeds in March.", user_id="u1", session_id="s1", quiet=True)
await memory.add_session_to_memory(
await sessions.get_session(app_name="mem_app", user_id="u1", session_id="s1")
)
found = await memory.search_memory(app_name="mem_app", user_id="u1", query="office move")
for entry in found.memories:
print(entry.author, "->", entry.content.parts[0].text)
await memory.close()
asyncio.run(main())

Each MemoryEntry returned by search_memory carries an id. Pass it to delete_memory to remove that memory (2.13.0). This runs against InMemoryMemoryService; other services raise NotImplementedError.

import asyncio
from google.adk.events import Event
from google.adk.memory import InMemoryMemoryService
from google.adk.sessions import InMemorySessionService
from google.genai import types
async def main():
sessions = InMemorySessionService()
memory = InMemoryMemoryService()
session = await sessions.create_session(app_name="app", user_id="u1")
await sessions.append_event(session, Event(
author="user",
content=types.Content(role="user", parts=[types.Part(text="The office moves to Leeds in March.")]),
))
session = await sessions.get_session(app_name="app", user_id="u1", session_id=session.id)
await memory.add_session_to_memory(session)
found = await memory.search_memory(app_name="app", user_id="u1", query="office")
await memory.delete_memory(app_name="app", user_id="u1", memory_id=found.memories[0].id)
found = await memory.search_memory(app_name="app", user_id="u1", query="office")
print(len(found.memories)) # 0
asyncio.run(main())
from google.adk.memory.memory_entry import MemoryEntry
from google.genai import types
entry = MemoryEntry(
content=types.Content(
role="user",
parts=[types.Part(text="User's favourite language is Rust.")],
),
timestamp="2025-05-12T00:00:00Z", # ISO 8601 string, optional
custom_metadata={"source": "self-report"},
)

search_memory returns a SearchMemoryResponse whose memories: list[MemoryEntry] is what the model sees via load_memory.

BaseArtifactService (artifacts/base_artifact_service.py) abstracts versioned file storage. Key methods:

MethodPurpose
save_artifact(*, app_name, user_id, filename, artifact, session_id=None, custom_metadata=None) -> intSave a new version. Returns the 0-based revision id
load_artifact(*, app_name, user_id, filename, session_id=None, version=None) -> types.PartLoad latest (or specific version)
list_artifact_keys(*, app_name, user_id, session_id=None) -> list[str]List filenames in scope
delete_artifact(*, app_name, user_id, filename, session_id=None)Remove an artifact
list_versions(*, app_name, user_id, filename, session_id=None) -> list[int]Version numbers only
list_artifact_versions(*, app_name, user_id, filename, session_id=None) -> list[ArtifactVersion]Version metadata (uri, mime, timestamp)
get_artifact_version(*, app_name, user_id, filename, session_id=None, version=None) -> Optional[ArtifactVersion]Metadata for a single version
  • session_id=<id> — session-scoped artifact.
  • filename="user:foo.pdf" — user-scoped: visible from every session of that user. This is the portable way to share a file across sessions.
  • session_id=None without the user: prefix behaves differently per service: FileArtifactService treats it as user-scoped, while InMemoryArtifactService and GcsArtifactService raise InputValidationError: Session ID must be provided for session-scoped artifacts.
ServiceStorageNotes
InMemoryArtifactService()Python dict; keeps full blobs in memoryDev/testing
FileArtifactService(root_dir)Local filesystem under root_dir/Versions stored as apps/<app>/users/<user>/sessions/<session>/artifacts/<filename>/versions/<N>/<filename> (user-scoped: apps/<app>/users/<user>/artifacts/...), with a metadata.json beside each. No locking — concurrent saves to the same artifact can race; use GCS or a single-writer process in production
GcsArtifactService(bucket_name, **kwargs)Google Cloud Storage bucketkwargs forwarded to google.cloud.storage.Client
from google.adk.artifacts import FileArtifactService, GcsArtifactService
# Local
local = FileArtifactService(root_dir="/var/adk/artifacts")
# GCS (defaults to ADC credentials)
gcs = GcsArtifactService(bucket_name="my-adk-artifacts")
# GCS with explicit project
gcs_proj = GcsArtifactService(bucket_name="my-adk-artifacts", project="my-gcp-project")
# GCS with service account key file
from google.oauth2 import service_account
sa_creds = service_account.Credentials.from_service_account_file(
"sa.json",
scopes=["https://www.googleapis.com/auth/cloud-platform"],
)
gcs_sa = GcsArtifactService("my-adk-artifacts", credentials=sa_creds)

GCS blob path structure (verified gcs_artifact_service.py:_get_blob_name):

ScopeHow to triggerBlob path
Session-scopedsession_id=<id>, filename without user: prefix{app_name}/{user_id}/{session_id}/{filename}/{version}
User-scopedfilename="user:foo" prefix — session_id is ignored{app_name}/{user_id}/user/{filename}/{version} (the user: prefix stays in filename, e.g. my_app/u1/user/user:profile.json/0)

GCS note: GcsArtifactService raises InputValidationError when session_id=None and the filename does not start with "user:". Use the "user:" filename prefix (not session_id=None alone) for cross-session user storage.

Version numbers start at 0 and increment by 1 on each save. Saves never overwrite: each upload is a create-only write (if_generation_match=0), so two concurrent saves of the same file can’t clobber each other; the loser takes the next number, up to 10 attempts. delete_artifact removes every version (there’s no single-version delete). All GCS calls run in asyncio.to_thread, and custom_metadata values are stored as strings.

To hand a file to a browser, GcsArtifactService (not the base class) has two URL helpers, both returning None if the artifact doesn’t exist:

import datetime
url = await gcs.get_signed_url(
app_name="file_app", user_id="u1", session_id="s1", filename="report.pdf",
expiration=datetime.timedelta(minutes=15), # default 1 hour; also datetime or epoch seconds
) # method="GET", signing_version="v2"|"v4", extra kwargs go to Blob.generate_signed_url
auth_url = await gcs.get_authenticated_url(
app_name="file_app", user_id="u1", session_id="s1", filename="report.pdf",
) # https://storage.cloud.google.com/...; the viewer needs a Google account with read access

Blob.generate_signed_url needs credentials that can sign: a service-account key, or (with token-only ADC on Cloud Run/GKE) pass service_account_email= and access_token= through the extra kwargs.

GCS IAM requirements: storage.objects.create (save), storage.objects.get (load), storage.objects.list (list/versions), storage.objects.delete (delete). The roles/storage.objectAdmin role covers all four.

from google.genai import types
from google.adk.tools import FunctionTool
async def make_report(topic: str, tool_context) -> dict:
pdf_bytes = render_pdf(topic)
part = types.Part(inline_data=types.Blob(mime_type="application/pdf", data=pdf_bytes))
version = await tool_context.save_artifact(filename=f"{topic}.pdf", artifact=part)
return {"saved": True, "version": version}
report_tool = FunctionTool(func=make_report)

Inside a callback/tool:

  • tool_context.save_artifact(filename, artifact, custom_metadata=None) — returns the new version int.
  • tool_context.load_artifact(filename, version=None) — returns types.Part or None.
  • tool_context.list_artifacts() — returns a list of filenames in scope.
  • tool_context.get_artifact_version(filename, version=None) — returns metadata only.

load_artifacts is a ready-made LoadArtifactsTool instance the model can call to fetch an artifact by name and have its content injected as a types.Part. Include it in tools=[load_artifacts] when the agent should reference past files.

# The model as defined in google.adk.artifacts.base_artifact_service
from typing import Any, Optional
from pydantic import BaseModel
class ArtifactVersion(BaseModel):
version: int
canonical_uri: str
custom_metadata: dict[str, Any]
create_time: float # unix seconds
mime_type: Optional[str]

canonical_uri is the back-end-specific reference (file path, gs://..., in-memory key). Use list_artifact_versions to get metadata without downloading blobs.

Append a plugin that overrides after_run_callback and calls memory_service.add_session_to_memory(session). All future chats for the same user gain recall.

Use custom_metadata={"ttl": ...} on add_events_to_memory with VertexAiMemoryBankService to auto-expire short-lived memories (e.g. session-specific preferences that shouldn’t leak to future users).

Save with filename="user:history.json". The artifact is available to every future session of the same user.

Each run saves a new version of report.pdf. The UI lists list_artifact_versions(...) with timestamps so a reviewer can diff outputs turn-by-turn.

VertexAiRagMemoryService(rag_corpus="...") plus load_memory in tools=. The service writes to the corpus via add_session_to_memory() (call it once when a session ends — see Writing to memory). Static content (files, web pages, BigQuery) can also be loaded via the Agent Platform corpus management API. add_events_to_memory() is not supported and raises NotImplementedError.

This shows the full lifecycle: chat, ingest the session, start a new session, and recall what was said.

import asyncio
from google.genai import types
from google.adk.agents import LlmAgent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.adk.memory import InMemoryMemoryService
from google.adk.apps import App
from google.adk.tools import load_memory
APP_NAME = "memory_demo"
USER_ID = "alice"
agent = LlmAgent(
name="assistant",
model="gemini-3.8-flash",
instruction=(
"You are a helpful assistant. Use load_memory to recall "
"things the user told you in previous conversations."
),
tools=[load_memory],
)
async def main():
session_service = InMemorySessionService()
memory_service = InMemoryMemoryService()
app = App(name=APP_NAME, root_agent=agent)
runner = Runner(app=app, session_service=session_service, memory_service=memory_service)
# --- Session 1: tell the agent a fact ---
s1 = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID)
async for event in runner.run_async(
user_id=USER_ID, session_id=s1.id,
new_message=types.Content(role="user", parts=[types.Part(text="My favourite programming language is Rust.")]),
):
if event.is_final_response():
print("Session 1:", event.content.parts[0].text)
# Ingest the session into memory so future sessions can recall it
session_1 = await session_service.get_session(
app_name=APP_NAME, user_id=USER_ID, session_id=s1.id
)
await memory_service.add_session_to_memory(session_1)
# --- Session 2: recall the fact ---
s2 = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID)
async for event in runner.run_async(
user_id=USER_ID, session_id=s2.id,
new_message=types.Content(role="user", parts=[types.Part(text="What is my favourite programming language?")]),
):
if event.is_final_response():
print("Session 2:", event.content.parts[0].text)
# → "Your favourite programming language is Rust."
asyncio.run(main())

Example B — saving and retrieving artifacts across an agent turn

Section titled “Example B — saving and retrieving artifacts across an agent turn”
import asyncio
from google.genai import types
from google.adk.agents import LlmAgent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.adk.artifacts import FileArtifactService
from google.adk.apps import App
from google.adk.tools import FunctionTool, load_artifacts
from google.adk.tools.tool_context import ToolContext
APP_NAME = "artifact_demo"
USER_ID = "bob"
async def generate_report(topic: str, tool_context: ToolContext) -> dict:
"""Generates a text report and saves it as an artifact."""
content = f"# Report: {topic}\n\nThis is an auto-generated report about {topic}."
part = types.Part(
inline_data=types.Blob(
mime_type="text/plain",
data=content.encode(),
)
)
version = await tool_context.save_artifact(
filename=f"{topic.lower().replace(' ', '_')}_report.txt",
artifact=part,
)
return {"saved": True, "filename": f"{topic.lower().replace(' ', '_')}_report.txt", "version": version}
report_tool = FunctionTool(func=generate_report)
agent = LlmAgent(
name="report_agent",
model="gemini-3.8-flash",
instruction=(
"Generate reports when asked. Use generate_report to save them. "
"Use load_artifacts to retrieve them when asked."
),
tools=[report_tool, load_artifacts],
)
async def main():
session_service = InMemorySessionService()
artifact_service = FileArtifactService(root_dir="/tmp/adk_artifacts")
app = App(name=APP_NAME, root_agent=agent)
runner = Runner(app=app, session_service=session_service, artifact_service=artifact_service)
session = await session_service.create_session(
app_name=APP_NAME, user_id=USER_ID
)
# Turn 1: generate and save a report
async for event in runner.run_async(
user_id=USER_ID, session_id=session.id,
new_message=types.Content(role="user", parts=[types.Part(text="Generate a report about climate change.")]),
):
if event.is_final_response():
print("Turn 1:", event.content.parts[0].text)
# Turn 2: retrieve the report by asking the agent to load it
async for event in runner.run_async(
user_id=USER_ID, session_id=session.id,
new_message=types.Content(role="user", parts=[types.Part(text="Show me the climate change report you generated.")]),
):
if event.is_final_response():
print("Turn 2:", event.content.parts[0].text)
asyncio.run(main())

Example C — VertexAiMemoryBankService for semantic recall

Section titled “Example C — VertexAiMemoryBankService for semantic recall”
import asyncio
from google.genai import types
from google.adk.agents import LlmAgent
from google.adk.runners import Runner
from google.adk.sessions import InMemorySessionService
from google.adk.memory import VertexAiMemoryBankService
from google.adk.apps import App
from google.adk.tools import load_memory, preload_memory
# Replace with your GCP project, location, and Agent Engine ID (numeric string)
PROJECT = "my-gcp-project"
LOCATION = "us-central1"
AGENT_ENGINE_ID = "1234567890" # Numeric ID, not the full resource path
APP_NAME = "vertex_memory_demo"
USER_ID = "charlie"
agent = LlmAgent(
name="vertex_assistant",
model="gemini-3.8-flash",
instruction=(
"You are a helpful assistant. Memories from past conversations "
"are automatically available to you via preload_memory. "
"Use load_memory to search for specific information."
),
# preload_memory runs automatically every turn — model sees memories without calling a tool
# load_memory lets the model explicitly query memories when needed
tools=[preload_memory, load_memory],
)
async def main():
memory_service = VertexAiMemoryBankService(
project=PROJECT,
location=LOCATION,
agent_engine_id=AGENT_ENGINE_ID,
# Optional: express_mode_api_key="..." for express mode
)
session_service = InMemorySessionService()
app = App(name=APP_NAME, root_agent=agent)
runner = Runner(app=app, session_service=session_service, memory_service=memory_service)
# Session 1 — establish user preferences
s1 = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID)
async for event in runner.run_async(
user_id=USER_ID, session_id=s1.id,
new_message=types.Content(role="user", parts=[types.Part(text="I'm a vegetarian and allergic to nuts. Keep this in mind.")]),
):
if event.is_final_response():
print("S1:", event.content.parts[0].text)
# Ingest into Vertex AI Memory Bank for semantic retrieval
s1_obj = await session_service.get_session(
app_name=APP_NAME, user_id=USER_ID, session_id=s1.id
)
await memory_service.add_session_to_memory(s1_obj)
# Session 2 — the agent recalls dietary requirements via semantic search
s2 = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID)
async for event in runner.run_async(
user_id=USER_ID, session_id=s2.id,
new_message=types.Content(role="user", parts=[types.Part(text="Suggest a recipe for dinner tonight.")]),
):
if event.is_final_response():
# Agent should suggest a vegetarian, nut-free recipe
print("S2:", event.content.parts[0].text)
asyncio.run(main())

Example D — versioned user-scoped GCS artifacts

Section titled “Example D — versioned user-scoped GCS artifacts”
import asyncio
from google.genai import types
from google.adk.artifacts import GcsArtifactService
from google.adk.sessions import InMemorySessionService
APP_NAME = "gcs_demo"
USER_ID = "diana"
async def demo_gcs_artifacts():
artifact_service = GcsArtifactService(bucket_name="my-adk-artifacts")
session_service = InMemorySessionService()
session = await session_service.create_session(app_name=APP_NAME, user_id=USER_ID)
# Save version 0 — user-scoped (survives session deletion)
# Use the "user:" prefix to scope to user rather than session
v0 = await artifact_service.save_artifact(
app_name=APP_NAME,
user_id=USER_ID,
session_id=session.id,
filename="user:preferences.json",
artifact=types.Part(
inline_data=types.Blob(
mime_type="application/json",
data=b'{"theme": "dark", "language": "en"}',
)
),
)
print(f"Saved version {v0}") # → 0
# Save version 1 — updated preferences
v1 = await artifact_service.save_artifact(
app_name=APP_NAME,
user_id=USER_ID,
session_id=session.id,
filename="user:preferences.json",
artifact=types.Part(
inline_data=types.Blob(
mime_type="application/json",
data=b'{"theme": "light", "language": "fr"}',
)
),
)
print(f"Saved version {v1}") # → 1
# List all versions
versions = await artifact_service.list_artifact_versions(
app_name=APP_NAME,
user_id=USER_ID,
session_id=session.id,
filename="user:preferences.json",
)
for v in versions:
print(f"Version {v.version}: {v.canonical_uri} at {v.create_time}")
# Load a specific version
old_prefs = await artifact_service.load_artifact(
app_name=APP_NAME,
user_id=USER_ID,
session_id=session.id,
filename="user:preferences.json",
version=0,
)
print("Old prefs:", old_prefs.inline_data.data)
asyncio.run(demo_gcs_artifacts())
  • preload_memory silently no-ops when no memory_service is configured (catches all exceptions). load_memory raises ValueError('Memory service is not available.') — the model receives a tool error. Always wire a memory_service on the Runner before exposing load_memory to the model.
  • VertexAiMemoryBankService requires the numeric agent_engine_id ("456"), not the full resource path. The constructor warns if it detects a /.
  • SaveFilesAsArtifactsPlugin replaced the deprecated RunConfig.save_input_blobs_as_artifacts. Install the plugin on the App instead of toggling the flag.
  • Artifact save_artifact accepts a types.Part OR a plain dict (camelCase or snake_case); ensure_part normalises via Pydantic validation (base_artifact_service.py).
  • FileArtifactService creates the root directory lazily on first save; make sure the process has write permissions.
  • GcsArtifactService uses Application Default Credentials by default — on GKE/Cloud Run make sure the service account has storage.objects.create and storage.objects.get.
  • An artifact’s version starts at 0, not 1 (base_artifact_service.py).