• 訊息
  • 託管代理
  • 管理
Search...
⌘K
第一步
Claude 簡介快速入門
使用 Claude 進行建構
功能概覽使用 Messages API停止原因與備援拒絕與備援備援額度
模型能力
擴展思考自適應思考努力程度任務預算(測試版)快速模式(研究預覽)結構化輸出引用串流訊息批次處理搜尋結果串流拒絕多語言支援嵌入
工具
概覽工具使用的運作方式教學:建構使用工具的代理定義工具處理工具呼叫平行工具使用工具執行器(SDK)嚴格工具使用搭配提示快取的工具使用伺服器工具疑難排解網頁搜尋工具網頁擷取工具程式碼執行工具顧問工具記憶體工具Bash 工具電腦使用工具文字編輯器工具
工具基礎架構
工具參考管理工具上下文工具組合工具搜尋程式化工具呼叫細粒度工具串流
上下文管理
上下文視窗壓縮上下文編輯提示快取對話中系統訊息建構協調模式快取診斷(測試版)Token 計數
處理檔案
Files APIPDF 支援圖片與視覺
技能
概覽快速入門最佳實務企業技能API 中的技能
MCP
遠端 MCP 伺服器MCP 連接器
雲端平台上的 Claude
Amazon BedrockAmazon Bedrock(舊版)AWS 上的 Claude PlatformMicrosoft FoundryVertex AI
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
訊息/技能

在 API 中開始使用 Agent Skills

了解如何在 10 分鐘內使用 Agent Skills 透過 Claude API 建立文件。

本教學將向您展示如何使用 Agent Skills 建立 PowerPoint 簡報。您將學習如何啟用 Skills、發出簡單的請求,以及存取產生的檔案。

先決條件

  • Claude API 金鑰
  • 已安裝 Python 3.7+ 或 curl
  • 對發出 API 請求有基本的熟悉度

Agent Skills 概述

預建的 Agent Skills 透過專業知識擴展 Claude 的能力,可用於建立文件、分析資料和處理檔案等任務。Anthropic 在 API 中提供以下預建的 Agent Skills:

  • PowerPoint (pptx): 建立和編輯簡報
  • Excel (xlsx): 建立和分析試算表
  • Word (docx): 建立和編輯文件
  • PDF (pdf): 產生 PDF 文件

想要建立自訂 Skills 嗎? 請參閱 Agent Skills Cookbook,了解如何使用特定領域的專業知識建立您自己的 Skills 範例。

步驟 1:列出可用的 Skills

首先,檢查有哪些 Skills 可用。使用 Skills API 列出所有由 Anthropic 管理的 Skills:

# List Anthropic-managed Skills
ant beta:skills list --source anthropic

您會看到以下 Skills:pptx、xlsx、docx 和 pdf。

此 API 會回傳每個 Skill 的中繼資料:其名稱和描述。Claude 在啟動時載入這些中繼資料,以了解有哪些 Skills 可用。這是「progressive disclosure」(漸進式揭露)的第一層,Claude 在此階段發現 Skills,但尚未載入其完整指令。

步驟 2:建立簡報

現在使用 PowerPoint Skill 建立一份關於再生能源的簡報。在 Messages API 中使用 container 參數指定 Skills:

# Create a message with the PowerPoint Skill
response = client.beta.messages.create(
    model="claude-opus-4-8",
    max_tokens=16000,
    betas=["code-execution-2025-08-25", "skills-2025-10-02"],
    container={
        "skills": [{"type": "anthropic", "skill_id": "pptx", "version": "latest"}]
    },
    messages=[
        {
            "role": "user",
            "content": "Create a presentation about renewable energy with 5 slides",
        }
    ],
    tools=[{"type": "code_execution_20250825", "name": "code_execution"}],
)

print(f"stop_reason={response.stop_reason}, blocks={len(response.content)}")

讓我們分解每個部分的作用:

  • container.skills: 指定 Claude 可以使用哪些 Skills
  • type: "anthropic": 表示這是由 Anthropic 管理的 Skill
  • skill_id: "pptx": PowerPoint Skill 的識別碼
  • version: "latest": Skill 版本設定為最近發布的版本
  • tools: 啟用程式碼執行(Skills 所需)
  • Beta 標頭: code-execution-2025-08-25 和 skills-2025-10-02

