Skip to content

API Reference parrot.tools.filemanager

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.filemanager

View source

FileManagerTool and FileManagerToolkit — tools for AI agents to interact with file systems.

Implementations live in parrot.interfaces.file:

  • LocalFileManager / TempFileManager: always available (stdlib only)
  • S3FileManager / GCSFileManager: lazy-loaded (require aioboto3 / google-cloud-storage)

Preferred API: FileManagerToolkit — each file operation is a separate, focused tool. Legacy API: FileManagerTool — single tool with an operation dispatch field (deprecated).

Alias AbstractTool

Re-exported from parrot.tools.abstract.AbstractTool.

Alias AbstractToolArgsSchema

Re-exported from parrot.tools.abstract.AbstractToolArgsSchema.

Alias AbstractToolkit

Re-exported from parrot.tools.toolkit.AbstractToolkit.

Alias BatchItemResult

Re-exported from parrot.interfaces.file.batch.BatchItemResult.

Alias BatchSummary

Re-exported from parrot.interfaces.file.batch.BatchSummary.

Class FileManagerFactory

Factory for creating file managers.

Thin delegate over navigator.utils.file.FileManagerFactory. Maps the historical parrot-side key "fs" to the upstream "local" key; forwards all other keys verbatim. Parrot-native managers ("sharepoint", "onedrive", "gdrive") are resolved locally and never forwarded upstream, which does not know them (FEAT-603).

Method FileManagerFactory.create

Create a file manager instance.

create(manager_type: ManagerType, **kwargs: Any) -> FileManagerInterface

Parameter Type Default Description
manager_type ManagerType "fs", "temp", "s3", "gcs" (upstream navigator managers) or "sharepoint", "onedrive", "gdrive" (parrot-native Graph / Google Drive managers, lazily imported).
**kwargs Any {} Forwarded to the manager constructor.

Returns: FileManagerInterface — A FileManagerInterface instance.

Raises:

  • ValueError — If manager_type is not recognised (the message lists every valid key).

Alias FileManagerInterface

Re-exported from parrot.interfaces.file.FileManagerInterface.

Class FileManagerTool

Tool for AI agents to interact with file systems.

.. deprecated:: FileManagerTool uses a multi-operation dispatch pattern (an operation field that routes to one of nine sub-operations). This flat schema confuses LLMs because every call must include the operation key and the parameters vary by operation. Prefer :class:FileManagerToolkit instead — it exposes each operation as a separate, focused tool with a minimal, unambiguous schema.

Provides secure file operations across different storage backends:

  • 'fs': Local filesystem
  • 'temp': Temporary storage (auto-cleanup)
  • 's3': AWS S3 buckets
  • 'gcs': Google Cloud Storage

Usage Pattern: The LLM must specify an 'operation' field to route to the correct action. Each operation has specific required and optional fields.

Parameter Type Default Description
manager_type ManagerType 'fs' Type of file manager ("fs", "temp", "s3", "gcs", "sharepoint", "onedrive", "gdrive").
default_output_dir str None Default directory for file operations.
allowed_operations Optional[set] None Set of allowed operations (None = all allowed).
max_file_size int 100 * 1024 * 1024 Maximum file size in bytes.
auto_create_dirs bool True Automatically create directories.
**manager_kwargs {} Additional arguments for the specific manager.

Attributes:

Attribute Type Description
name str
args_schema type[AbstractToolArgsSchema]
description str

Class FileManagerToolArgs

Arguments schema for FileManagerTool.

The operation field determines which file operation to perform. Each operation requires different additional fields.

Attributes:

Attribute Type Description
operation Literal['list', 'upload', 'download', 'copy', 'delete', 'exists', 'get_url', 'get_metadata', 'create', 'find', 'batch_upload', 'batch_download']
path Optional[Union[str, Path]]
pattern Optional[str]
source_path Optional[str]
destination Optional[str]
destination_name Optional[str]
source Optional[str]
content Optional[str]
encoding Optional[str]
expiry_seconds Optional[int]
keywords Optional[Union[str, List[str]]]
extension Optional[str]
prefix Optional[str]
items Optional[List[Dict[str, str]]]

Class FileManagerToolkit

