跳至正文內容
TursoDB.cn 獨立社群 · MVCC 並行寫入與每 Agent 獨立庫實戰 閱讀解析 →
AgentFS(測試版) 實戰指南

與 Turso Cloud 同步

將 agent 檔案系統與遠端 Turso 資料庫同步

AgentFS 可以與 Turso Cloud 同步,藉此實現備份、協作以及分散式 agent 部署。

設定同步

1. 建立 Turso 資料庫

如果你還沒有 Turso 帳號,請先註冊。

為你的 agent 建立一個資料庫:

turso db create my-agent-db

取得資料庫 URL:

turso db show my-agent-db --url
# Output: libsql://my-agent-db-username.turso.io

2. 以同步功能初始化

建立一個已啟用同步的新 agent 檔案系統:

agentfs init my-agent --sync-remote-url libsql://my-agent-db-username.turso.io

或是為既有的 agent 加入同步:

# Edit the database to add sync configuration
# (Feature coming soon)

同步指令

拉取遠端變更

從 Turso Cloud 下載變更:

agentfs sync my-agent pull

推送本機變更

將本機變更上傳至 Turso Cloud:

agentfs sync my-agent push

檢視同步狀態

查看同步統計資料:

agentfs sync my-agent stats

建立檢查點

強制建立同步檢查點:

agentfs sync my-agent checkpoint

使用情境

備份與還原

自動備份 agent 狀態:

# After important work
agentfs sync my-agent push

# On a new machine
agentfs init my-agent --sync-remote-url libsql://...
agentfs sync my-agent pull

多機器 Agent

在多台機器上執行 agent 並共用狀態:

# Machine A
agentfs run --session shared-agent python3 agent.py
agentfs sync shared-agent push

# Machine B
agentfs sync shared-agent pull
agentfs run --session shared-agent python3 agent.py

部分同步

對於大型檔案系統,可使用部分同步只取得需要的內容:

agentfs init my-agent \
  --sync-remote-url libsql://... \
  --sync-partial-prefetch \
  --sync-partial-segment-size 1000

部分同步選項

選項 說明
--sync-partial-prefetch 啟用預先擷取
--sync-partial-segment-size 部分同步的區段大小
--sync-partial-bootstrap-query 自訂 bootstrap 查詢
--sync-partial-bootstrap-length Bootstrap 前綴長度

驗證

同步需要 Turso 驗證權杖。請透過環境變數設定:

export TURSO_AUTH_TOKEN=$(turso db tokens create my-agent-db)

或建立長效權杖:

turso db tokens create my-agent-db --expiration none

衝突解決

AgentFS 對於衝突採用「後寫入者勝出」(last-write-wins)策略。若同一個檔案在多台機器上被修改:

  1. 從機器 A 推送成功
  2. 從機器 B 推送失敗(衝突)
  3. 機器 B 必須先拉取,然後再推送

後續步驟

同步自官方 Turso 文件倉庫 ( tursodatabase/turso-docs · MIT 開源授權) 檢視官方原文 ↗
搜尋
按 Esc 關閉 · 由 Pagefind 靜態索引驅動