DeepAgents Backend manages Agent file system operations, including artifact storage, user cloud drive, and long-term memory.
1. Overview
1.1 Current Issues
| Issue | Description |
|---|---|
| In-memory data loss | StateBackend uses InMemoryStore; all data is lost on service restart |
| Frontend cannot access data | Files in the virtual file system are inaccessible to the frontend |
| Sandbox destruction | Artifacts are lost when the E2B sandbox times out |
| Multi-environment inconsistency | Data is fragmented across Desktop, Sandbox, and in-memory environments |
1.2 Goals
- All artifacts are automatically persisted to cloud storage
- Users have a “cloud drive” experience with access to their files at any time
- Unified storage architecture to reduce complexity
2. DeepAgents Backend Types
DeepAgents provides the following Backend types:| Backend | Durability | Storage Location | Use Case |
|---|---|---|---|
| StateBackend | ❌ Temporary | LangGraph State (in-memory) | Temporary files for a single session |
| StoreBackend | ✅ Persistent | LangGraph Store | Long-term memory |
| FilesystemBackend | ✅ Persistent | Local file system | Desktop mode |
| BaseSandbox | ⚠️ Sandbox lifetime | Remote sandbox (E2B) | Code execution |
| CompositeBackend | Composite | Routes to different Backends | Hybrid architecture |
3. Recommended Solution: CloudDriveBackend
3.1 Architecture Design
3.2 Storage Structure
4. CloudDriveBackend Overview
CloudDriveBackend is a persistent file backend built on Supabase Storage with the following features:- Isolated storage space per user
- All files are automatically persisted
- Redis cache for acceleration
- Support for large files (images, documents, etc.)
/workspace/- Workspace files (Agent artifacts)/memory/- Long-term memory (user knowledge)
- Virtual path
/code/main.pymaps tousers/{user_id}/workspace/code/main.py - Virtual path
/memory/facts.jsonmaps tousers/{user_id}/memory/facts.json
4.1 Integration
BaseService manages CloudDriveBackend instances through Redis cache and a per-user Backend cache. Each user has an independent Backend instance, accessed viaget_backend(user_id).
5. Desktop Mode Support
When users are on the Desktop app, the system automatically selects the appropriate Backend based on the device type:- Desktop mode: Uses FilesystemBackend (local file system)
- Cloud mode: Uses CloudDriveBackend (Supabase Storage)
6. Frontend Cloud Drive API
The frontend interacts with the cloud drive through the following API endpoints:GET /api/storage/list?path=...- List filesPOST /api/storage/upload- Upload filesGET /api/storage/download?path=...- Download filesDELETE /api/storage/delete?path=...- Delete filesGET /api/storage/url?path=...- Get preview URL
7. Sandbox Artifact Sync
When the E2B sandbox generates files, the system automatically syncs the artifacts to the user’s cloud drive, stored under the/workspace/sandbox-output/{date}/ path.
8. Performance Optimization
8.1 Redis Cache Performance
| Operation | Without Cache | With Cache (hit) | Improvement |
|---|---|---|---|
| Read file | 200-500ms | 1-5ms | 100x |
| List directory | 100-300ms | 5-10ms | 30x |
| Check file existence | 100-200ms | 1ms | 100x |
8.2 Cache Strategy
- Workspace files TTL: 5 minutes
- Memory files TTL: 10 minutes
- Cache is updated immediately after writes/edits
9. Migration Steps
- Create Supabase Storage Bucket - Create the
workspacebucket in the Supabase Dashboard - Configure RLS Policies - Ensure users can only access their own files
- Configure Environment Variables - Set
SUPABASE_URL,SUPABASE_SERVICE_KEY,REDIS_URL(optional) - Create CloudDriveBackend - Implement the core Backend logic
- Modify BaseService - Integrate CloudDriveBackend
- Remove Old Code - Remove StateBackend and InMemoryStore related usage
10. Summary
| Item | Current State | Target State |
|---|---|---|
| Backend | StateBackend (in-memory) | CloudDriveBackend (Supabase) |
| Durability | ❌ Lost on service restart | ✅ Permanently saved |
| User Visibility | ❌ Frontend cannot access | ✅ Cloud drive experience |
| Cache | ❌ None | ✅ Redis acceleration |
| Memory | InMemoryStore | Supabase Storage (custom implementation) |