Toolkit for AI agents to interact with file systems — preferred API.

Exposes each file operation as a separate, focused tool with a minimal schema. LLMs no longer need to know about an operation dispatch field; they simply call the right tool directly.

Tool names (with tool_prefix="fs"):

  • fs_list_files — list files in a directory
  • fs_upload_file — upload a local file to storage
  • fs_download_file — download a file from storage
  • fs_copy_file — copy a file within storage
  • fs_delete_file — delete a file from storage
  • fs_file_exists — check whether a file exists
  • fs_get_file_url — get a URL to access a file
  • fs_get_file_metadata — fetch detailed file metadata
  • fs_create_file — create a new file with text content
  • fs_find_files — find files by keyword(s)/extension under a prefix
  • fs_batch_upload — upload many local files in one call
  • fs_batch_download — download many files in one call

Example::

toolkit = FileManagerToolkit(manager_type="fs")
tools = toolkit.get_tools()   # returns 9 AbstractTool instances
result = await toolkit.list_files(path="docs", pattern="*.md")
Parameter Type Default Description
manager_type ManagerType 'fs' Storage backend — one of "fs", "temp", "s3", "gcs", "sharepoint", "onedrive", "gdrive".
default_output_dir Optional[str] None Default directory for resolving relative paths. Defaults to parrot.conf.OUTPUT_DIR.
allowed_operations Optional[Set[str]] None Restrict which operations are exposed as tools. Pass a subset of {"list", "upload", "download", "copy", "delete", "exists", "get_url", "get_metadata", "create"}. None means all operations are allowed (default).
max_file_size int 100 * 1024 * 1024 Maximum file size in bytes (default 100 MB). Enforced on create_file and upload_file.
auto_create_dirs bool True Automatically create parent directories when writing files (default True).
**manager_kwargs Any {} Extra keyword arguments forwarded to the backend manager constructor (e.g. base_path, bucket).

Attributes:

Attribute Type Description
tool_prefix Optional[str]
allowed_operations Set[str]
manager FileManagerInterface

Method FileManagerToolkit.list_files

List files in a directory on the configured storage backend.

Returns a dictionary with keys files (list of file info dicts), count (int), directory (str), and pattern (str).

list_files(path: str = '', pattern: str = '*') -> Dict[str, Any]

Parameter Type Default Description
path str '' Directory path to list. Defaults to the root of the configured storage.
pattern str '*' Glob pattern to filter filenames (e.g. "*.pdf"). Defaults to "*" (all files).

Returns: Dict[str, Any] — Dict containing files, count, directory, pattern.

Method FileManagerToolkit.upload_file

Upload a local file to the configured storage backend.

Checks that the file exists and that its size does not exceed the configured max_file_size limit before uploading.

upload_file(source_path: str, destination: Optional[str] = None, destination_name: Optional[str] = None) -> Dict[str, Any]

Parameter Type Default Description
source_path str Absolute or relative path to the local file to upload.
destination Optional[str] None Destination directory on the backend. Defaults to the toolkit's default_output_dir.
destination_name Optional[str] None Custom name for the uploaded file. Defaults to the source filename.

Returns: Dict[str, Any] — Dict with keys uploaded, name, path, size, content_type, and url.

Raises:

  • ValueError — If source_path is missing or the file is too large.
  • FileNotFoundError — If the source file does not exist on disk.

Method FileManagerToolkit.download_file

Download a file from the storage backend to the local filesystem.

download_file(path: str, destination: Optional[str] = None) -> Dict[str, Any]

Parameter Type Default Description
path str Path of the file on the storage backend.
destination Optional[str] None Local path where the file will be saved. Defaults to the toolkit's default_output_dir using the source filename.

Returns: Dict[str, Any] — Dict with keys downloaded, source, destination, and size (bytes saved on disk).

Raises:

  • ValueError — If path is empty.

Method FileManagerToolkit.copy_file

Copy a file within the configured storage backend.

copy_file(source: str, destination: str) -> Dict[str, Any]

Parameter Type Default Description
source str Source path of the file to copy.
destination str Destination path for the copied file.

Returns: Dict[str, Any] — Dict with keys copied, source, destination, name, size, and url.

