> ## Documentation Index
> Fetch the complete documentation index at: https://docs.formation.texturehq.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Kept attachments

> Keep the original of each file shared with an agent, so reading it does not depend on the chat service.

A connector delivers a file's name, type and size with its message and holds
the bytes itself. By default Formation fetches those bytes when an agent reads
the file and then discards them. Every read therefore depends on one request to
the chat service at that moment. If the request is refused, the file cannot be
read, and each tool that could read it fails the same way.

An install with a blob store keeps the original instead:

1. When a message with attachments is recorded, Formation fetches each file
   through the connector that delivered it and stores it. This starts beside
   the agent's turn, not after it.
2. A refused fetch is retried in the background: after a minute, then at
   doubling intervals up to an hour, ten times in all. The reason for the last
   refusal is recorded in the connector's own words, with no address,
   credential or response body.
3. `read_document`, `view_images` and `import_attachment` read the kept copy.
   When there is none (not fetched yet, every try refused, or the message is
   older than this feature), they fetch from the connector as before and keep
   what they get. A fetch that succeeds once never has to succeed again.

Files over the 8 MiB transfer limit are not kept. They are not fetched for
reading either.

## What does not change

Keeping a file changes where its bytes come from, never who may read them. A
read passes the same conversation and audience checks as before and only then
asks for the bytes. The object's key is derived from the attachment's ID, is
recorded only in the database, and is never shown to a model or a person.

## Retention

A kept original lives exactly as long as the message it arrived with. When the
message's record is deleted, the object is deleted on the next pass of the
capture loop.

Deleting a file in the chat service does not delete Formation's copy. The copy
remains readable, by those the conversation's checks admit, until its message
is deleted.

Kept originals are not sealed by Formation. Use a bucket with encryption at
rest.

## Configuration

The blob store is process configuration, and optional. Without it nothing is
kept and nothing else changes.

| Variable | Purpose |
| - | - |
| `FORMATION_BLOB_S3_ENDPOINT` | The store's API origin, for example `https://s3.us-east-1.amazonaws.com`. HTTPS, with no path. |
| `FORMATION_BLOB_S3_REGION` | The signing region. Stores without regions accept `auto`. |
| `FORMATION_BLOB_S3_BUCKET` | The bucket. It must already exist. |
| `FORMATION_BLOB_S3_ACCESS_KEY_ID` / `FORMATION_BLOB_S3_SECRET_ACCESS_KEY` | A key pair that may put, get and delete objects in the bucket. It needs nothing else. |
| `FORMATION_BLOB_S3_PREFIX` | Optional. A prefix for every object, so several installs can share one bucket. |

Set the first five together or not at all; a partial set fails startup. A
complete set that cannot be used (a malformed endpoint, an invalid bucket name)
is logged at startup and the install serves without keeping files.

Formation speaks the S3 object API with path-style addresses and Signature
Version 4. It makes three calls: `PutObject`, `GetObject` and `DeleteObject`.
A wrong key pair or a missing bucket is not detected at startup; it shows as
attachments that stay unkept, with the store's error code in the log.

### A blob broker instead of a bucket

An install can also reach its store through a blob broker, and hold no storage
credential at all. Set `FORMATION_BLOB_BROKER_URL` and
`FORMATION_BLOB_BROKER_TOKEN` in place of the variables above. Formation then
asks the broker for a short-lived signed address for each object and moves the
bytes directly to or from the store behind it. The contract is the
[blob broker protocol](https://docs.formation.texturehq.com/runtime/blob-broker-protocol.md).

An install has one blob store: setting a broker and a bucket together fails
startup.

### For a hosting operator

There are two ways to give each install its own storage.

* **A bucket or scoped prefix per install.** Provision one bucket per install,
  or one prefix per install in a shared bucket with a key pair the store
  itself restricts to that prefix, and set the `FORMATION_BLOB_S3_*` variables
  when the install is deployed. `FORMATION_BLOB_S3_PREFIX` only chooses where
  Formation writes. It is not a boundary: a key pair that can read the whole
  bucket can read every install's objects.
* **A blob broker.** Keep one store and one key pair that no install sees, run
  a broker that implements the [blob broker protocol](https://docs.formation.texturehq.com/runtime/blob-broker-protocol.md),
  and give each install the broker's URL and its own token. This suits a store
  that cannot issue enough scoped key pairs for one per install.

Either way Formation creates no buckets, lists nothing, and holds no state
about the store outside its own database.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.