Agent file manager service¶
consortium.server.services.agent_file_manager_service
¶
AgentFileManagerService(agent)
¶
get_all_assets()
¶
Returns all asset resources available to the agent.
Returns:
| Type | Description |
|---|---|
list[Asset]
|
A list of all asset resources. Empty if none have been uploaded. |
get_asset_by_asset_id(asset_id)
¶
Returns a single asset resource by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_id
|
str | UUID
|
The ID of the asset resource to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Asset
|
The requested asset resource. |
Raises:
| Type | Description |
|---|---|
ResourceNotFoundError
|
If no asset with the given ID exists. |
get_all_artifacts()
¶
Returns all artifact resources produced by agents.
Returns:
| Type | Description |
|---|---|
list[Artifact]
|
A list of all artifact resources. Empty if none have been created. |
get_artifact_by_artifact_id(artifact_id)
¶
Returns a single artifact resource by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
artifact_id
|
str | UUID
|
The ID of the artifact resource to retrieve. |
required |
Returns:
| Type | Description |
|---|---|
Artifact
|
The requested artifact resource. |
Raises:
| Type | Description |
|---|---|
ResourceNotFoundError
|
If no artifact with the given ID exists. |
read_asset_by_asset_id(asset_id, binary=False, encoding='utf-8', chunk_size=None)
¶
Reads the content of a file asset by its ID.
Retrieves the asset and reads its content from disk. The full read spectrum of the underlying repository file is exposed: content can be read as text or as raw bytes, and either eagerly (the whole content at once) or lazily as a generator of chunks for streaming large assets without loading them fully into memory.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
asset_id
|
str | UUID
|
The ID of the asset to read. |
required |
binary
|
bool
|
When |
False
|
encoding
|
str
|
The text encoding used to decode the content when |
'utf-8'
|
chunk_size
|
int | None
|
When |
None
|
Returns:
| Type | Description |
|---|---|
str | bytes | Generator[str | bytes]
|
The asset's content: a |
Raises:
| Type | Description |
|---|---|
ResourceNotFoundError
|
If no asset with the given ID exists. |
IsADirectoryError
|
If the asset is a directory, which has no readable file content. |
RepositoryFileDoesNotExistError
|
If the asset is a file but no longer exists
on disk. Always raised immediately, before any content is read, even
when |
RepositoryResourceFileSystemError
|
If reading the file from disk fails for a
reason other than it being missing (for example a permissions error).
Raised immediately when |
LookupError
|
If |
UnicodeDecodeError
|
If the file's content cannot be decoded using
|
create_artifact_file(content, name=None, description='')
async
¶
Creates a new artifact file from in-memory or streamed content.
The content is written to a new file in the artifacts repository and attributed to the owning agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
str | bytes | TextIO | BinaryIO
|
The content to write into the new artifact file, supplied either directly as text/bytes or as an open text/binary stream to read from. |
required |
name
|
str | None
|
A human-readable display name for the artifact. When |
None
|
description
|
str
|
A short human-readable description of the artifact. Defaults to an empty string when omitted. |
''
|
Returns:
| Type | Description |
|---|---|
Artifact
|
The newly created artifact file resource, attributed to the owning agent. |
Raises:
| Type | Description |
|---|---|
AgentNotFoundError
|
If the owning agent is no longer registered. |
RepositoryResourceFileSystemError
|
If the artifact file cannot be written to disk. |
RepositoryMetadataFileSystemError
|
If the repository's metadata file cannot be written to disk after the artifact file is created. |
UnicodeDecodeError
|
If |
add_artifact_file(path, name=None, description='', copy=False)
async
¶
Registers an existing file on disk as an artifact.
No new content is written: the file at path is moved (or copied when
copy=True) into the artifacts repository and attributed to the owning agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Filesystem path to the existing file to ingest as an artifact. |
required |
name
|
str | None
|
A human-readable display name for the artifact. When |
None
|
description
|
str
|
A short human-readable description of the artifact. Defaults to an empty string when omitted. |
''
|
copy
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Artifact
|
The newly registered artifact file resource, attributed to the owning agent. |
Raises:
| Type | Description |
|---|---|
AgentNotFoundError
|
If the owning agent is no longer registered. |
RepositoryResourceFileSystemError
|
If no file exists at |
RepositoryMetadataFileSystemError
|
If the repository's metadata file cannot be written to disk afterwards. |
create_artifact_directory(content=None, archive_file_format=None, name=None, description='')
async
¶
Creates a new artifact directory, optionally populated from existing content.
An empty directory is created in the artifacts repository, or, when content is
provided, it is populated from that content. How content is interpreted depends
on its type: raw bytes and open binary streams are unpacked as archive content
using archive_file_format, while a str or pathlib.Path is treated as a path
to an existing source directory whose tree is copied in. The directory is
attributed to the owning agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
content
|
bytes | BinaryIO | str | Path | None
|
Archive content to unpack into the new directory, supplied as raw
bytes or an open binary stream, or a path to an existing source directory
to copy in. When |
None
|
archive_file_format
|
Literal['zip', 'tar', 'gztar', 'bztar', 'xztar'] | None
|
The archive format used to interpret |
None
|
name
|
str | None
|
A human-readable display name for the artifact. When |
None
|
description
|
str
|
A short human-readable description of the artifact. Defaults to an empty string when omitted. |
''
|
Returns:
| Type | Description |
|---|---|
Artifact
|
The newly created artifact directory resource, attributed to the owning agent. |
Raises:
| Type | Description |
|---|---|
AgentNotFoundError
|
If the owning agent is no longer registered. |
InvalidRepositoryDirectoryArchiveFileFormatError
|
If |
RepositoryResourceFileSystemError
|
If the artifact directory cannot be created, or the source directory or archive cannot be copied or unpacked into it. |
RepositoryMetadataFileSystemError
|
If the repository's metadata file cannot be written to disk after the artifact directory is created. |
add_artifact_directory(path, name=None, description='', copy=False)
async
¶
Registers an existing directory on disk as an artifact.
No new directory is created: the directory at path is moved (or copied when
copy=True) into the artifacts repository and attributed to the owning agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | str
|
Filesystem path to the existing directory to ingest as an artifact. |
required |
name
|
str | None
|
A human-readable display name for the artifact. When |
None
|
description
|
str
|
A short human-readable description of the artifact. Defaults to an empty string when omitted. |
''
|
copy
|
bool
|
When |
False
|
Returns:
| Type | Description |
|---|---|
Artifact
|
The newly registered artifact directory resource, attributed to the owning agent. |
Raises:
| Type | Description |
|---|---|
AgentNotFoundError
|
If the owning agent is no longer registered. |
RepositoryResourceFileSystemError
|
If no directory exists at |
RepositoryMetadataFileSystemError
|
If the repository's metadata file cannot be written to disk afterwards. |