A MongoDB-Backed Virtual Filesystem for LangChain Deep Agents
A MongoDB-backed virtual filesystem for LangChain Deep Agents: bytes in object storage, search in Atlas with hybrid grep, rank fusion, chunking and sync.
This article is published in English.
Sources: MongoDB VFS for LangChain Deep Agents: A Searchable Filesystem for Agents
The expectations on AI agents have grown past answering questions. They're asked to carry out whole jobs: lay out a multi-step plan, study source files, create interim artifacts and delegate slices of the problem to peer agents, turning what used to take days into hours. Speed like that only works when the agent can move around its filesystem with confidence, searching, reading and updating files as it goes. The MongoDB virtual filesystem (VFS) for LangChain Deep Agents addresses that need. It ties a familiar filesystem view to MongoDB Atlas plus an object store underneath, such as an S3 bucket, so agents get a searchable workspace that outlives sessions, deployments and sub-agents. Developers on Deep Agents can treat Atlas as the data platform for their agents, with full-text and vector search close at hand.
The sections below explain the two concepts, show how the MongoDB backend operates inside an agent application, and point out where the pattern suits enterprise systems.
Deep Agents and their filesystem tools
Deep Agents form a harness on top of LangChain and LangGraph, made for complex, multi-step tasks. Planning, subagents and filesystem-style tools come built in, which lets an agent divide a large task into small actions instead of forcing it all into one context window. The built-in operations are:
lslists directories so the agent can see how things are laid outglobmatches files by path patterngreplooks inside file contentsreadreturns a filewriteandeditproduce or modify artifactsupload_filesanddownload_fileshandle bulk transfers
These tools sit behind a backend contract. The agent doesn't need to know whether files live on a local disk, in a LangGraph store, in object storage or behind some other persistence layer. It calls the same filesystem interface, and whatever backend is configured supplies the data.
What a virtual filesystem adds
A virtual filesystem presents data as logical paths while hiding where it's physically kept. An agent may see directories such as docs/, reports/ or projects/customer-a/, though the real bytes are in an object store and the searchable copy is in a database.
Navigating a filesystem happens in small steps, and that suits agents. Skipping the whole-corpus prompt, an agent lists a directory, narrows by filename pattern, searches for a concept, opens the relevant file and records its findings as a new artifact. Every step brings in only what it needs, so the agent stays within context limits and spends less. In that light, the virtual filesystem is a tool for managing context during agent work, beyond being a storage layer.
The package and how it routes work
The langchain-mongodb-deepagents-vfs package implements the Deep Agents BackendProtocol as a drop-in. An object-store-backed corpus appears to the agent as a filesystem, and each call is routed to the system that handles it best:
- Search-oriented operations (
grep,glob,ls) run against MongoDB Atlas. - Operations on file bytes (
read,write,edit,upload_files,download_files) go straight to the object store. - A background sync layer keeps the search representation in step with the object store.
That gives a clean split between source of truth and search index. The object store owns the original documents, and Atlas holds the searchable chunks, embeddings and path metadata that make the corpus discoverable.
One might ask why search should live in a separate system and not on an S3-compatible platform that bundles text, vector and hybrid search over the same data. The split is intended. Object storage excels at durable, inexpensive, long-lived file bytes, but it wasn't designed to maintain live indexes, rank hybrid queries and serve low-latency structured metadata lookups at the same time. Atlas is an operational database where search, vector search and hybrid ranking are indexed features from the start. The search plane therefore runs on software built for that role, and the object store continues with its own strength.
Hybrid search behind grep
Behind grep, the package pairs MongoDB Search with MongoDB Vector Search. Full-text matching shines for exact terms, identifiers, filenames and rare strings, while vectors shine for paraphrases and natural-language questions. Pairing them lets an agent hunt for a literal like MAX_RETRIES or ask where retries are configured, all through one interface.
The two result lists are merged by the $rankFusion aggregation stage in MongoDB. Because ranking stays inside the database, no client-side reranker is needed, and the extra agent round trip it would require disappears. There's a wider tradeoff here too. On an S3-compatible platform, getting full-text, vector and hybrid ranking usually means assembling several specialized systems: one engine for text, one vector database for embeddings, and a reranking layer to merge them, each with an indexing pipeline that has to track the source data. In Atlas one engine covers all three, and $rankFusion merges them in a single native query.
Chunking, formats and embeddings
Chunking is token-aware. Supported inputs are plain text, Markdown, PDF, DOCX, XLSX, XLS, PPTX and PPT. Each chunk retains positional metadata, namely source path, page number, character offsets and line information, which allows results to come back in the line-oriented format Deep Agents expect.
Embeddings default to Amazon Bedrock, with an OpenAI option through the package extras, and an application can inject any LangChain-compatible embedding implementation directly. A typical setup looks like this:
from deepagents import create_deep_agent
from langchain_mongodb_deepagents_vfs import MongoFilesystemBackend
backend = MongoFilesystemBackend(
s3_bucket_name="acme-docs",
mongodb_connection_string="mongodb+srv://<user>:<password>@<cluster>/",
)
agent = create_deep_agent(
tools=[],
instructions="You are a research assistant over the ACME documents corpus.",
backend=backend,
)
After that the agent uses its ordinary filesystem tools, with no custom MongoDB or S3 tools in its reasoning loop.
The two-plane architecture
Think of the system as two planes. Object storage is the data plane that holds file bytes, and MongoDB Atlas is the control and search plane covering metadata, chunks and retrieval indexes.
The figure shows how the backend sends file bytes through object storage and search operations through Atlas.
When the backend object is constructed, initialization continues in the background. Index provisioning, the first synchronization and watcher startup all run on a daemon thread. Pass-through file operations work right away, whereas search operations wait until the initial sync is ready. Ingestion proceeds like this:
- List objects under the configured S3 bucket and prefix.
- Download every eligible object.
- Pull out text with the parser for that format.
- Split the text into chunks that carry positional metadata.
- Create embeddings.
- Upsert chunks and metadata into Atlas.
- Provision or verify the Search and Vector Search indexes.
Chunks are 512 tokens with a 64-token overlap. ETags make the initial sync and watcher ingestion idempotent, so unchanged objects are skipped and not downloaded and embedded again.
Here's what each call does. ls asks Atlas for path metadata and groups it into directory entries. glob uses standard path-pattern rules to find matching files. grep has Atlas mix full-text and vector retrieval over the chunk corpus and return ranked hits. read pulls the current bytes from the object store instead of the index, and the difference is meaningful, since search results serve discovery and reads serve the original document.
Two watcher modes exist. A polling watcher checks the object store periodically and needs no extra AWS event infrastructure. An SQS watcher consumes S3 event notifications via Amazon SQS and suits lower-latency production synchronization.
Eventual consistency for search
Search is deliberately eventually consistent. A write succeeds in S3 first, then the watcher spots the change, chunks and embeds the object again and updates the indexes. Reads therefore show S3's state immediately, whereas grep, glob and ls may trail until sync and indexing complete.
A few rules of thumb follow for shared work. Read directly when the data is hot and shared, rely on edit for optimistic concurrency over shared files, and keep search for finding things once the corpus is stable. Giving each agent its own output namespace, like shared/outputs/<agent_id>/, further reduces clashes between parallel workers.
Where the pattern fits
Code exploration. Rather than being handed a huge code dump, a coding agent can step through a big repository: list the layout, locate files with glob, run hybrid grep for a concept or identifier, read the exact file and make an ETag-protected edit. Typical uses are onboarding to a repository, investigating incidents, analyzing dependencies and configuration, finding tests with targeted fixes, and generating documentation from code.
Document corpora. Policies, contracts, procedures, runbooks, product documents and customer files often pile up in object storage, and the backend offers an agent a filesystem-like way into them. A document agent might search for the refund policy covering enterprise customers, surface passages worded differently, open the source PDF or DOCX and write a summary with citations to another path. That suits retrieval-augmented generation when navigation is needed, not just one lookup.
Multi-agent teams. A coordinator can assign focused jobs to specialist subagents over one shared corpus. A security agent looks for risky code patterns, a documentation agent gathers deployment steps and configuration references, a test agent finds relevant test files and writes coverage notes, and a synthesis agent reads everything and compiles a report. All share one namespace, with Atlas as the discovery layer.
Living document stores. Enterprise content keeps changing: reports arrive, policies move, operational artifacts get revised. Since the watcher keeps Atlas aligned with the object store, an agent started later searches current content without rebuilding an index each run. That helps runbook assistants, compliance and policy monitoring, research assistants over constantly refreshed data, support agents on product and troubleshooting docs, and partner assistants working from shared implementation artifacts.
Durable workspaces. Deep Agents can save plans, scratch notes, summaries and final deliverables as files. Storing them in the object store and indexing them in Atlas yields a workspace that survives restarts and that people or other agents can inspect.
Production limits and extension points
Production use requires access control, tenant isolation, data residency, retention and audit rules to be enforced by the application, the storage configuration and the metadata model. The package itself is responsible for the Deep Agents filesystem contract and for the route from object store to Atlas search.
There's room to extend it: further object stores like Azure Blob Storage or Google Cloud Storage, more embedding providers and configurable strategies, extra document parsers and faster ingestion, sturdier watchers with backfill and fresher data, improved search quality, filtering, ranking and metadata, and fuller examples, benchmarks and deployment advice. A good rule is to keep anything storage-specific behind the object-store interface, so the chunker, embedder, sync logic and search router deal only with paths, bytes, metadata and search, never one provider's API.
Separation of concerns is the core idea. Agents see a single simple virtual filesystem, applications park large and varied documents in object storage as the source of truth for bytes, Atlas converts them into a searchable layer with metadata, full-text, vector and hybrid ranking, and the sync layer keeps discovery matched to the live corpus.