Fix FileSystemMiddleware relative path handling #538
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.
Fixes #518
Problem
FileSystemMiddleware was incorrectly handling relative paths. In
filesystem.pyline 142, the path logic caused relative file paths to be treated as if they are located in the middleware's root folder, effectively discarding their actual relationship to the current working directory.Expected behavior: We need both relative paths and absolute paths depending if we are running this in a container or not.
Solution
_validate_pathto accept avirtual_modebool parameter that controls path normalizationvirtual_mode=False, relative paths are preserved as relative (fixes the issue)virtual_mode=TrueorNone, relative paths are converted to absolute virtual paths (maintains backward compatibility)ls,read_file,write_file,edit_file) to pass the backend'svirtual_modeattribute to_validate_path_get_virtual_modeto extract virtual_mode from backend instancesChanges
libs/deepagents/deepagents/middleware/filesystem.py: Updated_validate_pathfunction and all tool generatorslibs/deepagents/tests/unit_tests/middleware/test_validate_path.py: Updated tests to reflect new behaviorTesting
test_validate_path.py)Expected Behavior
virtual_mode=False