Based on AgentRun release · Synced .
Uploads
A run's input files. Send one in one call, its bytes the body and its path in the query:
curl -s "$AGENTRUN_BASE_URL/files?path=plan.md" -H "authorization: Bearer $AGENTRUN_API_KEY" --data-binary @plan.md
It answers 201 with the file, ready, under file: its file_id, size_bytes (the body's length) and sha256
(the body's own).
Its content_type is the query's content_type, else the request's own type when it names one (not
application/octet-stream, not curl's application/x-www-form-urlencoded), else its path's extension's, as a run's files
are served (plan.md is text/markdown; charset=utf-8), else application/octet-stream. A sha256 in the query is
checked against the bytes (422 input_invalid when they differ). A multipart form (curl -F) is 415: send the bytes
themselves. Without path a body that is not JSON is 422 at path, saying how to call. Idempotency-Key replays the
first file for the same bytes.
Or, as the contract has it, in two calls: POST /v2/files with the JSON {path, size_bytes, content_type?, sha256?}
reserves the file, pending, and answers where to send its bytes, upload.url; PUT them there as the raw body, any
content type. Their length must be size_bytes and their SHA-256 the sha256 given (422 input_invalid at that
field), and then the file is ready. upload.url is a path from the server's root, /v2/files/{id}: send it to the
server's address (curl -X PUT --data-binary @plan.md "${AGENTRUN_BASE_URL%/v2}$url"), not after the /v2 base, where a
404 says so. With no content_type the reservation's type is its path's extension's.
Either way the bytes are streamed to disk, never held whole, so max_body_bytes does not apply; a file is at most
limits.max_upload_bytes, 50 MiB (413). The same bytes sent again change nothing; other bytes are a 422.
GET /v2/files lists the server's uploads, pending and ready, newest first (limit, cursor), GET /v2/files/{id} reads
one's record, and DELETE /v2/files/{id} removes it and its bytes (204): these three are this server's own
(x-agentrun-serve: "files/1").
A run names up to limits.max_files_per_run, 20, ready files in file_ids: an unknown, pending or repeated one is
422 at file_ids before anything starts. Each is copied, never linked, into the run's work/inputs/ at its path,
folders kept, before the run's process starts, whatever its harness; a name already taken gets a suffix (notes-2.txt,
docs-2/), the same for the same files in the same order. The run reads them as any file of its workspace, and
GET /v2/runs/{id}/files lists them. A run's opening message is saved beside them as inputs/message.md, its
content byte for byte, so an agent can name it to a subagent instead of copying it (a run with no text content has
none; an upload at that path takes message-2.md); the files line never names it. An agentic run is told of them in its first message, on every harness: after the
input's content and a blank line, one line,
Files for this run: "inputs/notes.txt" (32 B), "inputs/docs/plan.md" (1.5 KB)., each file by the path the run's tools
take, quoted as a JSON string with a control, format or separator character as its \uXXXX escape (so no name forges an
entry or reorders the line), and its size, at most 20 and then how many more, and never past what the run's door takes
in one message (fewer named, then only how many). That is the message the harness gets, so it is the timeline's first
user_message; the run's input stays as it was sent. A run given no files is sent its content as it is. A deleted
upload stays in the runs that copied it; a run started after names it in vain. Each upload is kept in
DIR/files/<file_id>/, 0600. A start clears the temp files a crashed upload left (.incoming.*.tmp in DIR/files/,
bytes.*.tmp in a file's folder), each only when it is a regular file (a DIR/files/ that is a link is not swept), and
logs event=uploads_swept removed=N. upload.expires_at, which the contract requires, is advisory and not enforced in
this release: a PUT after it is still taken.
With Archil on (Mode 2), uploads live on Archil, not in DIR, so a runner needs no disk of the server's. The server
keeps them on an Archil disk of its own, agentrun-<server id>-files, made by its first upload, at
files/<file_id>/ (the same bytes and record). Listing, reading and deleting read that disk; the routes, limits and
answers are the ones above, but the bytes are held in the server's memory (up to 50 MiB a file) instead of streamed to
disk. When a run is started with file_ids, the server copies each file into the run's folder on its disk, at
work/inputs/<path> (the launch's archil_disk, else its agent's, made first when the agent has none), before the run
is queued, for at most 45 s. The server copies 2 files at a time across all the runs it is starting, because Archil
resets a connection carrying more large writes at once; 20 files of 10 MiB took 11 to 14 s. A copy that fails or takes
longer refuses the start with
424 upstream_failed ("The run's files could not be copied into its folder on Archil, so it was not started: ..."). No
run is made and what was copied is removed. The run's claim then finds its files in place and reads no upload. Files
uploaded while Archil was off stay in DIR/files/ and are not seen while it is on, and the other way round.
In Mode 2, an uploaded file that no run names is deleted once it is older than AGENTRUN_UPLOAD_RETENTION (default
7d; a whole number with ms, s, m, h or d, or off to keep every file). The server sweeps its uploads disk
once an hour and logs event=uploads_expired removed=N. A file is kept while a run the store still has was started with
it, or while a run started with it in the last hour (whose row may not be written yet). A file kept by a run that has
since been deleted becomes unnamed and goes after the retention. Mode 1 keeps every upload, as before.
