Loading...
  • 建構
  • 管理
  • 模型與定價
  • 客戶端 SDK
  • API 參考
Search...
⌘K
Log in
新增檔案
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Solutions

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

Partners

  • Amazon Bedrock
  • Google Cloud's Vertex AI

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
建構/將工作委派給代理

新增檔案

上傳檔案並將其掛載到容器中以供讀取和處理。

Was this page helpful?

您可以透過 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 是選用的,但請確保上傳的檔案具有描述性名稱,以便代理程式知道要尋找什麼。

將建立一個新的 file_id,用於參考工作階段中檔案的執行個體。這些副本不會計入您的儲存空間限制。

多個檔案

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

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

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

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

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

列出和下載工作階段檔案

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

支援的檔案類型

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

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

檔案路徑

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

  • 檔案會掛載在您指定的確切路徑
  • 父目錄會自動建立
  • 路徑應該是絕對路徑(以 / 開頭)
session = client.beta.sessions.create(
    agent=agent.id,
    environment_id=environment.id,
    resources=[
        {
            "type": "file",
            "file_id": file.id,
            "mount_path": "/workspace/data.csv",
        },
    ],
)
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"},
]
resource = client.beta.sessions.resources.add(
    session.id,
    type="file",
    file_id=file.id,
)
print(resource.id)  # "sesrsc_01ABC..."
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)
# List files associated with a session
files = client.beta.files.list(
    scope_id="sesn_abc123",
    betas=["managed-agents-2026-04-01"],
)
for f in files:
    print(f.id, f.filename)

# Download a file
content = client.beta.files.download(files.data[0].id)
content.write_to_file("output.txt")