org.llm4s.toolapi.builtin.filesystem
File system tools for reading, writing, and managing files.
These tools provide safe access to the file system with configurable path restrictions and size limits.
== Configuration ==
All file system tools accept FileConfig for read operations or WriteConfig for write operations. These configurations allow:
- Path allowlists and blocklists for security
- File size limits
- Symbolic link handling
== Available Tools ==
- ReadFileTool: Read file contents
- WriteFileTool: Write content to files (requires explicit path allowlist)
- ListDirectoryTool: List directory contents
- FileInfoTool: Get file metadata
Attributes
- Example
-
import org.llm4s.toolapi.builtin.filesystem._ import org.llm4s.toolapi.ToolRegistry // Read-only tools with default config (blocked: /etc, /var, /sys, /proc, /dev) val readOnlyTools = new ToolRegistry(Seq( ReadFileTool.tool, ListDirectoryTool.tool, FileInfoTool.tool )) // Tools with custom restrictions val config = FileConfig( maxFileSize = 512 * 1024, allowedPaths = Some(Seq("/tmp", "/home/user/workspace")) ) val restrictedTools = new ToolRegistry(Seq( ReadFileTool.create(config), ListDirectoryTool.create(config) )) // Write tool with explicit allowlist val writeConfig = WriteConfig( allowedPaths = Seq("/tmp/output"), allowOverwrite = true ) val writeTools = new ToolRegistry(Seq( WriteFileTool.create(writeConfig) ))
Members list
Type members
Classlikes
Configuration for file system tools.
Configuration for file system tools.
Value parameters
- allowedPaths
-
Paths that are allowed to be accessed. None means any path.
- blockedPaths
-
Paths that are blocked from access (takes precedence over allowedPaths)
- followSymlinks
-
Whether to follow symbolic links (default: false for security)
- maxFileSize
-
Maximum file size to read in bytes (default: 1MB)
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Information about a single file or directory entry.
Information about a single file or directory entry.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Detailed information about a file.
Detailed information about a file.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
FileInfoResult.type
Tool for getting detailed file information.
Tool for getting detailed file information.
Features:
- File metadata (size, timestamps)
- File type detection
- Permission checks
- Human-readable size formatting
Attributes
- Example
-
import org.llm4s.toolapi.builtin.filesystem._ val infoTool = FileInfoTool.create(FileConfig( allowedPaths = Some(Seq("/tmp")) )) val tools = new ToolRegistry(Seq(infoTool)) agent.run("Get info about /tmp/data.txt", tools) - Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
FileInfoTool.type
Result from listing a directory.
Result from listing a directory.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
ListDirectoryResult.type
Tool for listing directory contents.
Tool for listing directory contents.
Features:
- List files and directories
- File metadata (size, modified time)
- Configurable max entries
- Path restrictions
Attributes
- Example
-
import org.llm4s.toolapi.builtin.filesystem._ val listTool = ListDirectoryTool.create(FileConfig( allowedPaths = Some(Seq("/tmp", "/home/user")) )) val tools = new ToolRegistry(Seq(listTool)) agent.run("List files in /tmp", tools) - Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
ListDirectoryTool.type
Result from reading a file.
Result from reading a file.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
ReadFileResult.type
Tool for reading file contents.
Tool for reading file contents.
Features:
- Configurable size limits
- Path restrictions for security
- Optional line limit
- Encoding detection
Attributes
- Example
-
import org.llm4s.toolapi.builtin.filesystem._ val readTool = ReadFileTool.create(FileConfig( maxFileSize = 512 * 1024, allowedPaths = Some(Seq("/tmp", "/home/user/workspace")) )) val tools = new ToolRegistry(Seq(readTool)) agent.run("Read the contents of /tmp/data.txt", tools) - Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
ReadFileTool.type
Configuration for write operations.
Configuration for write operations.
Value parameters
- allowOverwrite
-
Whether to allow overwriting existing files
- allowedPaths
-
Paths where writing is allowed (required for safety)
- createDirectories
-
Whether to create parent directories if they don't exist
- maxFileSize
-
Maximum file size to write in bytes
Attributes
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Result from writing a file.
Result from writing a file.
Attributes
- Companion
- object
- Supertypes
-
trait Serializabletrait Producttrait Equalsclass Objecttrait Matchableclass AnyShow all
Attributes
- Companion
- class
- Supertypes
-
trait Producttrait Mirrorclass Objecttrait Matchableclass Any
- Self type
-
WriteFileResult.type
Tool for writing file contents.
Tool for writing file contents.
IMPORTANT: This tool requires explicit path allowlisting for safety. It will not write to any path that is not in the allowedPaths list.
Features:
- Requires explicit path allowlist
- Optional append mode
- Auto-creates parent directories
- Size limits
Attributes
- Example
-
import org.llm4s.toolapi.builtin.filesystem._ val writeTool = WriteFileTool.create(WriteConfig( allowedPaths = Seq("/tmp", "/home/user/output") )) val tools = new ToolRegistry(Seq(writeTool)) agent.run("Write 'Hello World' to /tmp/output.txt", tools) - Supertypes
-
class Objecttrait Matchableclass Any
- Self type
-
WriteFileTool.type
Value members
Concrete fields
All file system tools with default configuration (read-only, excludes write).
All file system tools with default configuration (read-only, excludes write).