Skip to content

Conversation

@rlancemartin
Copy link

@rlancemartin rlancemartin commented Nov 7, 2025

Problem

When the agent creates files with paths like /research_plan.md, it tries to write to the root filesystem instead of the current working directory, resulting in errors:

Error writing file '/research_plan.md': [Errno 30] Read-only file system: '/research_plan.md'

Root Cause

The default FilesystemBackend in agent.py was created without virtual_mode=True:

backend = CompositeBackend(
    default=FilesystemBackend(),  # No virtual_mode
    routes={"/memories/": long_term_backend}
)

Without virtual_mode=True, the FilesystemBackend treats paths starting with / as absolute system paths rather than paths relative to the working directory.

Solution

Enable virtual_mode=True for the default backend:

backend = CompositeBackend(
    default=FilesystemBackend(root_dir=Path.cwd(), virtual_mode=True),  # With virtual_mode
    routes={"/memories/": long_term_backend}
)

With this fix:

  • /research_plan.md{cwd}/research_plan.md (sandboxed to working directory)
  • /memories/file.md → Still routes to agent directory via /memories/ route

Impact

  • Safer: File operations are sandboxed to the current working directory
  • More intuitive: Paths like /file.txt behave as users expect (relative to cwd)
  • No breaking changes: /memories/ routing continues to work as before

Testing

Verified with test script:

backend = FilesystemBackend(root_dir=Path.cwd(), virtual_mode=True)
path = backend._resolve_path("/research_plan.md")
# Result: /tmp/research_plan.md (writable) 

Without fix:

backend = FilesystemBackend()
path = backend._resolve_path("/research_plan.md") 
# Result: /research_plan.md (system root, not writable) 

Problem: When agent creates files with paths like '/research_plan.md',
it tries to write to root filesystem instead of current working directory,
resulting in 'Read-only file system' errors.

Root cause: Default FilesystemBackend was created without virtual_mode=True,
causing absolute paths to be treated as system absolute paths rather than
paths relative to the working directory.

Solution: Enable virtual_mode=True for the default backend so that:
- /research_plan.md → {cwd}/research_plan.md (sandboxed to working dir)
- /memories/ routes still work correctly with their own virtual_mode

Impact: This makes the agent's file operations safer and more intuitive,
as paths starting with / are now relative to the working directory rather
than system root.

Testing:
- Verified path resolution: /file.txt now correctly resolves to cwd/file.txt
- Confirmed /memories/ routing still works with virtual_mode backend
@rlancemartin rlancemartin marked this pull request as draft November 7, 2025 19:48
Problem: Agent was creating files in nested incorrect paths like:
  /Users/.../deepagents/Users/.../deepagents/research_project/file.md
instead of:
  /Users/.../deepagents/research_project/file.md

Root cause: Agent was converting relative paths like /research_project/file.md
to absolute system paths, which when processed by virtual_mode filesystem
backend, got nested under the working directory.

Solution: Add clear path handling documentation to system prompt:
- Paths starting with / are relative to working directory
- Do NOT use absolute system paths
- Explicitly show example: /file.txt → {cwd}/file.txt

This helps the agent understand the virtual filesystem behavior.
@rlancemartin rlancemartin marked this pull request as ready for review November 7, 2025 23:46
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.

2 participants