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.
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 []>| Name | Type | Description |
|---|---|---|
options | FilesystemMiddlewareOptions | Default: {}Filesystem middleware configuration. |
const middleware = createFilesystemMiddleware({
tools: ["read_file", "ls", "glob", "grep"],
});