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 ==

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

case class FileConfig(maxFileSize: Long, allowedPaths: Option[Seq[String]], blockedPaths: Seq[String], followSymlinks: Boolean)

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 Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class FileEntry(name: String, path: String, isDirectory: Boolean, isFile: Boolean, isSymlink: Boolean, size: Long, lastModified: Long)

Information about a single file or directory entry.

Information about a single file or directory entry.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
object FileEntry

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
FileEntry.type
case class FileInfoResult(path: String, name: String, exists: Boolean, isFile: Boolean, isDirectory: Boolean, isSymlink: Boolean, size: Long, sizeHuman: String, createdAt: Long, lastModified: Long, lastAccessed: Long, isReadable: Boolean, isWritable: Boolean, isExecutable: Boolean, extension: Option[String])

Detailed information about a file.

Detailed information about a file.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
object FileInfoTool

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 Object
trait Matchable
class Any
Self type
case class ListDirectoryResult(path: String, entries: Seq[FileEntry], totalFiles: Int, totalDirectories: Int, truncated: Boolean)

Result from listing a directory.

Result from listing a directory.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self 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 Object
trait Matchable
class Any
Self type
case class ReadFileResult(path: String, content: String, size: Long, lines: Int, truncated: Boolean)

Result from reading a file.

Result from reading a file.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
object ReadFileTool

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 Object
trait Matchable
class Any
Self type
case class WriteConfig(allowedPaths: Seq[String], maxFileSize: Long, allowOverwrite: Boolean, createDirectories: Boolean)

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 Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all
case class WriteFileResult(path: String, bytesWritten: Long, created: Boolean, appended: Boolean)

Result from writing a file.

Result from writing a file.

Attributes

Companion
object
Supertypes
trait Serializable
trait Product
trait Equals
class Object
trait Matchable
class Any
Show all

Attributes

Companion
class
Supertypes
trait Product
trait Mirror
class Object
trait Matchable
class Any
Self type
object WriteFileTool

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 Object
trait Matchable
class Any
Self type

Value members

Concrete fields

val readOnlyTools: Seq[ToolFunction[_, _]]

All file system tools with default configuration (read-only, excludes write).

All file system tools with default configuration (read-only, excludes write).

Attributes