本教程将向您展示如何使用 Agent Skills 创建 PowerPoint 演示文稿。您将学习如何启用 Skills、发起简单请求以及访问生成的文件。
预构建的 Agent Skills 通过专业知识扩展 Claude 的能力,可用于创建文档、分析数据和处理文件等任务。Anthropic 在 API 中提供以下预构建的 Agent Skills:
想要创建自定义 Skills? 请参阅 Agent Skills Cookbook,了解如何构建具有特定领域专业知识的自定义 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,但尚未加载其完整指令。
现在使用 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 可以使用哪些 Skillstype: "anthropic": 表示这是由 Anthropic 管理的 Skillskill_id: "pptx": PowerPoint Skill 的标识符version: "latest": Skill 版本设置为最新发布的版本tools: 启用代码执行(Skills 必需)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 的代码来创建您的演示文稿。
演示文稿已在代码执行容器中创建并保存为文件。响应中包含带有文件 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"}],
)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"}],
)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,接下来可以:
通过 Claude API 使用 Skills
上传您自己的 Skills 以处理专业任务
了解编写高效 Skills 的最佳实践
了解 Claude Code 中的 Skills
探索 Skills 示例和实现模式
Was this page helpful?