Filestore Integration
Relevant source files
The following files were used as context for generating this wiki page:
Filestore Integration manages the persistence and retrieval of binary assets, system documentation, and execution artifacts within the superglue ecosystem. It provides an abstraction layer over cloud storage (typically S3) to handle file-based knowledge ingestion for agents and file processing capabilities for deterministic tools.
The system facilitates three primary use cases:
- Knowledge Ingestion: Storing scraped or uploaded documentation for systems.
- Tool Execution: Binding files to tool inputs for processing by APIs, databases, or file servers.
- Agent Context: Allowing the AI agent to reference specific files using stable aliases and URI patterns.
Architecture and File Service
The Filestore module provides a centralized FileService used by both the API and core system logic. The SystemManager utilizes this service to download and process documentation files during search operations.
Component Overview
| Component | Function |
|---|---|
FileService | Provides methods to upload, download, and build storage URIs. |
FileReference | Stores metadata about a file, including its storage URI, status, and source. |
SystemManager | Loads file-based documentation from storage to enrich agent knowledge. |
DocumentationFiles | A record of file IDs grouped by type (upload, scrape, or OpenAPI). |
Sources: packages/core/systems/system-manager.ts:16-17, packages/core/api/systems-documentation.ts:25-50
Storage URI Structure
Storage URIs are built using organization IDs to ensure multi-tenant isolation.
- Raw Storage URI: Used for initial uploads or unprocessed files.
- Processed Storage URI: Used for files that have undergone text extraction or transformation.
Sources: packages/core/systems/system-manager.ts:165-170, packages/core/api/systems-documentation.ts:54-56
Documentation Lifecycle
Files enter the filestore through two main paths: manual user uploads and automated background scrapes.
Scrape and Upload Flow
The following diagram illustrates how external documentation is processed into the filestore.
runDocumentationScrape Function
This function executes the core logic for background ingestion:
- Updates the
FileReferencestatus toPROCESSING. - Uses
DocumentationFetcherto extract text from a provided URL. - Uploads the resulting
.txtcontent viaFileService. - Optionally detects and creates separate file references for OpenAPI specs found during the scrape.
- Updates metadata with timestamps and the final storage URI.
Sources: packages/core/api/systems-documentation.ts:80-130
File Statuses
File processing is asynchronous. The system tracks files through the following states:
PENDING: The reference is created but no content is stored.PROCESSING: An active job (e.g., scraping) is running.COMPLETED: The file is available in the filestore and ready for use.FAILED: Processing encountered an error, which is stored in the reference metadata.
Sources: packages/core/api/systems-documentation.ts:175-185, packages/core/api/response-helpers.ts:145-150
Agent and Tool Integration
The superglue agent interacts with the filestore to bind files to execution payloads.
File Reference Syntax
The agent uses a specific syntax to reference files in tool configurations and call_system requests.
file::<key>.raw: References the original binary bytes.file::<key>.extracted: References the parsed text content (e.g., from a PDF or CSV).file::<key>.base64: Encodes the file content as a base64 string for text-based APIs.
Sources: packages/web/src/lib/agent/registries/tool-registry.ts:110-125, packages/web/src/lib/agent/agent-prompts.ts:48-52
Binding Files to Tool Runs
When calling run_tool or build_tool, files must be passed in the top-level files argument rather than inside the standard JSON payload.
UI and API Features
Knowledge Base Management
The ContextSection component in the web frontend provides a visual interface for managing a system's knowledge base. It allows users to:
- Upload multiple files simultaneously.
- Monitor processing statuses (spinner for
PROCESSING, redXforFAILED). - Preview file content using the
FileContentViewer. - Delete documentation files, which triggers a cascading removal via the
deleteDocumentationFileAPI handler.
Sources: packages/web/src/components/systems/sections/ContextSection.tsx:50-120, packages/core/api/systems-documentation.ts:411-450
API Endpoints
| Method | Path | Description |
|---|---|---|
POST | /systems/:id/file-references | Initiates document upload and returns presigned URLs. |
GET | /systems/:id/file-references | Lists all files (scrapes/uploads) linked to a system. |
DELETE | /systems/:id/file-references/:fileId | Removes a file from storage and unlinks it from the system. |
POST | /systems/:id/documentation/scrape | Manually triggers a background scrape job for a URL. |
Sources: packages/core/api/systems-documentation.ts:601-650
Implementation Details
File Reference Validation
The validateUploadDocumentationBody helper ensures that:
- Requests contain a
filesarray. - The array size is between 1 and 20 files.
- Each file has a valid extension.
Sources: packages/core/api/response-helpers.ts:176-193
Date Transformation
API responses involving system files are normalized using transformSystemDates to ensure consistency between the datastore (Date objects) and the frontend (ISO strings).
Sources: packages/core/api/response-helpers.ts:21-28
Filestore integration ensures that the superglue platform can handle complex, data-heavy workflows by maintaining a reliable link between external file sources, system documentation, and the execution environment.