您可以在 Gemini Enterprise Agent Platform 中建立沙箱快照,儲存沙箱的目前狀態,並在日後還原。這項功能有助於執行生命週期管理工作,例如還原至已知良好狀態,或探索變異分支。
快照可提供多項優勢,協助您管理代理工作流程:
- 狀態持續性:儲存沙箱的確切狀態,包括已安裝的程式庫、檔案系統變更和記憶體狀態。
- 效率:您不必從頭重建複雜的環境,而是可以透過快照在幾秒內還原。
- 檢查點:在長時間執行的代理程式工作期間建立檢查點,以便在發生問題時復原。
- 分支:從同一個快照建立多個沙箱,探索不同路徑或測試變化。
限制
如果符合下列任一條件,您就無法將沙箱快照還原至新的沙箱環境:
- 新版沙箱採用不同的伺服器架構 (例如
amd64與arm64)。 - 新沙箱使用不同的沙箱執行階段版本 (例如在 GKE 叢集升級後)。
- 新的沙箱會使用不同的容器映像檔 URI。
保留
建立快照後,系統會根據 ttl 屬性指定的時長保留快照。如要在 TTL 到期前刪除快照,請參閱「刪除快照」。
建立快照
如要建立沙箱的快照,請使用 Python SDK:
import agentplatform
client = agentplatform.Client(project='PROJECT_ID', location='LOCATION')
sandbox_name = 'projects/PROJECT_ID/locations/LOCATION/reasoningEngines/INSTANCE_ID/sandboxEnvironments/SANDBOX_ID'
snapshot_operation = client.sandboxes.snapshots.create(
source_sandbox_environment_name=sandbox_name,
config={
"display_name": "DISPLAY_NAME",
"ttl": "3600s",
}
)
print(f"Snapshot creation initiated: {snapshot_operation.name}")
更改下列內容:
PROJECT_ID: Cloud de Confiance 專案 ID。LOCATION:資源的 Cloud de Confiance 區域。請參閱「支援的區域」。INSTANCE_ID:Agent Platform 執行個體 ID。SANDBOX_ID:要建立快照的現有沙箱 ID。DISPLAY_NAME:快照的說明顯示名稱。
從快照還原
建立新的沙箱環境時,您可以參照已儲存的快照,還原沙箱狀態:
agent_instance_name = 'projects/PROJECT_ID/locations/LOCATION/reasoningEngines/INSTANCE_ID
snapshot_name = 'projects/PROJECT_ID/locations/LOCATION/reasoningEngines/INSTANCE_ID/sandboxEnvironments/SANDBOX_ID'
# Restore from a snapshot
new_sandbox_operation = client.sandboxes.create(
name=agent_instance_name,
config={
"display_name": "restored-sandbox",
"sandbox_environment_snapshot": snapshot_name,
}
)
可列出快照
如要列出與 Agent Platform 執行個體相關聯的所有沙箱快照,請執行下列步驟:
snapshots_response = client.sandboxes.snapshots.list(name=agent_instance_name)
for snapshot in snapshots_response.sandbox_environment_snapshots:
print(snapshot.name)
查看快照詳細資料
如要查看特定沙箱快照的設定,請按照下列步驟操作:
snapshot = client.sandboxes.snapshots.get(name=snapshot_name)
print(snapshot)
刪除快照
如要明確刪除不再需要的沙箱快照,請按照下列步驟操作:
client.sandboxes.snapshots.delete(name=snapshot_name)
print("Snapshot deleted.")