Skip to content

Comments

Fix/artifact dict handling 3495 simplified#4523

Closed
Fangmbeng wants to merge 3 commits intogoogle:mainfrom
Fangmbeng:fix/artifact-dict-handling-3495-simplified
Closed

Fix/artifact dict handling 3495 simplified#4523
Fangmbeng wants to merge 3 commits intogoogle:mainfrom
Fangmbeng:fix/artifact-dict-handling-3495-simplified

Conversation

@Fangmbeng
Copy link

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

  • Closes: #issue_number
  • Related: #issue_number

2. Or, if no issue exists, describe the change:

If applicable, please follow the issue templates to provide as much detail as
possible.

Problem:
A clear and concise description of what the problem is.

Solution:
A clear and concise description of what you want to happen and why you choose
this solution.

Testing Plan

Please describe the tests that you ran to verify your changes. This is required
for all PRs that are not small documentation or typo fixes.

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Please include a summary of passed pytest results.

Manual End-to-End (E2E) Tests:

Please provide instructions on how to manually test your changes, including any
necessary setup or configuration. Please provide logs or screenshots to help
reviewers better understand the fix.

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

Add any other context or screenshots about the feature request here.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Fangmbeng, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly improves the usability of artifact saving by allowing developers to directly pass dictionary-shaped data, which is then automatically converted into the expected types.Part format. This change streamlines the process for handling serialized artifacts, reducing the need for manual conversion and making the API more intuitive for common use cases involving data interchange formats.

Highlights

  • Enhanced Artifact Saving Flexibility: The save_artifact methods across various artifact services (in-memory, GCS, file) and the Context class now accept both types.Part objects and dictionary-shaped artifacts (dict[str, Any]). This simplifies saving artifacts that have been serialized, such as from JSON.
  • Automatic Dictionary-to-Part Conversion: A new static method, _convert_artifact_if_dict, has been introduced in BaseArtifactService to automatically convert dictionary-shaped artifacts into types.Part objects before saving, ensuring consistent internal handling.
  • Updated API and Documentation: Type hints and docstrings for artifact parameters in save_artifact methods have been updated to reflect the new support for dictionary-shaped inputs. The SaveArtifactRequest schema in the web server also now explicitly allows dict[str, Any].
  • Comprehensive Unit Tests: New unit tests have been added to verify the correct saving and loading of dictionary-shaped artifacts across all supported artifact service types (in-memory, GCS, file), covering both byte data and text content.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • .gitignore
    • Added DICT_ARTIFACTS_FIX.md to the ignore list.
  • src/google/adk/agents/context.py
    • Updated the artifact parameter type hint in save_artifact to accept types.Part | dict[str, Any].
    • Expanded the docstring for the artifact parameter to clarify that it can be a types.Part or a dict-shaped artifact.
  • src/google/adk/artifacts/base_artifact_service.py
    • Introduced a new static method _convert_artifact_if_dict to handle the conversion of dictionary-shaped artifacts to types.Part.
    • Modified the artifact parameter type hint in the abstract save_artifact method to accept types.Part | dict[str, Any].
    • Updated the docstring for the artifact parameter in save_artifact to reflect the new dict-shaped artifact support.
  • src/google/adk/artifacts/file_artifact_service.py
    • Updated the artifact parameter type hint in save_artifact to accept types.Part | dict[str, Any].
    • Integrated the _convert_artifact_if_dict method call to process the artifact before saving.
  • src/google/adk/artifacts/gcs_artifact_service.py
    • Updated the artifact parameter type hint in save_artifact to accept types.Part | dict[str, Any].
    • Integrated the _convert_artifact_if_dict method call to process the artifact before saving.
  • src/google/adk/artifacts/in_memory_artifact_service.py
    • Updated the artifact parameter type hint in save_artifact to accept types.Part | dict[str, Any].
    • Integrated the _convert_artifact_if_dict method call to process the artifact before saving.
  • src/google/adk/cli/adk_web_server.py
    • Modified the artifact field in SaveArtifactRequest to accept types.Part | dict[str, Any].
    • Updated the description for the artifact field to indicate support for dict-shaped artifacts.
  • src/google/adk/tools/_forwarding_artifact_service.py
    • Updated the artifact parameter type hint in save_artifact to accept types.Part | dict[str, Any].
    • Added a comment explaining that the conversion of dict-shaped artifacts will be handled by the concrete artifact service implementation.
  • tests/unittests/artifacts/test_artifact_service.py
    • Added test_save_load_dict_shaped_artifact to verify saving and loading of dict-shaped artifacts with byte data across all service types.
    • Added test_save_text_dict_shaped_artifact to verify saving and loading of dict-shaped artifacts with text content across all service types.
Activity
  • The pull request description includes placeholders for linking to issues, describing the problem and solution, and outlining a testing plan, but no specific activity or comments have been recorded yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot
Copy link
Collaborator

adk-bot commented Feb 18, 2026

Response from ADK Triaging Agent

Hello @Fangmbeng, thank you for your contribution!

To help us review this PR, could you please fill out the pull request description? Specifically, it would be helpful to:

You can find more details in our contribution guide. This information will help reviewers to understand and verify your changes more efficiently. Thanks!

@Fangmbeng Fangmbeng closed this Feb 18, 2026
@Fangmbeng Fangmbeng deleted the fix/artifact-dict-handling-3495-simplified branch February 18, 2026 09:01
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request simplifies artifact handling by allowing dictionary-shaped artifacts to be passed to save_artifact methods. The changes are consistently applied across different artifact service implementations, and new tests are added to cover this functionality. My review includes one high-severity finding regarding a bug where custom_metadata is not forwarded correctly in one of the services, and a couple of medium-severity suggestions to enhance the new tests by including custom_metadata in the test cases. Overall, this is a good improvement.

Comment on lines +49 to +50
# Delegate to parent tool context, which will handle conversion in the
# concrete artifact service implementation.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

This delegation is missing the custom_metadata parameter in the call to self.tool_context.save_artifact. This will cause any provided custom_metadata to be silently ignored. Please forward it to the underlying call.

For example:

return await self.tool_context.save_artifact(
    filename=filename,
    artifact=artifact,
    custom_metadata=custom_metadata,
)

user_id=user_id,
session_id=session_id,
filename=filename,
artifact=dict_artifact,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new tests for dict-shaped artifacts are great! To make them even more robust, consider also testing the custom_metadata parameter. This would ensure that metadata is correctly handled when saving dictionary-shaped artifacts.

You would also need to add assertions to verify that the custom_metadata is saved and loaded correctly, for example by using get_artifact_version.

      artifact=dict_artifact,
      custom_metadata={"source": "dict-test"}

user_id=user_id,
session_id=session_id,
filename=filename,
artifact=dict_artifact,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the test above, consider testing the custom_metadata parameter here as well to ensure it's handled correctly with text-based dict-shaped artifacts. You'll also need to add assertions to verify the metadata.

      artifact=dict_artifact,
      custom_metadata={"source": "dict-text-test"}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants