memory.artifact_tools¶
memory.artifact_tools ¶
Artifact, pipeline, and experiment MCP tools.
This block manages DVC-tracked large files, S3 remotes, DVC pipelines, and
experiment reproduction/rerun. It is graph-free — every tool delegates to
memory.artifacts (and memory.jobs for cloud reruns), touching only DVC,
S3, manifests, and the filesystem. Because it never opens the KGLite store, it
is hosted in its own memory-artifacts MCP server process (see
memory/artifacts_server.py) so it can be toggled independently of the core
memory server without risking a concurrent-borrow panic on the shared cache.
Tools are defined at module level and registered onto a server via
:func:register. They call the module-level _schedule_memory_commit hook
(a no-op until register wires in the host server's committer) so that
manifest/dvc.yaml writes get committed.
configure_artifact_remote ¶
configure_artifact_remote(bucket: str, prefix: str = '', region: str = '', remote_name: str = DEFAULT_REMOTE_NAME, endpoint_url: str = '', force: bool = False, dry_run: bool = True) -> str
Configure the DVC S3 remote used for artifact push/pull.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bucket
|
str
|
S3 bucket name. |
required |
prefix
|
str
|
Optional bucket prefix for this repo/project. |
''
|
region
|
str
|
Optional AWS region. |
''
|
remote_name
|
str
|
DVC remote name. |
DEFAULT_REMOTE_NAME
|
endpoint_url
|
str
|
Optional S3-compatible endpoint URL. |
''
|
force
|
bool
|
Replace an existing remote with the same name. |
False
|
dry_run
|
bool
|
If true, return the commands without changing DVC config. |
True
|
Source code in memory/artifact_tools.py
add_artifact ¶
Register one or more repository-local paths with DVC.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
str
|
Comma/newline-separated paths or a JSON list of paths. |
required |
dry_run
|
bool
|
If true, return the DVC command without executing it. |
True
|
Source code in memory/artifact_tools.py
push_artifact ¶
Push DVC-tracked artifacts to the configured remote.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
str
|
Optional comma/newline-separated target paths or JSON list. |
''
|
dry_run
|
bool
|
If true, return the DVC command without contacting the remote. |
True
|
Source code in memory/artifact_tools.py
pull_artifact ¶
Pull DVC-tracked artifacts from the configured remote.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
targets
|
str
|
Optional comma/newline-separated target paths or JSON list. |
''
|
dry_run
|
bool
|
If true, return the DVC command without contacting the remote. |
True
|
Source code in memory/artifact_tools.py
verify_artifacts ¶
Verify local artifact/pointer presence and DVC status.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
paths
|
str
|
Optional comma/newline-separated paths or JSON list. |
''
|
dry_run
|
bool
|
If true, return the DVC status command without executing it. |
True
|
Source code in memory/artifact_tools.py
list_artifacts ¶
List DVC artifact pointers and stored experiment manifests.
Source code in memory/artifact_tools.py
resolve_artifact ¶
Resolve an artifact path/id to a DVC pointer, manifest, or local path.
Source code in memory/artifact_tools.py
list_pipeline_stages ¶
List DVC pipeline stages from dvc.yaml.
add_pipeline_stage ¶
add_pipeline_stage(name: str, command: str, deps: str = '', outs: str = '', params: str = '', metrics: str = '', plots: str = '', wdir: str = '', force: bool = False, dry_run: bool = True) -> str
Add or update a DVC pipeline stage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
DVC stage name. |
required |
command
|
str
|
Stage command to execute. |
required |
deps
|
str
|
Comma/newline-separated dependency paths or JSON list. |
''
|
outs
|
str
|
Comma/newline-separated output paths or JSON list. |
''
|
params
|
str
|
Comma/newline-separated DVC params keys or JSON list. |
''
|
metrics
|
str
|
Comma/newline-separated metrics paths or JSON list. |
''
|
plots
|
str
|
Comma/newline-separated plot paths or JSON list. |
''
|
wdir
|
str
|
Optional repo-local working directory for the stage. |
''
|
force
|
bool
|
Pass --force when updating an existing stage. |
False
|
dry_run
|
bool
|
If true, return the planned DVC command without writing dvc.yaml. |
True
|
Source code in memory/artifact_tools.py
run_pipeline ¶
run_pipeline(pipeline_id: str, targets: str = '', dry_run: bool = True, require_remote: bool = False, environment_json: str = '') -> str
Run or plan DVC pipeline reproduction and write a manifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pipeline_id
|
str
|
Stable id for the pipeline-run manifest. |
required |
targets
|
str
|
Optional comma/newline-separated DVC stage targets or JSON list. |
''
|
dry_run
|
bool
|
If true, plan the DVC repro command without executing it. |
True
|
require_remote
|
bool
|
If true, push DVC outputs before treating the run as portable. |
False
|
environment_json
|
str
|
Optional JSON object to override the environment summary. |
''
|
Source code in memory/artifact_tools.py
run_experiment ¶
run_experiment(experiment_id: str, command: str, artifacts_json: str = '', cwd: str = '', execute: bool = False, dry_run: bool = True, require_remote: bool = False, include_dirty_diff: bool = False, dirty_note: str = '', environment_json: str = '') -> str
Create an experiment manifest and optionally execute the command.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Stable id for the manifest filename. |
required |
command
|
str
|
Command needed to reproduce the experiment. |
required |
artifacts_json
|
str
|
JSON list of artifact records, JSON list of paths, or comma-separated paths. |
''
|
cwd
|
str
|
Optional repo-local working directory for the command. |
''
|
execute
|
bool
|
If true and dry_run is false, execute the command. |
False
|
dry_run
|
bool
|
Default true; captures provenance without running the command. |
True
|
require_remote
|
bool
|
If true, push DVC artifacts before treating the manifest as portable. |
False
|
include_dirty_diff
|
bool
|
Include a git diff stat in the manifest. |
False
|
dirty_note
|
str
|
Optional human note about dirty working-tree state. |
''
|
environment_json
|
str
|
Optional JSON object to override the environment summary. |
''
|
Source code in memory/artifact_tools.py
push_manifest_artifacts ¶
Push all DVC artifacts referenced by a manifest and update remote state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Manifest id to load. |
required |
dry_run
|
bool
|
If true, return planned push semantics without remote I/O. |
False
|
Source code in memory/artifact_tools.py
verify_manifest ¶
Verify local artifact pointers/files and report manifest remote state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Manifest id to load. |
required |
dry_run
|
bool
|
If true, return planned DVC status without executing it. |
False
|
Source code in memory/artifact_tools.py
export_experiment_catalog ¶
export_experiment_catalog(experiment_id: str, catalog_prefix: str = '', copy_small_artifacts: bool = True, max_artifact_bytes: int = 1000000, dry_run: bool = True) -> str
Export a human-readable S3 catalog beside DVC's hash-addressed cache.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Manifest id to export. |
required |
catalog_prefix
|
str
|
Optional explicit s3:// prefix; defaults to |
''
|
copy_small_artifacts
|
bool
|
Copy small non-input artifacts, such as metrics JSON, into the catalog. |
True
|
max_artifact_bytes
|
int
|
Maximum artifact size to copy into the readable catalog. |
1000000
|
dry_run
|
bool
|
If true, return planned AWS uploads without writing local catalog files or uploading. |
True
|
Source code in memory/artifact_tools.py
reproduce_experiment ¶
reproduce_experiment(experiment_id: str, pull: bool = False, execute: bool = False, dry_run: bool = True) -> str
Prepare or execute reproduction steps from a stored manifest.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Manifest id to load. |
required |
pull
|
bool
|
Pull DVC artifacts listed in the manifest before running. |
False
|
execute
|
bool
|
If true and dry_run is false, execute the manifest command. |
False
|
dry_run
|
bool
|
Default true; returns planned DVC/command actions without remote I/O. |
True
|
Source code in memory/artifact_tools.py
rerun_experiment ¶
rerun_experiment(experiment_id: str, where: str = 'cloud', executor: str = '', dry_run: bool = True) -> str
Rerun an experiment from its manifest in a clean sandbox.
Cloud mode (default) enqueues a job to the S3 queue for the AWS runner and returns a job_id to poll with get_rerun_job. Local mode runs the sandbox rerun on this machine (git worktree at the original commit + dvc pull + command + new dated run manifest with a replication check).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
experiment_id
|
str
|
Manifest id of the run to rerun. |
required |
where
|
str
|
"cloud" to enqueue for the runner, "local" to run here. |
'cloud'
|
executor
|
str
|
Optional executor label recorded in the manifest/job. |
''
|
dry_run
|
bool
|
Default true; cloud mode returns the job spec without enqueueing, local mode returns the sandbox plan without executing. |
True
|
Source code in memory/artifact_tools.py
get_rerun_job ¶
Get the state and log tail of a queued/running/finished rerun job.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
job_id
|
str
|
Job id returned by rerun_experiment(where="cloud"). |
required |
tail_chars
|
int
|
Maximum number of trailing log characters to return. |
8000
|
Source code in memory/artifact_tools.py
backup_artifact ¶
One-step backup of a local file: DVC add + push + verify.
The file stays where it is; this tracks it with DVC, ships a copy to the S3 remote, and returns the pointer/md5 so the path is restorable on any machine via dvc pull.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Repo-local path of the file or directory to back up. |
required |
dry_run
|
bool
|
If true, return planned add/push without remote I/O. |
False
|
Source code in memory/artifact_tools.py
artifact ¶
artifact(action: Literal['configure_remote', 'add', 'push', 'pull', 'verify', 'list', 'resolve', 'backup'], paths: str = '', targets: str = '', identifier: str = '', path: str = '', include_manifests: bool = True, bucket: str = '', prefix: str = '', region: str = '', remote_name: str = '', endpoint_url: str = '', force: bool = False, dry_run: bool | None = None) -> str
Use this when you need to manage a large/regenerable file via DVC: register, ship, retrieve, verify, resolve, or back it up.
Actions — name(required, optional?): configure_remote(bucket, prefix?, region?, remote_name?, endpoint_url?, force?, dry_run?): configure the DVC S3 remote. add(paths, dry_run?): register repo-local paths with DVC. push(targets?, dry_run?): push DVC-tracked artifacts to the remote. pull(targets?, dry_run?): pull DVC-tracked artifacts from the remote. verify(paths?, dry_run?): verify local pointer/file presence + DVC status. list(include_manifests?): list DVC pointers and stored manifests. resolve(identifier): resolve an identifier to a pointer/manifest/local path. backup(path, dry_run?): one-step DVC add + push + verify of a local path.
dry_run defaults to true for every action except backup (false).
All return JSON.
Source code in memory/artifact_tools.py
pipeline ¶
pipeline(action: Literal['list_stages', 'add_stage', 'run'], name: str = '', command: str = '', deps: str = '', outs: str = '', params: str = '', metrics: str = '', plots: str = '', wdir: str = '', force: bool = False, pipeline_id: str = '', targets: str = '', require_remote: bool = False, environment_json: str = '', dry_run: bool | None = None) -> str
Use this when you need to define or run a reproducible DVC pipeline: list stages, add/update a stage, or reproduce.
Actions — name(required, optional?): list_stages(): list DVC pipeline stages from dvc.yaml. add_stage(name, command, deps?, outs?, params?, metrics?, plots?, wdir?, force?, dry_run?): add/update a stage. run(pipeline_id, targets?, require_remote?, environment_json?, dry_run?): run/plan DVC repro and write a manifest.
dry_run defaults to true. All return JSON.
Source code in memory/artifact_tools.py
experiment ¶
experiment(action: Literal['run', 'push_manifest', 'verify_manifest', 'export_catalog', 'reproduce', 'rerun', 'get_job'], experiment_id: str = '', command: str = '', artifacts_json: str = '', cwd: str = '', execute: bool = False, require_remote: bool = False, include_dirty_diff: bool = False, dirty_note: str = '', environment_json: str = '', catalog_prefix: str = '', copy_small_artifacts: bool = True, max_artifact_bytes: int = 1000000, pull: bool = False, where: str = 'cloud', executor: str = '', job_id: str = '', tail_chars: int = 8000, dry_run: bool | None = None) -> str
Use this when running or replicating an experiment: capture a provenance manifest, ship/verify it, reproduce, or rerun.
Actions — name(required, optional?):
run(experiment_id, command, artifacts_json?, cwd?, execute?, require_remote?, include_dirty_diff?, dirty_note?, environment_json?, dry_run?):
create a manifest and optionally execute. dry_run default true.
push_manifest(experiment_id, dry_run?): push a manifest's DVC artifacts.
dry_run default false.
verify_manifest(experiment_id, dry_run?): verify a manifest's pointers/files.
dry_run default false.
export_catalog(experiment_id, catalog_prefix?, copy_small_artifacts?, max_artifact_bytes?, dry_run?):
export a human-readable S3 catalog. dry_run default true.
reproduce(experiment_id, pull?, execute?, dry_run?): prepare/execute
reproduction. dry_run default true.
rerun(experiment_id, where?, executor?, dry_run?): rerun in a clean sandbox.
dry_run default true.
get_job(job_id, tail_chars?): state + log tail of a cloud rerun.
All return JSON.
Source code in memory/artifact_tools.py
overview ¶
Use this first when you're unsure how to work with artifacts: a compact orientation map.
Read-only. Returns the artifacts server's purpose and a tool -> action index.
Authoritative action values also live on each tool's own action schema enum.
Source code in memory/artifact_tools.py
register ¶
Register the artifact tools onto mcp_server.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mcp_server
|
object
|
A FastMCP instance exposing |
required |
schedule_commit
|
Callable[[str], None] | None
|
Optional callable |
None
|