Claude Platform Docs
  • Messages
  • 託管代理
  • 管理

Search...
⌘K
第一步
概覽快速入門在 Console 中建立原型
定義您的代理
代理設定工具MCP 連接器權限政策代理技能
設定代理環境
雲端環境設定雲端沙箱參考
將工作委派給您的代理
啟動工作階段工作階段操作工作階段事件串流訂閱 Webhook定義結果使用保管庫進行驗證
管理代理上下文
存取 GitHub附加與下載檔案
進階協調
多代理工作階段排程部署
參考
託管代理參考
處理檔案
Files APIPDF 支援
技能
概覽最佳實踐企業技能
MCP
遠端 MCP 伺服器
雲端平台上的 Claude
AWS 上的 Claude Platform

Log in
附加與下載檔案
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Claude Platform Docs

Solutions

  • AI agents
  • Code modernization
  • Coding
  • Customer support
  • Education
  • Financial services
  • Government
  • Life sciences

Partners

  • Claude on AWS
  • Claude on Google Cloud

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Company

  • Anthropic
  • Careers
  • Economic Futures
  • Research
  • News
  • Responsible Scaling Policy
  • Security and compliance
  • Transparency

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Help and security

  • Availability
  • Status
  • Support
  • Discord

Terms and policies

  • Privacy policy
  • Responsible disclosure policy
  • Terms of service: Commercial
  • Terms of service: Consumer
  • Usage policy
託管代理/管理代理上下文

新增檔案

上傳檔案並將其掛載到您的沙箱中以供讀取和處理。

您可以透過 Files API 上傳檔案,並將其掛載到工作階段的沙箱中,以便提供檔案給您的代理程式使用。



所有 Managed Agents API 請求都需要 managed-agents-2026-04-01 beta 標頭。SDK 會自動設定此 beta 標頭。

上傳檔案

首先,使用 Files API 上傳檔案:

file = client.beta.files.upload(file=Path("data.csv"))
print(f"File ID: {file.id}")

在工作階段中掛載檔案

在建立工作階段時,將已上傳的檔案新增至 resources 陣列,即可將其掛載到沙箱中:



mount_path 是選填的,但請確保上傳的檔案具有描述性的名稱,以便代理程式能夠識別它。

session = client.beta.sessions.create(
    agent=agent.id,
    environment_id=environment.id,
    resources=[
        {
            "type": "file",
            "file_id": file.id,
            "mount_path": "/workspace/data.csv",
        },
    ],
)

系統會建立一個新的 file_id,用於參照工作階段中該檔案的實例。這些副本不會計入您的儲存空間限制。

多個檔案

透過在 resources 陣列中新增多個項目來掛載多個檔案:

resources = [
    {"type": "file", "file_id": "file_abc123", "mount_path": "/workspace/data.csv"},
    {"type": "file", "file_id": "file_def456", "mount_path": "/workspace/config.json"},
    {"type": "file", "file_id": "file_ghi789", "mount_path": "/workspace/src/main.py"},
]

每個工作階段最多支援 100 個檔案。

管理執行中工作階段的檔案

您可以在工作階段建立後,使用工作階段資源 API 來新增或移除檔案。每個資源在新增(或列出)時都會回傳一個 id,您可以使用此 ID 來執行刪除操作。

resource = client.beta.sessions.resources.add(
    session.id,
    type="file",
    file_id=file.id,
)
print(resource.id)  # "sesrsc_01ABC..."

使用 resources.list 列出工作階段中的所有資源。若要移除檔案,請使用資源 ID 呼叫 resources.delete:

listed = client.beta.sessions.resources.list(session.id)
for entry in listed.data:
    print(entry.id, entry.type)

client.beta.sessions.resources.delete(resource.id, session_id=session.id)

列出和下載工作階段檔案

使用 Files API 列出限定於某個工作階段的檔案並下載它們。

# 列出與工作階段相關聯的檔案
files = client.beta.files.list(
    scope_id="sesn_abc123",
    betas=["managed-agents-2026-04-01"],
)
for f in files:
    print(f.id, f.filename)

# 下載檔案
content = client.beta.files.download(files.data[0].id)
content.write_to_file("output.txt")

支援的檔案類型

代理程式可以處理任何檔案類型,包括:

  • 原始碼(.py、.js、.ts、.go、.rs 等)
  • 資料檔案(.csv、.json、.xml、.yaml)
  • 文件(.txt、.md)
  • 壓縮檔(.zip、.tar.gz)— 代理程式可以使用 bash 解壓縮這些檔案
  • 二進位檔案 — 代理程式可以使用適當的工具處理這些檔案

檔案路徑



掛載在沙箱中的檔案是唯讀副本。代理程式可以讀取它們,但無法修改原始上傳的檔案。若要處理修改後的版本,代理程式會寫入沙箱內的新路徑。

  • 檔案會掛載在您指定的確切路徑
  • 父目錄會自動建立
  • 路徑應為絕對路徑(以 / 開頭)

Was this page helpful?

  • 上傳檔案
  • 在工作階段中掛載檔案
  • 多個檔案
  • 管理執行中工作階段的檔案
  • 列出和下載工作階段檔案
  • 支援的檔案類型
  • 檔案路徑