Skip to content

Conversation

@mattiagaggi
Copy link

@mattiagaggi mattiagaggi commented Dec 3, 2025

Fixes #518

Problem

FileSystemMiddleware was incorrectly handling relative paths. In filesystem.py line 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

  • Modified _validate_path to accept a virtual_mode bool parameter that controls path normalization
  • When virtual_mode=False, relative paths are preserved as relative (fixes the issue)
  • When virtual_mode=True or None, relative paths are converted to absolute virtual paths (maintains backward compatibility)
  • Updated all tool generators (ls, read_file, write_file, edit_file) to pass the backend's virtual_mode attribute to _validate_path
  • Added helper function _get_virtual_mode to extract virtual_mode from backend instances

Changes

  • libs/deepagents/deepagents/middleware/filesystem.py: Updated _validate_path function and all tool generators
  • libs/deepagents/tests/unit_tests/middleware/test_validate_path.py: Updated tests to reflect new behavior

Testing

  • ✅ All existing tests pass (9/9 tests in test_validate_path.py)
  • ✅ Updated tests to reflect new behavior
  • ✅ Verified backward compatibility with StateBackend and virtual FilesystemBackend

Expected Behavior

  • Relative paths are now correctly resolved relative to the current working directory when using FilesystemBackend with virtual_mode=False
  • Backward compatibility is maintained for StateBackend and virtual FilesystemBackend

- Modified _validate_path to accept virtual_mode parameter
- When virtual_mode=False, preserve relative paths as relative (fixes issue)
- When virtual_mode=True or None, convert relative paths to absolute virtual paths (backward compatibility)
- Updated all tool generators to pass backend's virtual_mode to _validate_path
- Updated tests to reflect new behavior

Fixes issue where relative paths were incorrectly treated as root-level files
when using FilesystemBackend with virtual_mode=False.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FileSystemMiddleware incorrectly normalizes relative paths, treating them as root-level files

2 participants