Skip to content

Unable to Send Emails with Attachments Due to Artifact Loading Failure #4266

@sudharshanredd445

Description

@sudharshanredd445

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.parts with inline_data

Steps to Reproduce

  1. Deploy an ADK agent with a tool that sends emails with attachments
  2. Upload a file (PDF, image, etc.) through the ADK Web Developer UI
  3. Agent attempts to send email with attachment using send_email_with_attachment(artifact_name="filename.pdf")
  4. Tool calls await tool_context.load_artifact("filename.pdf")
  5. Method returns None or 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 fails

Error Messages

Common errors encountered:

  • Artifact 'filename.pdf' not found
  • None returned from load_artifact() despite file being uploaded
  • AttributeError: 'NoneType' object has no attribute 'inline_data'

Workarounds Attempted

  1. 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
  1. Trying multiple name variations: Attempted loading with different name formats:

    • filename.pdf
    • user:filename.pdf
    • Exact name from placeholder
    • All return None
  2. Saving artifact first: Attempted to save file from user_content as artifact, but save_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

  1. How should artifacts be loaded when files are uploaded through the UI?
  2. Is there a different method or approach to access uploaded file data for email attachments?
  3. Should save_artifact() be called explicitly after file uploads?
  4. 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.

Metadata

Metadata

Assignees

Labels

mcp[Component] Issues about MCP supporttools[Component] This issue is related to tools

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions