What is FileStorage::readOnly in Laravel 13?

In Laravel 13, the FileStorage::readOnly method is a feature of the Laravel AI SDK that provides AI agents with safe, read-only access to files on a specified filesystem disk .

It is designed to prevent an AI agent from accidentally or maliciously modifying your files. When you pass a disk to this method, the agent receives tools to list and read files, but it cannot write, copy, or delete anything .

How It Works in Practice?

You typically use it within an agent is tools() method. By default, it only grants read permissions. If you want the agent to be able to modify files, you must explicitly merge in additional, custom tools for those actions .

use LaravelAiToolsFileStorage;

public function tools(): iterable
{
   $disk = $this->workspace->disk();

   // Gives the agent safe read/list capabilities only
   return FileStorage::readOnly($disk)->merge([
       // You must explicitly opt-in to mutable actions
       new WorkspaceWriteFile($disk),
       new WorkspaceDeleteFile($disk),
   ]);
}

Don not Confuse It with Disk Configuration

It is important to note that this is different from the read-only => true configuration option you might see in your filesystems.php config file. That config option (which requires the league/flysystem-read-only package) makes an entire disk immutable at the framework level .

FileStorage::readOnly is specifically an AI SDK tool wrapper that controls what the agent is allowed to do with the disk, regardless of the disk is own configuration.

 

15 Views