LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
  • Agent
  • Middleware
  • Backends
  • Sandboxes
  • Skills
  • Subagents
  • Types
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
  • Vitest
⌘I

LangChain Assistant

Ask a question to get started

Enter to send•Shift+Enter new line

Menu

OverviewAgentMiddlewareBackendsSandboxesSkillsSubagentsTypes
Modal
Daytona
Deno
Node VFS
Sandbox Standard Tests
Vitest
Language
Theme
JavaScriptdeepagentsnodecreateFilesystemMiddleware
Functionā—Since v1.10

createFilesystemMiddleware

Create middleware that provides built-in filesystem tools and filesystem-aware prompt guidance.

By default, the middleware registers every built-in filesystem tool listed in FILESYSTEM_TOOL_NAMES. Use FilesystemMiddlewareOptions.tools to narrow that set for read-only, search-only, or otherwise restricted agents. The allowlist only controls built-in filesystem tools; custom tools from the agent or other middleware are left untouched.

The middleware also filters tools whose backend capabilities are unavailable at request time. In particular, execute is only visible when the resolved backend supports command execution. The filesystem prompt is generated from the final visible filesystem tools so the model is not instructed to call tools it cannot see.

Copy
createFilesystemMiddleware(
  options: FilesystemMiddlewareOptions = {}
): AgentMiddleware<StateSchema<__type>, undefined, unknown, DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "ls"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, strip>>, __type, unknown, ToolMessage<MessageStructure<MessageToolSet>> | __type[] | __type[], unknown, "read_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "write_file"> | DynamicStructuredTool<ZodPreprocess<ZodObject<__type, strip>>, __type, unknown, string | ToolMessage<MessageStructure<MessageToolSet>> | Command<unknown, __type, string>, unknown, "edit_file"> | DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "glob"> | DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string | ToolMessage<MessageStructure<MessageToolSet>>, unknown, "grep"> | DynamicStructuredTool<ZodObject<__type, strip>, __type, __type, string, unknown, "execute">[], readonly []>

Used in Docs

  • Prebuilt middleware

Parameters

NameTypeDescription
optionsFilesystemMiddlewareOptions
Default:{}

Filesystem middleware configuration.

Example

Copy
const middleware = createFilesystemMiddleware({
  tools: ["read_file", "ls", "glob", "grep"],
});
View source on GitHub