How to Add File Storage to Smolagents
Smolagents is a fast way to build AI agents, but it lacks persistent storage by default. This guide shows you how to add a cloud layer so your agents can save artifacts, handle large documents, and share results with your team. This guide covers smolagents file storage with practical examples.
Why Smolagents Need External Storage: smolagents file storage
Smolagents is a lightweight library from Hugging Face that focuses on logic and code rather than complex infrastructure. But in the real world, agents need to handle files that last longer than a single script execution. Without external storage, an agent that makes a chart or writes a report has nowhere to put it except the local disk. This is a problem in production because local disks are usually temporary (like in a Docker container or a serverless function) and users can't easily reach those files anyway. If the container restarts, that data is gone. You've wasted tokens and time, and debugging becomes a nightmare because you can't see the intermediate files or logs the agent made before it crashed or finished. Adding a cloud storage layer lets your agents:
- Save artifacts: Keep images, CSVs, and reports in a cloud space that stays alive even if the agent container stops. * Share with humans: Give users a link they can actually click, rather than a local file path they can't reach. * Work together: Let multiple agents read and write to the same shared folder so they can pass data back and forth and keep track of project state.
Helpful references: Fast.io Workspaces, Fast.io Collaboration, and Fast.io AI.
What to check before scaling smolagents file storage
The easiest way to add storage is via the Model Context Protocol (MCP). Smolagents supports MCP, so you can use pre-built tool servers without writing new code. Fast.io provides a free MCP server with 251 file operations tools.
Prerequisites:
- A Fast.io account (Free tier includes 50GB storage). 2. The
smolagentsPython library installed. Here is how to configure a smolagent with full file system access:
from smolagents import CodeAgent, HfApiModel, Tool
from fastio_mcp import FastIOServer # Hypothetical wrapper for connection
### 1. Initialize the Storage MCP Server
### Fast.io provides an SSE endpoint for the agent to connect to
storage_tools = FastIOServer.connect(
api_key="your_fastio_key",
mount_path="/my-agent-workspace"
)
### 2. Create the Agent with Storage Tools
### The agent now has tools like 'upload_file', 'list_files', 'read_file'
agent = CodeAgent(
tools=[*storage_tools],
model=HfApiModel()
)
### 3. Run a Task requiring storage
agent.run(
"Analyze the CSV in 'sales_data/' and save a summary chart to 'reports/'"
)
In this setup, the agent knows it can use list_files to find the CSV and upload_file to save the chart. The files are instantly available in your web dashboard. This approach means you don't have to write boilerplate code for S3 buckets, IAM roles, or local folders. The MCP server handles the communication between the agent and the storage, so you can scale across different environments without making the codebase messy.
Building a Custom Python Tool
If you want more control or want to limit the agent to specific actions (like "save only"), you can define a custom tool using the Fast.io API. This is useful if you need to add custom logic, like checking a file's format before uploading or sorting files into dated folders. You can also add your own error handling or send a Slack notification whenever the agent finishes a file. Using the API directly also lets you use features like branded links, expiration dates, or webhooks for new files. ```python from smolagents import tool import requests
@tool def save_artifact(filename: str, content: str) -> str: """ Saves text content to cloud storage and returns a shareable link. Args: filename: The name of the file (e.g., 'report.md') content: The text content to save """ ### Fast.io API endpoint for upload url = "https://api.fast.io/v1/files/upload"
response = requests.post(
url,
headers={"Authorization": "Bearer YOUR_API_KEY"},
files={"file": (filename, content)}
)
if response.status_code == 200:
return f"File saved! View at: {response.json()['share_link']}"
return "Error saving file."
Add the custom tool to your agent
agent = CodeAgent(tools=[save_artifact], model=HfApiModel()) ```
Using Intelligence Mode for RAG
Storage isn't just about saving output; it's about reading input. When you connect smolagents to a Fast.io workspace with Intelligence Mode enabled, the storage layer becomes a useful part of the workflow. Instead of just reading raw bytes, your agent can ask questions about the files. This is helpful when dealing with large datasets or long documents that are too big for the model's context window. This "chat with your files" capability means the agent only grabs the info it needs for the current task.
How it works:
- Auto-Indexing: Any file uploaded to the workspace (PDFs, docs, spreadsheets) is automatically indexed. 2. Semantic Search: The agent can use a
search_workspacetool to find information across thousands of files using natural language. 3. Citation: The storage layer returns the exact source text and file location, so the agent can show where it got its information. This gives your agent long-term memory without a separate vector database like Pinecone. The storage handles the indexing, which keeps your setup simple and costs down for your team.
Comparison: Local vs. S3 vs. Fast.io MCP
The right storage depends on where you're deploying your agent.
| Feature | Local Filesystem | Generic S3 | Fast.io MCP |
|---|---|---|---|
| Persistence | Low (Ephemeral) | High | High |
| Setup Difficulty | None | High (Boto3 code) | Low (Native Tool) |
| Agent Usability | High | Low (Complex API) | High (251 Tools) |
| RAG/Search | None | None | Built-in |
| Human Access | Difficult | Console Access | Web Dashboard |
For local prototypes, the filesystem works fine. For production agents that need to work with humans or other agents, a cloud storage service designed for agents is usually the easiest way to go.
Frequently Asked Questions
How do I authenticate smolagents with Fast.io?
You authenticate by passing your API key to the MCP client or custom tool. You can use scoped API keys so your agent only sees the files it needs for its job.
Can smolagents read files uploaded by humans?
Yes. If you upload a file to the shared workspace via the web interface, the agent can find and read it right away. This makes it easy for humans to provide input and let agents do the rest.
Is there a cost for agent storage?
Fast.io has a Free Tier for agents that includes 50GB of storage and 5,000 monthly credits. This is enough for most dev projects and you don't need a credit card to start.
Does smolagents support MCP natively?
Yes, smolagents has support for the Model Context Protocol (MCP), so it can connect to any standard MCP server, including the Fast.io server.
What file types are supported for agent storage?
Fast.io supports all file types. For Intelligence Mode (RAG), it supports common formats like PDF, DOCX, TXT, CSV, and Markdown, automatically extracting text for the agent to search.
Related Resources
Run Add File Storage To Smolagents workflows on Fast.io
Stop losing agent artifacts. Connect your smolagents to persistent cloud storage with built-in RAG and sharing.