Loading...
    • 開發者指南
    • API 參考
    • MCP
    • 資源
    • 發行說明
    Search...
    ⌘K
    入門
    Claude 簡介快速開始
    模型與定價
    模型概覽選擇模型Claude 4.6 新功能遷移指南模型棄用定價
    使用 Claude 構建
    功能概覽使用 Messages API處理停止原因提示詞最佳實踐
    上下文管理
    上下文視窗壓縮上下文編輯
    功能
    提示詞快取延伸思考自適應思考思考力度串流訊息批次處理引用多語言支援Token 計數嵌入視覺PDF 支援Files API搜尋結果結構化輸出
    工具
    概覽如何實作工具使用細粒度工具串流Bash 工具程式碼執行工具程式化工具呼叫電腦使用工具文字編輯器工具網頁擷取工具網頁搜尋工具記憶工具工具搜尋工具
    Agent Skills
    概覽快速開始最佳實踐企業級 Skills透過 API 使用 Skills
    Agent SDK
    概覽快速開始TypeScript SDKTypeScript V2(預覽版)Python SDK遷移指南
    API 中的 MCP
    MCP 連接器遠端 MCP 伺服器
    第三方平台上的 Claude
    Amazon BedrockMicrosoft FoundryVertex AI
    提示詞工程
    概覽提示詞產生器使用提示詞範本提示詞改進器清晰直接使用範例(多範例提示)讓 Claude 思考(CoT)使用 XML 標籤賦予 Claude 角色(系統提示詞)串聯複雜提示詞長上下文技巧延伸思考技巧
    測試與評估
    定義成功標準開發測試案例使用評估工具降低延遲
    強化防護機制
    減少幻覺提高輸出一致性防範越獄攻擊串流拒絕減少提示詞洩漏讓 Claude 保持角色
    管理與監控
    Admin API 概覽資料駐留工作區用量與成本 APIClaude Code Analytics API零資料保留
    Console
    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
    • Catalog
    • 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
    • Catalog
    • 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
    Agent Skills

    在 API 中開始使用 Agent Skills

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

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

    先決條件

    • Anthropic 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:

    import anthropic
    
    client = anthropic.Anthropic()
    
    # List Anthropic-managed Skills
    skills = client.beta.skills.list(
        source="anthropic",
        betas=["skills-2025-10-02"]
    )
    
    for skill in skills.data:
        print(f"{skill.id}: {skill.display_title}")

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

    此 API 會回傳每個 Skill 的中繼資料:其名稱和描述。Claude 在啟動時載入此中繼資料以了解有哪些可用的 Skills。這是漸進式揭露的第一層,Claude 在不載入完整指令的情況下發現 Skills。

    步驟 2:建立簡報

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

    import anthropic
    
    client = anthropic.Anthropic()
    
    # Create a message with the PowerPoint Skill
    response = client.beta.messages.create(
        model="claude-opus-4-6",
        max_tokens=4096,
        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(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

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

    步驟 3:下載建立的檔案

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

    # Extract file ID from response
    file_id = None
    for block in response.content:
        if block.type == 'tool_use' and block.name == 'code_execution':
            # File ID is in the tool result
            for result_block in block.content:
                if hasattr(result_block, 'file_id'):
                    file_id = result_block.file_id
                    break
    
    if file_id:
        # Download the file
        file_content = client.beta.files.download(
            file_id=file_id,
            betas=["files-api-2025-04-14"]
        )
    
        # Save to disk
        with open("renewable_energy.pptx", "wb") as f:
            file_content.write_to_file(f.name)
    
        print(f"Presentation saved to renewable_energy.pptx")

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

    嘗試更多範例

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

    建立試算表

    response = client.beta.messages.create(
        model="claude-opus-4-6",
        max_tokens=4096,
        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-6",
        max_tokens=4096,
        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-6",
        max_tokens=4096,
        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 SDK 中使用 Skills

    在 TypeScript 和 Python 中以程式化方式使用 Skills

    Agent Skills Cookbook

    探索 Skills 範例和實作模式

    Was this page helpful?

    • 什麼是 Agent Skills?
    • 步驟 1:列出可用的 Skills
    • 步驟 2:建立簡報
    • 步驟 3:下載建立的檔案
    • 建立 Word 文件
    • 生成 PDF