feat(artifacts): add LocalFileArtifactService for local file system storage#2408
Closed
eduramirezh wants to merge 4 commits intogoogle:mainfrom
Closed
feat(artifacts): add LocalFileArtifactService for local file system storage#2408eduramirezh wants to merge 4 commits intogoogle:mainfrom
eduramirezh wants to merge 4 commits intogoogle:mainfrom
Conversation
…torage
This adds a new LocalFileArtifactService implementation that stores artifacts
on the local file system instead of cloud storage or memory, providing developers
with a local persistence option for development, testing, and deployment scenarios.
Key features:
- File system storage with configurable base path (defaults to ./adk_artifacts)
- Maintains consistent directory structure with user/session namespacing
- Stores MIME type metadata in separate .metadata.json files
- Full async support using asyncio.to_thread() for non-blocking I/O
- Proper error handling for corrupted metadata and missing files
- Sequential integer versioning starting from version 0
Changes:
- Add LocalFileArtifactService class implementing BaseArtifactService interface
- Add comprehensive standalone unit tests for all functionality
- Integrate with existing parametrized tests for consistency validation
- Export new service in artifacts/__init__.py
- Fix minor typo in CONTRIBUTING.md
## Testing Plan
### Unit Tests
All unit tests pass with comprehensive coverage:
**Standalone Tests (24 tests):**
- test_local_file_artifact_service.py covers:
- Basic CRUD operations (save/load/delete)
- Version management and specific version loading
- User-namespaced vs session-scoped file handling
- MIME type preservation across different content types
- Directory structure validation
- Error handling (corrupted metadata, missing files)
- Edge cases (nonexistent versions, empty lists)
**Integration Tests (24 additional tests):**
- Extended existing parametrized tests in test_artifact_service.py
- Added LOCAL_FILE variant to all existing test cases
- Validates consistency with InMemoryArtifactService and GcsArtifactService
**Test Results:**
```
========================= 48 passed, 1 warning in 1.75s =========================
```
Note: The 1 warning is a pre-existing Pydantic warning unrelated to this change.
**Code Quality:**
- pylint: 10.00/10 (perfect score)
- mypy: Success, no type errors
- Formatted with pyink and isort per repository standards
### Manual E2E Testing
The LocalFileArtifactService can be manually tested by:
1. **Basic Usage:**
```python
from google.adk.artifacts import LocalFileArtifactService
service = LocalFileArtifactService(base_path="./test_artifacts")
```
2. **Directory Structure Verification:**
After saving artifacts, verify correct file system layout:
- Regular files: `./test_artifacts/{app}/{user}/{session}/{filename}/{version}`
- User files: `./test_artifacts/{app}/{user}/user/{filename}/{version}`
- Metadata files: `{path}.metadata.json` alongside each artifact
3. **Integration Testing:**
Can be used as drop-in replacement for other artifact services in any
existing ADK application or workflow.
This implementation maintains full API compatibility with existing artifact
services while providing local file system persistence capabilities.
Collaborator
|
Response from ADK Triaging Agent Hello @eduramirezh, thank you for creating this PR! This PR is a new feature, could you please associate a GitHub issue with this PR? If there is no existing issue, could you please create one? This information will help reviewers to review your PR more efficiently. Thanks! |
Author
|
Related issue: #2410 |
Collaborator
|
It's supported in https://github.com/google/adk-python/blob/main/src/google/adk/artifacts/file_artifact_service.py. Thanks for the contribution. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds a new LocalFileArtifactService implementation that stores artifacts
on the local file system instead of cloud storage or memory, providing developers
with a local persistence option for development, testing, and deployment scenarios.
Key features:
Changes:
Testing Plan
Unit Tests
All unit tests pass with comprehensive coverage:
Standalone Tests (24 tests):
Integration Tests (24 additional tests):
Test Results:
Note: The 1 warning is a pre-existing Pydantic warning unrelated to this change.
Code Quality:
Manual E2E Testing
The LocalFileArtifactService can be manually tested by:
Basic Usage:
Directory Structure Verification:
After saving artifacts, verify correct file system layout:
./test_artifacts/{app}/{user}/{session}/{filename}/{version}./test_artifacts/{app}/{user}/user/{filename}/{version}{path}.metadata.jsonalongside each artifactIntegration Testing:
Can be used as drop-in replacement for other artifact services in any
existing ADK application or workflow.
This implementation maintains full API compatibility with existing artifact
services while providing local file system persistence capabilities.