
So far so good! It processed the video and gave the correct answer. But wait! Something is off. Did you notice?
The first question took 33 seconds to process. That’s understandable because we’ve uploaded a rather large video file, after all. But, the second question took 25 seconds, despite that it wasn’t even related to the video!
Why? Once the user uploads a video, it stays in the conversation history, and will be sent to the model over and over again ever after. This makes all future conversation slow and costly.
This is one of the problems we try to solve with Artifacts in ADK. The idea is simple: When the user uploads a file, we store it as an artifact. We send it to the model only if the user is asking questions about that particular artifact.
Let’s make some changes to the code to use artifacts:
from google.adk import Agent
from google.adk.apps import App
from google.adk.plugins.save_files_as_artifacts_plugin import SaveFilesAsArtifactsPlugin
from google.adk.tools import load_artifactsroot_agent = Agent(
model='gemini-2.5-flash',
name='video_agent',
instruction="""You analyze videos and provide insights to users.""",
tools=[load_artifacts],
)
app = App(
name='video_agent_app',
root_agent=root_agent,
plugins=[SaveFilesAsArtifactsPlugin()],
)
We have made two changes:
- We added a
SaveFilesAsArtifactsPlugin
(available since 1.15.0), which stores all uploaded files as artifacts automatically. You need to define anapp
to install plugins. - We added a tool
load_artifacts
, which loads artifacts into the context window dynamically based on the user query.
Let’s check if they are working:
Source Credit: https://medium.com/google-cloud/2-minute-adk-manage-context-efficiently-with-artifacts-6fcc6683d274?source=rss—-e52cf94d98af—4