Agents APIWorkspace
Files
Give the agent files and take back what it makes.
Every session has a disk of its own. You upload files to it, the agent works with them and leaves its results there, and you download what you need. Each call moves one file, named by its path in the workspace.
The workspace
/work ← the agent's working directory
├── payments/ ← a repository, cloned into /work/<repo name>
├── uploads/ ← your files
└── out/ ← what the agent leaves for you- The session's disk holds 5 GiB and is mounted at
/workin every sandbox the session runs in. - Each repository is cloned into
/work/<repo name>. See Repositories and patches. - Put your files in
uploads/. The agent is told to leave what you ask for inout/. - A path in a file call is relative to
/work:uploads/photo.png,out/report.md,payments/README.md.
You don't need to explain this to the agent. When its sandbox starts, LatentStack writes a note into its instructions with this layout, how files move, what a pause keeps and what the network allows. Your own instructions come after the note and win where the two meet.
Upload a file
import { readFile } from "node:fs/promises"
const photo = await readFile("photo.png")
const file = await sessions.uploadFile(session.id, "uploads/photo.png", photo, { contentType: "image/png" })
console.log(file.path, file.size, file.sha256)- The file is stored at that path. Missing folders are created, and an existing file is replaced.
- The answer is the stored file:
{ object: "agent.file", path, size, sha256 }. - TypeScript takes a
BloborFile, anArrayBuffer, a typed array such as a Node.jsBuffer, or a string. A string is the file's content, as UTF-8. - Python takes
bytes, an open binary file, or a path. Astris the path of a file to read, not content. - One upload is at most 1 GiB. A larger file fails with
file_too_large.
Show the agent an image
Name workspace images in files when you send a message. The model sees them together with your text.
await sessions.message(session.id, "Make a 3-second mp4 that zooms into this photo. Save it as out/zoom.mp4.", {
files: ["uploads/photo.png"],
})- PNG, JPEG, GIF or WebP only. Up to 10 images per message, 5 MiB each and 20 MiB in all.
- Any other file, such as a CSV or a video, the agent reads at its path. Name the path in your message, not in
files.
List and download
import { writeFile } from "node:fs/promises"
import { basename } from "node:path"
const { data } = await sessions.listFiles(session.id, { prefix: "out/" })
for (const file of data) {
const blob = await sessions.downloadFile(session.id, file.path)
await writeFile(basename(file.path), Buffer.from(await blob.arrayBuffer()))
}- A listing is
{ object, data: [{ path, size, modified_at }], truncated }, in path order..gitfolders are left out. prefixkeeps only paths that start with it.limitis up to 1,000, the default. Whentruncatedis true there were more files; narrow the prefix.- A download is the whole file: a
Blobin TypeScript,bytesin Python. Its content type comes from the file's extension.
Delete a file
await sessions.deleteFile(session.id, "uploads/photo.png")A path with no file fails with not_found. You don't need to clean up before deleting a session: its disk goes with it.
Limits, and paused sessions
| Limit | Value |
|---|---|
| One upload | 1 GiB |
| The session's disk | 5 GiB, for everything in the workspace |
| Images on one message | 10, at most 5 MiB each and 20 MiB in all |
| One listing | 1,000 files |
Paused and starting sessions
File calls are served by the session's sandbox. A paused session, or one that's still starting, has none to serve them, and file calls fail with conflict. Send a paused session a message to resume it, then try again once its status is idle, running or waiting.
A message that names files can go to a paused session. It resumes the session and attaches the images once it runs. If an image is missing or too large by then, that message is dropped and the session's error says why. A new session that hasn't started yet refuses a message with files with conflict: there is nothing uploaded to attach.
Over HTTP
| Request | Does |
|---|---|
| GET /v1/agents/sessions/{id}/files?prefix=&limit= | Lists files. |
| PUT /v1/agents/sessions/{id}/files/{path} | Stores the request body at path. Needs a Content-Length. Answers 201 with the stored file. |
| GET /v1/agents/sessions/{id}/files/{path} | Downloads the file. |
| DELETE /v1/agents/sessions/{id}/files/{path} | Removes the file. Answers 204. |
To attach images over HTTP, list their paths in the message input's files.