此處的範例使用 code_execution_20250825 工具版本及其對應的 code-execution-2025-08-25 beta 標頭。Skills 也適用於較新的程式碼執行工具修訂版本(code_execution_20260120 及更新版本);任何程式碼執行工具版本都能滿足 Skills 的需求。無論您使用哪個版本,請確保其工具 type 和 beta 標頭與程式碼執行工具頁面保持一致,並始終包含 skills-2025-10-02。

當您發出此請求時,Claude 會自動將您的任務與相關的 Skill 進行比對。由於您要求建立簡報,Claude 判斷 PowerPoint Skill 是相關的,並載入其完整指令:這是漸進式揭露的第二層。接著 Claude 執行該 Skill 的程式碼來建立您的簡報。

步驟 3:下載建立的檔案

簡報已在程式碼執行容器中建立並儲存為檔案。回應中包含帶有檔案 ID 的檔案參照。提取檔案 ID 並使用 Files API 下載它:

# Extract file ID from the code-execution tool result. The Skill might run
# its work through either the Python or bash code-execution tool, so check
# both result types.
file_id = None
for block in response.content:
    if block.type == "code_execution_tool_result":
        if block.content.type == "code_execution_result":
            for output in block.content.content:
                file_id = output.file_id
    elif block.type == "bash_code_execution_tool_result":
        if block.content.type == "bash_code_execution_result":
            for output in block.content.content:
                file_id = output.file_id

if file_id:
    # Download the file and save it
    output_path = Path(tempfile.gettempdir()) / "renewable_energy.pptx"
    file_content = client.beta.files.download(file_id=file_id)
    file_content.write_to_file(output_path)
    print(f"Presentation saved to {output_path}")

如需處理產生檔案的完整詳細資訊,請參閱程式碼執行工具文件。

嘗試更多範例

現在您已經使用 Skills 建立了第一份文件,請嘗試以下變化:

建立試算表

response = client.beta.messages.create(
    model="claude-opus-4-8",
    max_tokens=16000,
    betas=["code-execution-2025-08-25", "skills-2025-10-02"],
    container={
        "skills": [{"type": "anthropic", "skill_id": "xlsx", "version": "latest"}]
    },
    messages=[
        {
            "role": "user",
            "content": "Create a quarterly sales tracking spreadsheet with sample data",
        }
    ],
    tools=[{"type": "code_execution_20250825", "name": "code_execution"}],
)

建立 Word 文件

response = client.beta.messages.create(
    model="claude-opus-4-8",
    max_tokens=16000,
    betas=["code-execution-2025-08-25", "skills-2025-10-02"],
    container={
        "skills": [{"type": "anthropic", "skill_id": "docx", "version": "latest"}]
    },
    messages=[
        {
            "role": "user",
            "content": "Write a 2-page report on the benefits of renewable energy",
        }
    ],
    tools=[{"type": "code_execution_20250825", "name": "code_execution"}],
)

產生 PDF

response = client.beta.messages.create(
    model="claude-opus-4-8",
    max_tokens=16000,
    betas=["code-execution-2025-08-25", "skills-2025-10-02"],
    container={
        "skills": [{"type": "anthropic", "skill_id": "pdf", "version": "latest"}]
    },
    messages=[
        {
            "role": "user",
            "content": "Generate a PDF invoice template",
        }
    ],
    tools=[{"type": "code_execution_20250825", "name": "code_execution"}],
)

後續步驟

現在您已經使用了預建的 Agent Skills,您可以:

API 指南

透過 Claude API 使用 Skills

建立自訂 Skills

上傳您自己的 Skills 以執行專業任務

撰寫指南

了解撰寫有效 Skills 的最佳實務

在 Claude Code 中使用 Skills

了解 Claude Code 中的 Skills

Agent Skills Cookbook

探索 Skills 範例和實作模式

Was this page helpful?

  • 先決條件
  • Agent Skills 概述
  • 步驟 1:列出可用的 Skills
  • 步驟 2:建立簡報
  • 步驟 3:下載建立的檔案
  • 嘗試更多範例
  • 建立試算表
  • 建立 Word 文件
  • 產生 PDF
  • 後續步驟