-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Description
Issue : Unable to Send Emails with Attachments Due to Artifact Loading Failure
Description
Agents cannot send emails with file attachments because tool_context.load_artifact() fails to load files that were uploaded through the UI. This is a direct consequence of Issue No :4265 (list_artifacts() returning empty), but also affects cases where artifact names are known but cannot be loaded.
Problem
When attempting to send an email with an attachment using tool_context.load_artifact(filename), the method fails to find or load the artifact even when:
- The file was successfully uploaded through the UI
- The artifact name is known (e.g., from
[Uploaded Artifact: "filename.pdf"]placeholder) - The file content is accessible via
user_content.partswithinline_data
Steps to Reproduce
- Deploy an ADK agent with a tool that sends emails with attachments
- Upload a file (PDF, image, etc.) through the ADK Web Developer UI
- Agent attempts to send email with attachment using
send_email_with_attachment(artifact_name="filename.pdf") - Tool calls
await tool_context.load_artifact("filename.pdf") - Method returns
Noneor raises an error, preventing email from being sent
Expected Behavior
tool_context.load_artifact(filename) should:
- Successfully load artifacts that were uploaded through the UI
- Return artifact data that can be used to send as email attachments
- Work with artifact names that appear in conversation placeholders
Actual Behavior
tool_context.load_artifact(filename) returns None or fails even when:
- Files are successfully uploaded
- Artifact names are correctly specified
- Files are visible in the conversation as placeholders
Code Example
from google.adk.tools import ToolContext, FunctionTool
from google.adk.agents import Agent
import requests
import base64
async def send_email_with_attachment(
tool_context: ToolContext,
artifact_name: str
) -> dict:
"""Send email with file attachment."""
# This fails to load the artifact
artifacts = await tool_context.list_artifacts()
print(f"artifacts: {artifacts}") # Prints: []
# Files are uploaded but not detected here
artifact = await tool_context.load_artifact(artifact_name)
if artifact is None:
return {
"success": False,
"message": f"Artifact '{artifact_name}' not found"
}
# Extract file data
if artifact.inline_data:
file_bytes = artifact.inline_data.data
mime_type = artifact.inline_data.mime_type
else:
return {"success": False, "message": "No file data in artifact"}
# Encode and send email via Microsoft Graph API
encoded_file = base64.b64encode(file_bytes).decode("utf-8")
# Email sending code...
# This never executes because artifact loading failsError Messages
Common errors encountered:
Artifact 'filename.pdf' not foundNonereturned fromload_artifact()despite file being uploadedAttributeError: 'NoneType' object has no attribute 'inline_data'
Workarounds Attempted
- Loading from user_content: Successfully extracted file data from
tool_context.user_content.parts, but this only works for files in the current message:
# Workaround: Extract from user_content
if hasattr(tool_context, 'user_content') and tool_context.user_content:
for part in tool_context.user_content.parts:
if hasattr(part, 'inline_data') and part.inline_data:
file_bytes = part.inline_data.data
# Can send email with this, but only for current message-
Trying multiple name variations: Attempted loading with different name formats:
filename.pdfuser:filename.pdf- Exact name from placeholder
- All return
None
-
Saving artifact first: Attempted to save file from
user_contentas artifact, butsave_artifact()may not be available or may fail in Agent Engine deployments.
Impact
This issue prevents:
- Sending uploaded files via email
- Building file sharing workflows
- Creating agents that process and forward documents
- Implementing document distribution features
Relationship to Issue No: 4265
This issue is directly related to Issue No: 4265 (list_artifacts() returning empty):
- If
list_artifacts()worked, we could discover artifact names - If
load_artifact()worked, we could access file data for email attachments - Both issues stem from the same root cause: artifacts uploaded through UI are not properly registered/accessible via the artifact service
Questions
- How should artifacts be loaded when files are uploaded through the UI?
- Is there a different method or approach to access uploaded file data for email attachments?
- Should
save_artifact()be called explicitly after file uploads? - Are there deployment-specific requirements for artifact loading in Agent Engine?
Related Documentation
Note: This issue blocks email functionality in file upload agents. A solution or workaround would enable important use cases like document sharing and distribution.