feat: Add artifact metadata support and a new sample for context offloading

Enhanced `save_artifact` in `callback_context.py` to accept `custom_metadata` and added `get_artifact_version` to retrieve artifact details.

Introduced a new sample, `context_offloading_with_artifact`, demonstrating how to use ADK artifacts to offload large data from the LLM context. The sample includes:
-   `QueryLargeDataTool`: Generates mock sales reports, saves them as artifacts with custom metadata, and injects the artifact content into the LLM request immediately after creation.
-   `CustomLoadArtifactsTool`: Provides summaries of available artifacts to the LLM based on metadata and loads artifact content on demand when `load_artifacts` is called.

Co-authored-by: Hangfei Lin <hangfei@google.com>
PiperOrigin-RevId: 830592786
This commit is contained in:
Hangfei Lin
2025-11-10 14:10:10 -08:00
committed by Copybara-Service
parent 74959414d8
commit 2b0f953255
5 changed files with 365 additions and 1 deletions
@@ -296,6 +296,7 @@ class TestCallbackContext:
session_id="test-session-id",
filename="test_file.txt",
artifact=test_artifact,
custom_metadata=None,
)
assert version == 1