Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix/artifact dict handling 3495#4524

Closed
Fangmbeng wants to merge 6 commits intogoogle:maingoogle/adk-python:mainfrom
Fangmbeng:fix/artifact-dict-handling-3495Fangmbeng/adk-python:fix/artifact-dict-handling-3495Copy head branch name to clipboard
Closed

Fix/artifact dict handling 3495#4524
Fangmbeng wants to merge 6 commits intogoogle:maingoogle/adk-python:mainfrom
Fangmbeng:fix/artifact-dict-handling-3495Fangmbeng/adk-python:fix/artifact-dict-handling-3495Copy head branch name to clipboard

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 enhances the flexibility of the artifact saving mechanism by allowing users to provide artifacts as standard Python dictionaries, which are then automatically converted into the expected types.Part format. This change simplifies integration with serialized data sources and improves the overall usability of the artifact services, ensuring that both types.Part objects and dictionary representations can be seamlessly handled.

Highlights

  • Enabled saving of dictionary-shaped artifacts: The save_artifact methods across various artifact services now accept dict[str, Any] in addition to types.Part, providing greater flexibility for artifact input.
  • Introduced automatic conversion for dictionary artifacts: A new static method _convert_artifact_if_dict was added to BaseArtifactService to automatically convert dictionary-shaped artifacts into types.Part objects before saving, ensuring compatibility with existing systems.
  • Updated API and CLI definitions: The SaveArtifactRequest in the web server CLI was updated to reflect the new accepted artifact type, aligning the API with the enhanced functionality.
  • Added comprehensive unit tests: New tests were implemented to ensure the correct saving and loading of dictionary-shaped artifacts across in-memory, GCS, and file-based artifact services, validating the new feature's robustness.

🧠 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 ignore list.
  • src/google/adk/agents/context.py
    • Modified save_artifact method to accept dict[str, Any] for the artifact parameter and updated its docstring.
  • src/google/adk/artifacts/base_artifact_service.py
    • Introduced a new static method _convert_artifact_if_dict to handle conversion from dict to types.Part.
    • Updated the save_artifact abstract method signature and docstring to include dict[str, Any] as an accepted artifact type.
  • src/google/adk/artifacts/file_artifact_service.py
    • Updated the save_artifact method signature to accept dict[str, Any] and integrated the _convert_artifact_if_dict conversion logic.
  • src/google/adk/artifacts/gcs_artifact_service.py
    • Updated the save_artifact method signature to accept dict[str, Any] and integrated the _convert_artifact_if_dict conversion logic.
  • src/google/adk/artifacts/in_memory_artifact_service.py
    • Updated the save_artifact method signature to accept dict[str, Any] and integrated the _convert_artifact_if_dict conversion logic.
  • src/google/adk/cli/adk_web_server.py
    • Modified the SaveArtifactRequest Pydantic model to allow the artifact field to be either types.Part or dict[str, Any], updating its description accordingly.
  • src/google/adk/tools/_forwarding_artifact_service.py
    • Updated the save_artifact method signature to accept dict[str, Any] and added a comment indicating that conversion will be handled by the concrete artifact service.
  • tests/unittests/artifacts/test_artifact_service.py
    • Added two new asynchronous parameterized tests, test_save_load_dict_shaped_artifact and test_save_text_dict_shaped_artifact, to validate the saving and loading of dictionary-shaped artifacts across all implemented artifact service types.
Activity
  • No human activity (comments, reviews, progress updates) was found in the provided pull request 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
Copy link
Collaborator

adk-bot commented Feb 18, 2026

Response from ADK Triaging Agent

Hello @Fangmbeng, thank you for creating this PR!

To help reviewers understand the context and purpose of your contribution, could you please fill out the PR description template? Specifically, please provide the following:

  • A link to the relevant GitHub issue.
  • A description of the problem and the solution.
  • A description of your testing plan.

This information is requested in our contribution guidelines and will help us review your PR more efficiently. Thanks!

@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
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 introduces a valuable enhancement by allowing save_artifact methods to accept dictionary-shaped artifacts. The changes are consistently applied across all artifact service implementations (File, GCS, InMemory) and the web server API. The addition of a _convert_artifact_if_dict helper in the base class is a clean way to handle the conversion logic. The new unit tests effectively validate this new functionality. I have one suggestion to improve the precision of an assertion in one of the new tests.

Comment on lines +860 to +867
# GCS/File services may return text as inline_data bytes; accept either form.
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!"
) No newline at end of file
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 comment on line 860 is not entirely accurate. The FileArtifactService preserves text artifacts as text, while GcsArtifactService converts them to inline_data with bytes. InMemoryArtifactService also preserves text.

The current assertion is a bit too general and could mask incorrect behavior in one of the services. To make the test more robust and clear about the expected behavior of each service, I suggest adding specific assertions for each service_type.

Suggested change
# GCS/File services may return text as inline_data bytes; accept either form.
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!"
)
# GCS service converts text to inline_data bytes, while File and InMemory
# services preserve text content.
if service_type is ArtifactServiceType.GCS:
assert loaded.text is None
assert loaded.inline_data is not None
assert loaded.inline_data.data == b"Hello, World!"
assert loaded.inline_data.mime_type == "text/plain"
else:
assert loaded.inline_data is None
assert loaded.text == "Hello, World!"

@Fangmbeng Fangmbeng closed this Feb 18, 2026
@Fangmbeng Fangmbeng deleted the fix/artifact-dict-handling-3495 branch February 18, 2026 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

2 participants

Comments

Close sidebar
Morty Proxy This is a proxified and sanitized view of the page, visit original site.