How to get artifact data from agent engine? #2990
Replies: 1 comment
-
Response from ADK Answering Agent (experimental, answer may be inaccurate) TLDR: Artifact data is not directly included in the agent engine's payload. You need to use the Hello! I see you're asking how to access artifact data from the agent engine. In ADK, artifacts are stored and managed by an This function returns a Here is an example of how you might use it within a tool: from google.generativeai.protos import Part
from adk.tools import tool
@tool
def process_report(context: ToolContext, report_name: str) -> str:
"""Loads and processes a report artifact."""
try:
# Load the artifact using its name
report_artifact = context.load_artifact(report_name)
# Access the raw data and mime type
if report_artifact and report_artifact.inline_data:
data = report_artifact.inline_data.data
mime_type = report_artifact.inline_data.mime_type
print(f"Successfully loaded artifact {report_name} with mime_type: {mime_type}")
# Now you can process the data...
# For example, if it's a text file:
if "text" in mime_type:
content = data.decode('utf-8')
# ... do something with the content ...
return "Report processed successfully."
else:
return "Artifact not found or has no inline data."
except Exception as e:
return f"An error occurred: {e}" For more detailed information, you can refer to the official documentation on artifacts. [1] |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
like question, i print out payload from agent engine and my agent have call load artifact inside, but in the payload it does not any inline data that i can use, did anyone solve this problem?
Beta Was this translation helpful? Give feedback.
All reactions