Skip to content

[BUG]: artifacts show up twice in adk web #4036

@Tyrooon

Description

@Tyrooon

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Describe the bug
I upgrade google-adk to v1.21.0, and the bug shows up. The artifacts shows up twice incorrectly.

Image

The primary function of my agent is to analyze data and generate a data analysis report. I declared an upload_artifacts function in the code, and when called via the ADK web, the frontend will display the artifacts' results twice.

My code

async def upload_file_to_artifact(tool_context: ToolContext, file_path: str):
    """
    Reads a file from the provided file path, saves it as an Artifact, and automatically sets the mime_type.
    
    :param tool_context: ToolContext object, used to call the save_artifact method.
    :param file_path: The local path of the file.
    """
    # Get the filename from the file path
    filename = os.path.basename(file_path)
    
    # Read the file
    with open(file_path, "rb") as file:
        file_bytes = file.read()
    
    # Get the MIME type of the file
    mime_type, _ = mimetypes.guess_type(file_path)
    
    # Create Artifact
    artifact = types.Part.from_bytes(
        data=file_bytes,
        mime_type=mime_type or "application/octet-stream"
    )
    
    # Save Artifact
    try:
        await tool_context.save_artifact(filename, artifact)
        print(f"Successfully saved artifact '{filename}'.")
    except ValueError as e:
        print(f"Failed to save artifact '{filename}': {e}")
    except Exception as e:
        print(f"Unexpected error while saving artifact '{filename}': {e}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    web[Component] This issue will be transferred to adk-web

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions