feat: add file info tracking in the state #309
+1,207
−83
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.
Description
This PR adds comprehensive file state tracking to the
file_read,file_write, andeditortools, enabling agents to maintain awareness of their file interactions throughout a session (and cross sessions when session manager is passed).Key Features
State Management via
agent.state:ToolContextandagent.statefilesdict keyed by path) and sequential lists (files_written,files_read)Enhanced FileInfo Structure:
path,is_dir,size,created_at,modified_atmodefield tracks operation type (e.g., "view", "write", "search", "chunk")mode_infofield stores mode-specific parameters (e.g.,{"chunk_size": 1024, "chunk_offset": 0})Tools Updated:
file_write.py: Tracks file writes with mode="write"file_read.py: Tracks all 10 reading modes with specific mode_info parameterseditor.py: Tracks all 7 editor commands with operation-specific detailsDocumentation & Examples:
docs/FILE_STATE_TRACKING.mdexamples/file_state_tracking.pydemonstrating all featurestests/test_file_info.pyBenefits
Related Issues
Documentation PR
Type of Change
Improving existing Tools
Testing
How have you tested the change?
hatch run prepareToolContextTest Coverage:
tests/test_file_info.py::test_get_file_info_for_file PASSED tests/test_file_info.py::test_get_file_info_for_directory PASSED tests/test_file_info.py::test_get_file_info_nonexistent_file PASSED tests/test_file_info.py::test_format_file_info PASSED tests/test_file_write.py::test_file_write_via_agent PASSED tests/test_file_read.py::test_file_read_via_agent PASSED # ... 35 tests total, all passingChecklist
docs/FILE_STATE_TRACKING.md)examples/file_state_tracking.py)Files Modified:
src/strands_tools/utils/file_info.py- Core FileInfo structure and utilitiessrc/strands_tools/file_write.py- State tracking for write operationssrc/strands_tools/file_read.py- State tracking for all read modessrc/strands_tools/editor.py- State tracking for all editor commandsdocs/FILE_STATE_TRACKING.md- Comprehensive documentationexamples/file_state_tracking.py- Working examplesBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.