Skip to content

fix(artifacts): accept dict-shaped artifacts in InMemoryArtifactService (#3495)#4540

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

fix(artifacts): accept dict-shaped artifacts in InMemoryArtifactService (#3495)#4540
Fangmbeng wants to merge 3 commits intogoogle:mainfrom
Fangmbeng:fix/artifact-dict-handling-3495

Conversation

@Fangmbeng
Copy link

@Fangmbeng Fangmbeng commented Feb 18, 2026

fix(artifacts): accept dict-shaped artifacts in InMemoryArtifactService (#3495)

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 flexibility of artifact handling by enabling save_artifact methods to directly accept dictionary-shaped artifacts. This change streamlines the process for users working with serialized artifact data, as the system now automatically converts these dictionaries into the required types.Part objects. The update ensures broader compatibility and ease of use when integrating with various data serialization formats.

Highlights

  • Enhanced Artifact Saving Flexibility: The save_artifact methods across various artifact services (In-Memory, GCS, File) now accept dictionary-shaped artifacts (dict[str, Any]) in addition to the existing types.Part objects. This allows for more flexible handling of serialized artifact data.
  • Centralized Artifact Conversion: A new static method, _convert_artifact_if_dict, has been introduced in BaseArtifactService to standardize the conversion of dictionary-shaped artifacts into types.Part objects. This method is called by concrete service implementations before saving.
  • API and Schema Updates: The SaveArtifactRequest schema in the web server (adk_web_server.py) has been updated to reflect the new acceptance of dictionary-shaped artifacts, ensuring consistency across the API.
  • Comprehensive Unit Testing: New unit tests have been added to test_artifact_service.py to thoroughly verify the saving and loading of both byte-data and text-based dictionary-shaped artifacts across all supported artifact service types.

🧠 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 type hint for the artifact parameter in save_artifact to accept dict[str, Any] alongside types.Part.
    • Modified the docstring for the artifact parameter to reflect the new accepted type.
  • src/google/adk/artifacts/base_artifact_service.py
    • Introduced a new static method _convert_artifact_if_dict to convert dictionary-shaped artifacts to types.Part objects.
    • Updated the type hint for the artifact parameter in the abstract save_artifact method.
    • Revised the docstring for the artifact parameter to explain the new dict-shaped artifact acceptance and conversion.
  • src/google/adk/artifacts/file_artifact_service.py
    • Updated the type hint for the artifact parameter in save_artifact.
    • Added a call to self._convert_artifact_if_dict(artifact) to ensure dict-shaped artifacts are converted before further processing.
  • src/google/adk/artifacts/gcs_artifact_service.py
    • Updated the type hint for the artifact parameter in save_artifact.
    • Added a call to self._convert_artifact_if_dict(artifact) to convert dict-shaped artifacts.
  • src/google/adk/artifacts/in_memory_artifact_service.py
    • Updated the type hint for the artifact parameter in save_artifact.
    • Added a call to self._convert_artifact_if_dict(artifact) to convert dict-shaped artifacts.
  • src/google/adk/cli/adk_web_server.py
    • Modified the SaveArtifactRequest Pydantic model to allow the artifact field to accept dict[str, Any] in addition to types.Part.
    • Updated the field description accordingly.
  • src/google/adk/tools/_forwarding_artifact_service.py
    • Updated the type hint for the artifact parameter in save_artifact.
    • Added a comment explaining that conversion 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 (bytes data) across all artifact service types.
    • Added test_save_text_dict_shaped_artifact to verify saving and loading of dict-shaped artifacts (text data) across all artifact service types.
Activity
  • The pull request was opened by Fangmbeng.
  • No specific review comments or progress updates are available in the provided context.
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 adk-bot added the services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc label Feb 18, 2026
@adk-bot
Copy link
Collaborator

adk-bot commented Feb 18, 2026

Response from ADK Triaging Agent

Hello @Fangmbeng, thank you for creating this PR!

Could you please fill out the PR template in the description? This includes providing a link to an existing issue or a description of the change, a testing plan, and filling out the checklist.

This information will help reviewers to review your PR more efficiently. Thanks!

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

The pull request successfully implements support for dict-shaped artifacts in the save_artifact method across various artifact services. This enhancement improves the flexibility of the API, especially when dealing with serialized data. I have identified a few minor issues regarding the .gitignore configuration and indentation consistency in the newly added tests.

I am having trouble creating individual review comments. Click here to see my feedback.

.gitignore (107)

medium

Adding a specific, PR-related file like DICT_ARTIFACTS_FIX.md to the repository's .gitignore is generally discouraged. If this is a temporary local file, it's better to use your local .git/info/exclude or a global gitignore file. If it's meant to be a permanent part of the repository, it should probably be committed rather than ignored.

tests/unittests/artifacts/test_artifact_service.py (861-867)

medium

The indentation in this block is inconsistent with the rest of the file. The project appears to use 2-space indentation, but this block uses 4 spaces for the assert statements relative to the if/else keywords.

  if loaded.text is not None:
    assert loaded.text == "Hello, World!"
  else:
    assert (
        loaded.inline_data is not None
        and loaded.inline_data.data == b"Hello, World!"
    )

@Fangmbeng Fangmbeng changed the title fix(artifacts): accept dict-shaped artifacts in InMemoryArtifactServi… fix(artifacts): accept dict-shaped artifacts in InMemoryArtifactService (#3495) Feb 18, 2026
@Fangmbeng Fangmbeng force-pushed the fix/artifact-dict-handling-3495 branch from 9538df5 to 984b680 Compare February 18, 2026 22:07
@ryanaiagent
Copy link
Collaborator

Hi @Fangmbeng, Thank you for your contribution! We need additional information to start the review. Please provide a clear description of the changes, and if applicable, supporting details such as screenshots, logs, and/or unit tests. Providing more context will help us understand the purpose of your contribution and expedite the review process.

@ryanaiagent ryanaiagent self-assigned this Feb 19, 2026
@ryanaiagent ryanaiagent added the request clarification [Status] The maintainer need clarification or more information from the author label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

request clarification [Status] The maintainer need clarification or more information from the author services [Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

Comments