Agentic workflows – Volumes
Let an AI agent take snapshots, clone and restore workspaces and environments, and delete snapshots and volumes.
Last updated
On this page
Description and operation
General
An agent saves and recovers work with the snapshot, clone and restore tools. The platform chapter Volumes explains the volume, its lineage and its snapshots. This page gives the tool call for each task.
Four rules are specific to an agent:
- The history, refs and delete tools take the
idof a volume, never its name. Read theidfromvolume_list, or from thevolumefield of the workspace or the environment. - The first push of a volume must give
volume, its name. Each later push is a version. Restore and clone takesnapshot_idas a reference:name,name@Nor a snapshot id. See Names and versions. - A push, a clone and a restore return
202at once. The agent polls thephasein the history, or thestateof the new workspace or environment. - When
env_restoreanswers409withlost, the agent names the services indiscardonly after the developer accepts the loss.
An agent clones to try a change on a copy, and deletes the copy when it is done.
Tasks
Take a snapshot of a workspace
Reason for the task: Save the state of a workspace in a snapshot.
Job set-up
- Access: you
- Agent tool:
workspace_snapshot - References:
POST /v1/workspaces/{id}/snapshots
Procedure
Push a snapshot with a note in
message. Add the volume name involumefor the first push.{"tool": "workspace_snapshot", "arguments": {"workspace": "ws-0a1b2c3d4e5f6a7b", "message": "before the refactor", "volume": "backend-base"}}
Close-out
- Show the history, as in task 003. Wait until the first row shows your note and the
phaseready.
The same task with the SDK or CLI: Snapshots task 001.
Take a snapshot of an environment
Reason for the task: Save the services and the data of an environment in a snapshot.
Job set-up
- Access: you
- Agent tool:
env_snapshot - References:
POST /v1/environments/{id}/snapshots
Procedure
Push a snapshot with a note in
message. Add the volume name involumefor the first push.{"tool": "env_snapshot", "arguments": {"env": "env-1f2e3d4c5b6a7988", "message": "before the schema change", "volume": "dev-data"}}
Close-out
- Show the history, as in task 003. Wait until the first row shows your note and the
phaseready.
The same task with the SDK or CLI: Snapshots task 002.
Show the snapshot history
Reason for the task: Find the snapshots of a workspace or an environment and their ids.
Job set-up
- Access: you
- Agent tool:
volume_history - Conditions: you know the
idof the volume, which is theidof the workspace or the environment. See Show the volumes. - References:
GET /v1/volumes/{key}/history,GET /v1/volumes/{key}/refs
Procedure
Show the lineage, tip first.
{"tool": "volume_history", "arguments": {"volume": "ws-0a1b2c3d4e5f6a7b"}}Show the tip,
main. A clone or a restore uses it by default.{"tool": "volume_refs", "arguments": {"volume": "ws-0a1b2c3d4e5f6a7b"}}
Close-out
- Write down the
idof the snapshot for a restore, a clone or a delete.
The same task with the SDK or CLI: Lineage task 001.
Delete a snapshot
Reason for the task: Remove a snapshot that you do not need.
Job set-up
- Access: you
- Agent tool:
snapshot_delete - Conditions: no running workspace or environment is based on the snapshot.
- References:
DELETE /v1/volumes/{key}/snapshots/{snapshot}
The deletion is immediate and final. If it is the last snapshot of a volume that nothing uses, the volume and its data are deleted too.
Procedure
Delete the snapshot. Use the
idfrom the history forsnapshot.{"tool": "snapshot_delete", "arguments": {"volume": "ws-0a1b2c3d4e5f6a7b", "snapshot": "ws-0a1b2c3d4e5f6a7b-8a7b6c91"}}
Close-out
- Show the history. The
idis gone, or the call returns404if the volume went with it.
The same task with the SDK or CLI: Lineage task 004.
Clone a workspace
Reason for the task: Make a new workspace that starts with a copy of the files of a workspace.
Job set-up
- Access: you
- Agent tool:
workspace_clone - References:
POST /v1/workspaces/{id}/clone
Procedure
Clone the workspace. Use a free name for
name.{"tool": "workspace_clone", "arguments": {"workspace": "ws-0a1b2c3d4e5f6a7b", "name": "api-experiment", "task": "try the new parser"}}
Close-out
- Make sure that
interruptedisfalse, then wait until the new workspace isready.
The same task with the SDK or CLI: Workspaces task 008.
Clone an environment
Reason for the task: Make a new environment from the present state of an environment, or from one of its snapshots.
Job set-up
- Access: you
- Agent tool:
env_clone - References:
POST /v1/environments/{id}/clone
Procedure
Clone the present state of the environment. Use a plain name for
name.{"tool": "env_clone", "arguments": {"env": "env-1f2e3d4c5b6a7988", "name": "dev-copy"}}Give the
idof a snapshot insnapshot_idto clone that snapshot. See Show the snapshot history.{"tool": "env_clone", "arguments": {"env": "env-1f2e3d4c5b6a7988", "name": "dev-before-migration", "snapshot_id": "env-1f2e3d4c5b6a7988-8a7b6c91"}}
Close-out
- Wait until the
stateof the new environment isrunning, then check its services.
The same task with the SDK or CLI: Environments task 008.
Restore a workspace from a snapshot
Reason for the task: Make a new workspace from the state that a snapshot froze.
Job set-up
- Access: you
- Agent tool:
workspace_restore - Conditions: you know the
idof areadysnapshot of a workspace. See Show the snapshot history. - References:
POST /v1/workspaces/restore
Procedure
Restore the workspace. Use the
idforsnapshot_id, and a free name forname.{"tool": "workspace_restore", "arguments": {"name": "api-restored", "snapshot_id": "ws-0a1b2c3d4e5f6a7b-8a7b6c91"}}Add
image,packagesorquota_gbto the same call to override a value.{"tool": "workspace_restore", "arguments": {"name": "api-restored", "snapshot_id": "ws-0a1b2c3d4e5f6a7b-8a7b6c91", "quota_gb": 40}}
Close-out
- Wait until the new workspace is
ready, then check its packages.
The same task with the SDK or CLI: Workspaces task 009.
Restore an environment from a snapshot
Reason for the task: Put an environment back to the services and the data of one of its snapshots.
Job set-up
- Access: you
- Agent tool:
env_restore - Conditions: you know the
idof areadysnapshot of this environment. No service that the restore removes has an intercept. - References:
POST /v1/environments/{id}/restore, Remove an intercept
The restore replaces the present data of the environment with the data of the snapshot. Take a snapshot first to keep the present state.
Procedure
Restore the environment. Use the
idof the snapshot forsnapshot_id.{"tool": "env_restore", "arguments": {"env": "env-1f2e3d4c5b6a7988", "snapshot_id": "env-1f2e3d4c5b6a7988-8a7b6c91"}}If the call returns
409with a listlost, restore again and name those services indiscard.{"tool": "env_restore", "arguments": {"env": "env-1f2e3d4c5b6a7988", "snapshot_id": "env-1f2e3d4c5b6a7988-8a7b6c91", "discard": ["redis"]}}
Close-out
- Read
rolled_back,added,removedanddiscardedin the answer. Wait until thestateisrunning.
The same task with the SDK or CLI: Environments task 009.
Show the volumes
Reason for the task: Find the volumes that hold your snapshots, and which of them nothing uses.
Job set-up
- Access: you
- Agent tool:
volume_list - References:
GET /v1/volumes
Procedure
Show the volumes. Use
kindandownerto filter the list.{"tool": "volume_list", "arguments": {"kind": "environment", "owner": "acme"}}
Close-out
- Write down the
idof the volume. Wheredeletedistrue, nothing uses it.
The same task with the SDK or CLI: Volumes task 001.
Delete a volume
Reason for the task: Remove a detached volume and all its snapshots to free disk.
Job set-up
- Access: you
- Agent tool:
volume_delete - Conditions:
deletedistrue. See Show the volumes. - References:
DELETE /v1/volumes/{key}
The platform deletes the volume and all its snapshots at once. You cannot restore from them afterwards.
Procedure
Delete the volume. Use its
id.{"tool": "volume_delete", "arguments": {"volume": "env-1f2e3d4c5b6a7988"}}
Close-out
- Show the volumes. The deleted name is gone.
The same task with the SDK or CLI: Volumes task 002.
Troubleshooting
| Symptom | Possible cause | Corrective action |
|---|---|---|
409 with snapshots: 20 of 20 in use; request more under Quota | You used all the snapshots of the quota. The numbers are examples. | Delete a snapshot, or request more quota. |
409 with a snapshot is already being cut for this workspace | An earlier snapshot is still in progress. | Wait until its phase is ready, then take the snapshot again. |
409 with a sync point cannot be deleted by hand | The id is not a snapshot. | Show the history and use an id from it. |
409 with this snapshot is the base of a running worktree | A workspace or an environment is based on this snapshot. | Stop or delete it, or delete a different snapshot. |
422 with volume: this volume has no name yet; name it on its first push | The volume has no name, and the push gave no volume. | Push again with volume. |
409 with volume go-base already exists; delete it first | Another volume of the owner has this name. | Use a different name, or delete the other volume. |
409 with volume go-base is used by pipeline build | A pipeline or a run reads the volume. | Wait for the run, or change the pipeline. See Delete rules. |
409 with a list lost when an environment is restored | The restore removes services that hold data. | Restore again and name those services in discard. |
409 with the volume still has a workspace or environment | A workspace or an environment uses the volume. | Delete it, or delete a snapshot instead. |
404 with not found | The volume does not exist or is not yours. | Use an id from the list. |