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 思考(思维链)使用 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