
Artifacts: handling large binary content
When users upload non-text files (for example, a 30-page invoice PDF, a large image, or an audio recording), you should avoid embedding those large binaries directly into the session history or every model request. ADK solves this by storing such files as artifacts.- An artifact is a named, versioned file managed by the ADK Artifact Service.
- Files live in the Artifact Service (not in session history). Sessions reference artifacts when the model needs them.
- Artifacts can be scoped to a session or to a user, depending on naming and storage choices.
- Each save returns a version number instead of overwriting existing files.
save_artifact and passing a Part object that wraps the file bytes and MIME type. Example:
0 the first time you save "invoice.pdf", 1 the next time, etc.). This gives you immutable versions and simple change history.
Loading artifacts into a single turn
When the agent needs a file, ADK provides an artifact-loading tool that fetches the artifact and injects its contents into the model request for that single turn only. The loaded file is not appended to the persistent session history—if the model needs it again later, ADK loads it again. This prevents large binary data from inflating the conversation context or your billing.
Long-term memory across sessions
Session state and compaction handle short-term context, but when information must persist beyond a single conversation, use ADK’s Memory Service.- Use
add_session_to_memoryafter a conversation to extract and store important facts from the session. - In a future session, retrieve relevant facts with
search_memory. - You can let the model decide when to query memory (provide a memory tool) or have ADK preload memory results before the model receives the new message.
search_memory.

Quick reference: when to use each mechanism
Putting it together: session state and recent events are your short-term memory. Compaction keeps the conversation prompt from growing without bound. Artifacts keep large files outside the context until they’re needed. The Memory Service provides durable recall across conversations. Each mechanism addresses a different problem — use the right one for predictable costs, smaller prompts, and faster responses.

Keep large binary content out of session history by storing it as an artifact and loading it into the model request only when needed.