Raises:

  • ValueError — If either source or destination is empty.

Method FileManagerToolkit.delete_file

Delete a file from the configured storage backend.

delete_file(path: str) -> Dict[str, Any]

Parameter Type Default Description
path str Path of the file to delete on the storage backend.

Returns: Dict[str, Any] — Dict with keys deleted (bool) and path (str).

Raises:

  • ValueError — If path is empty.

Method FileManagerToolkit.file_exists

Check whether a file exists on the configured storage backend.

file_exists(path: str) -> Dict[str, Any]

Parameter Type Default Description
path str Path of the file to check.

Returns: Dict[str, Any] — Dict with keys exists (bool) and path (str).

Raises:

  • ValueError — If path is empty.

Method FileManagerToolkit.get_file_url

Get a URL to access a file on the configured storage backend.

For cloud backends (S3, GCS) this generates a pre-signed URL valid for expiry_seconds. For local backends it typically returns the file path or a static URL.

get_file_url(path: str, expiry_seconds: int = 3600) -> Dict[str, Any]

Parameter Type Default Description
path str Path of the file on the storage backend.
expiry_seconds int 3600 URL validity duration in seconds (default 3 600 = 1 hour).

Returns: Dict[str, Any] — Dict with keys url (str), path (str), and expiry_seconds (int).

Raises:

  • ValueError — If path is empty.

Method FileManagerToolkit.get_file_metadata

Retrieve detailed metadata for a file on the storage backend.

get_file_metadata(path: str) -> Dict[str, Any]

Parameter Type Default Description
path str Path of the file whose metadata should be fetched.

Returns: Dict[str, Any] — Dict with keys name, path, size, content_type, modified_at (ISO-8601 string or None), and url.

Raises:

  • ValueError — If path is empty.

Method FileManagerToolkit.create_file

Create a new text file on the configured storage backend.

Encodes content using encoding, checks the resulting byte length against max_file_size, then writes the file and returns metadata.

create_file(path: str, content: str, encoding: str = 'utf-8') -> Dict[str, Any]

Parameter Type Default Description
path str Destination path for the new file (relative to default_output_dir unless absolute).
content str Text content to write to the file.
encoding str 'utf-8' Character encoding for the content (default "utf-8").

Returns: Dict[str, Any] — Dict with keys created (True), name, path, size, content_type, and url.

Raises:

  • ValueError — If path or content is empty, or if the encoded content exceeds max_file_size.

Method FileManagerToolkit.find_files

Find files whose name contains ALL keywords and ends with extension, under prefix.

Uses the backend's server-side search when available (SharePoint / OneDrive), otherwise lists and filters.

find_files(keywords: Optional[Union[str, List[str]]] = None, extension: Optional[str] = None, prefix: Optional[str] = None) -> Dict[str, Any]

Parameter Type Default Description
keywords Optional[Union[str, List[str]]] None One substring or a list of substrings that must all appear in the file name.
extension Optional[str] None File extension filter, e.g. ".csv".
prefix Optional[str] None Only search under this folder/path prefix.

Returns: Dict[str, Any] — Dict with files (list of file info dicts, same shape as list_files) and count.

Method FileManagerToolkit.batch_upload

Upload many local files at once; one failing file never fails the batch.

batch_upload(items: List[Dict[str, str]]) -> Dict[str, Any]

Parameter Type Default Description
items List[Dict[str, str]] [{"source": "<local file path>", "destination": "<storage path incl. file name>"}, ...].

Returns: Dict[str, Any] — Dict with total, succeeded, failed, skipped, aborted and items (per-file result with state, error and metadata), in input order.

Method FileManagerToolkit.batch_download

Download many files at once; one failing file never fails the batch.

batch_download(items: List[Dict[str, str]]) -> Dict[str, Any]

Parameter Type Default Description
items List[Dict[str, str]] [{"source": "<storage path>", "destination": "<local path, optional>"}, ...].

Returns: Dict[str, Any] — Same shape as batch_upload.

Attribute ManagerType

Alias OUTPUT_DIR

Re-exported from parrot.conf.OUTPUT_DIR.

Alias ToolResult

Re-exported from parrot.tools.abstract.ToolResult.

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally