---
sidebar:
  label: roboto.upload_agent.agent
  order: 0
title: roboto.upload_agent.agent
---
## Module Contents

### DEFAULT_ROBOTO_UPLOAD_FILE

```python
roboto.upload_agent.agent.DEFAULT_ROBOTO_UPLOAD_FILE
```

`from roboto.upload_agent.agent import DEFAULT_ROBOTO_UPLOAD_FILE`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/upload_agent/agent.py#L33-L33)

Path of the template file `UploadAgent.create_upload_configs` copies into each directory.

It is `~/.roboto/default_roboto_upload.json`.

### UploadAgent

```python
class roboto.upload_agent.agent.UploadAgent(
    agent_config: roboto.upload_agent.files.UploadAgentConfig,
    roboto_client: Optional[roboto.http.RobotoClient] = None,
    default_roboto_upload_file: Optional[pathlib.Path] = None,
)
```

`from roboto.upload_agent.agent import UploadAgent`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/upload_agent/agent.py#L40-L425)

Service that uploads directories on local disk to Roboto datasets.

A directory is queued for upload when it holds an upload config file, named by [`upload_config_filename`](/docs/reference/python-sdk/roboto/upload_agent/files#roboto.upload_agent.files.UploadAgentConfig.upload_config_filename). `create_upload_configs` writes those files, and `process_uploads` uploads the directories that have one.

**Parameters**

- **agent_config** (`roboto.upload_agent.files.UploadAgentConfig`): Directories to scan, the name of the upload config file, and what to delete after an upload.
- **roboto_client** (`Optional[roboto.http.RobotoClient]`): Client to make requests to Roboto with. Defaults to one configured from the environment, by [`from_env()`](/docs/reference/python-sdk/roboto/http/roboto_client#roboto.http.roboto_client.RobotoClient.from_env).
- **default_roboto_upload_file** (`Optional[pathlib.Path]`): Template file `create_upload_configs` copies into each directory. `None` uses `DEFAULT_ROBOTO_UPLOAD_FILE`.

#### UploadAgent.create_upload_configs()

```python
def create_upload_configs()
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/upload_agent/agent.py#L69-L129)

Write an upload config file into each directory directly under a search path that has none.

A directory is skipped when it is empty or already holds an upload config file, an upload-in-progress file, or an upload-complete file. Search paths that are not directories are skipped.

Each file written is a copy of the template at `default_roboto_upload_file`, with each `$NAME` and `${NAME}` replaced by the value of environment variable `NAME`. When the template is missing or cannot be read or parsed, each file holds a config with every field at its default.

#### UploadAgent.process_uploads()

```python
def process_uploads(
    merge_uploads: bool = False,
) -> collections.abc.Sequence[roboto.domain.datasets.Dataset]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/upload_agent/agent.py#L131-L218)

Upload each directory that holds an upload config file, and return the datasets uploaded to.

Upload config files are found by searching each search path recursively; a file that cannot be parsed is logged and skipped. For each directory, in order:

1. Skip it if it holds an upload-complete file.
2. Choose its dataset: the one named by its upload-in-progress file, so an interrupted upload resumes into the dataset it started; otherwise the merged dataset, with `merge_uploads`; otherwise a new dataset built from the config file's `dataset` section.
3. Write an upload-in-progress file naming that dataset.
4. Upload the directory's files, filtered by the config file's `include_patterns` and `exclude_patterns`. Uploaded files are deleted from disk when the config file's `delete_uploaded_files` says so, or, when it is unset, the agent config's.
5. Delete the upload config file, write an upload-complete file, delete the upload-in-progress file, then upload the upload-complete file to the dataset.
6. With the agent config's `delete_empty_directories`, remove the directory if nothing but the upload-complete file is left in it.
7. Add the dataset to each collection in the config file's `add_to_collections`. A failure is logged and does not stop the run.

A failure in steps 2 to 6 stops the run. A directory that got past step 3 keeps a marker file, so the next run resumes it into the same dataset or, once its upload-complete file is written, skips it.

**Parameters**

- **merge_uploads** (`bool`): Whether to upload every directory into one new dataset, created in the agent config's `default_org_id`. Each directory's config file then updates that dataset: its description replaces the dataset's, an unset one clearing it, its metadata and tags are added, and its `add_to_collections` is ignored. `False` uploads each directory to its own dataset.

**Returns**

- `collections.abc.Sequence[roboto.domain.datasets.Dataset]`: With `merge_uploads`, the merged dataset. Otherwise, each dataset this call created or resumed an upload into.

**Raises**

- [`RobotoNotFoundException`](/docs/reference/python-sdk/roboto/exceptions/domain#roboto.exceptions.domain.RobotoNotFoundException): An upload-in-progress file names a dataset that no longer exists, or that the caller cannot see.

### logger

```python
roboto.upload_agent.agent.logger
```

`from roboto.upload_agent.agent import logger`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/upload_agent/agent.py#L30-L30)
