Fix/artifact dict handling 3495#4524
Fix/artifact dict handling 3495#4524Fangmbeng 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
…remove redundant conversion from ForwardingArtifactService
Summary of ChangesHello @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 Highlights
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
|
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:
This information is requested in our contribution guidelines and will help us review your PR more efficiently. Thanks! |
There was a problem hiding this comment.
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.
| # 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 |
There was a problem hiding this comment.
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.
| # 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!" |
…gitignore" This reverts commit fec8e25.
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):
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:
Please include a summary of passed
pytestresults.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
Additional context
Add any other context or screenshots about the feature request here.