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

稽核檔案系統變更

檢視並分析代理程式在工作階段期間執行的操作

AgentFS 會記錄每一次檔案操作與工具呼叫,讓您完整掌握代理程式的行為。這對於除錯、合規稽核,以及理解代理程式的運作方式至關重要。

檢視時間軸

查看依時間排序的工具呼叫清單:

agentfs timeline my-session

輸出:

ID   TOOL                 STATUS       DURATION STARTED
4    execute_code         pending            -- 2024-01-05 09:44:20
3    api_call             error           300ms 2024-01-05 09:44:15
2    read_file            success          50ms 2024-01-05 09:44:10
1    web_search           success        1200ms 2024-01-05 09:43:45

篩選結果

僅顯示特定工具類型:

agentfs timeline my-session --filter web_search

僅顯示錯誤:

agentfs timeline my-session --status error

限制項目數量:

agentfs timeline my-session --limit 20

JSON 輸出

供程式化分析使用:

agentfs timeline my-session --format json
[
  {
    "id": 1,
    "name": "web_search",
    "status": "success",
    "started_at": 1704447825,
    "completed_at": 1704447826,
    "duration_ms": 1200,
    "parameters": {"query": "AI agents"},
    "result": {"results": ["result1", "result2"]}
  }
]

檢視檔案

列出工作階段中的所有檔案:

agentfs fs ls my-session

輸出:

d artifacts
f config.json
f output.txt

列出子目錄:

agentfs fs ls my-session /artifacts

讀取檔案內容:

agentfs fs cat my-session /output.txt

檢視變更(差異比對)

查看相較於原始檔案系統有哪些變更:

agentfs diff my-session

這會顯示:

  • 新建的檔案
  • 修改過的檔案
  • 刪除的檔案

使用 SQL 查詢

由於 AgentFS 採用 SQLite,您可以執行任意查詢:

tursodb .agentfs/my-session.db

查詢範例:

-- Find all tool calls that took longer than 1 second
SELECT name, duration_ms
FROM toolcalls
WHERE duration_ms > 1000;

-- Count tool usage by type
SELECT name, COUNT(*) as count
FROM toolcalls
GROUP BY name
ORDER BY count DESC;

-- Find files modified in the last hour
SELECT path, mtime
FROM fs_inode
WHERE mtime > strftime('%s', 'now', '-1 hour');

-- Get total bytes written
SELECT SUM(size) as total_bytes
FROM fs_inode
WHERE mode & 0170000 = 0100000;  -- regular files only

使用案例

除錯代理程式失敗

當代理程式失敗時,使用時間軸來了解發生了什麼事:

# See recent activity
agentfs timeline my-session --limit 20

# Focus on errors
agentfs timeline my-session --status error

# Check what files were created/modified
agentfs fs ls my-session

效能分析

找出緩慢的操作:

SELECT name, AVG(duration_ms) as avg_ms, COUNT(*) as count
FROM toolcalls
GROUP BY name
ORDER BY avg_ms DESC;

合規稽核

匯出代理程式活動的完整記錄:

agentfs timeline my-session --format json > audit-log.json

後續步驟

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