Claude Platform Docs
Messagesスキル

APIでAgent Skillsを使い始める

Agent Skillsを使用して、Claude APIで10分以内にドキュメントを作成する方法を学びます。

このチュートリアルでは、Agent Skillsを使用してPowerPointプレゼンテーションを作成する方法を説明します。Skillsを有効にする方法、リクエストを行う方法、生成されたファイルにアクセスする方法を学びます。

前提条件

Agent Skillsの概要

事前構築済みのAgent Skillsは、ドキュメントの作成、データの分析、ファイルの処理などのタスクに特化した専門知識でClaudeの機能を拡張します。Anthropicは、APIで以下の事前構築済みAgent Skillsを提供しています。

  • PowerPoint (pptx): プレゼンテーションの作成と編集
  • Excel (xlsx): スプレッドシートの作成と分析
  • Word (docx): ドキュメントの作成と編集
  • PDF (pdf): PDFドキュメントの生成

ステップ1: 利用可能なSkillsを一覧表示する

まず、どのSkillsが利用可能かを確認します。Skills APIを使用して、Anthropicが管理するすべてのSkillsを一覧表示します。各言語タブは1つの連続したスクリプトからの抜粋であり、インポートとクライアントのセットアップは先頭にあります。

# Anthropic管理のSkillsを一覧表示
skills = client.skills.list(source="anthropic")

for skill in skills.data:
    print(f"{skill.id}: {skill.display_name}")

次のSkillsが表示されます: pptx、xlsx、docx、pdf。

このAPIは、各Skillのメタデータ(名前と説明)を返します。Claudeは起動時にこのメタデータを読み込み、どのSkillsが利用可能かを判断します。これは「progressive disclosure」(段階的開示)の第1段階であり、Claudeは完全な指示をまだ読み込まずにSkillsを発見します。

ステップ2: プレゼンテーションを作成する

PowerPoint Skillを使用して、再生可能エネルギーに関するプレゼンテーションを作成します。Messages APIのcontainerパラメータを使用してSkillsを指定します。

# PowerPoint Skillを使ってメッセージを作成
response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    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_20260521", "name": "code_execution"}],
)

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

このリクエストには以下の要素が含まれます。

  • model: コード実行ツールをサポートするモデル
  • container.skills: Claudeが使用できるSkillsを指定します
  • type: "anthropic": これがAnthropic管理のSkillであることを示します
  • skill_id: "pptx": PowerPoint Skillの識別子
  • version: "latest": 最新の公開バージョンに設定されたSkillのバージョン
  • tools: コード実行を有効にします(Skillsに必須)

このリクエストを行うと、Claudeはタスクを関連するSkillに自動的にマッチングします。プレゼンテーションを依頼したため、ClaudeはPowerPoint Skillが関連していると判断し、その完全な指示を読み込みます。これが段階的開示の第2段階です。その後、ClaudeはSkillのコードを実行してプレゼンテーションを作成します。

ステップ3: 作成されたファイルをダウンロードする

プレゼンテーションはコード実行コンテナ内で作成され、ファイルとして保存されました。ステップ2のresponseには、ファイルIDを持つファイル参照が含まれています。ファイルIDを抽出し、Files APIでファイルをダウンロードします。この例では、システムの一時ディレクトリに保存します。

# ファイルIDを抽出します。コード実行ツールはSkillのコードを
# Bashサブツール経由で実行し、生成されたファイルはbash_code_execution_output
# 項目としてbash_code_execution_tool_resultブロック内に現れます。
file_id = None
for block in response.content:
    if 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:
    # ファイルをダウンロードして保存
    output_path = Path(tempfile.gettempdir()) / "renewable_energy.pptx"
    file_content = client.files.download(file_id=file_id)
    file_content.write_to_file(output_path)
    print(f"Presentation saved to {output_path}")

その他の例を試す

以下のバリエーションを試してみてください。

スプレッドシートを作成する

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    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_20260521", "name": "code_execution"}],
)

Wordドキュメントを作成する

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    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_20260521", "name": "code_execution"}],
)

PDFを生成する

response = client.messages.create(
    model="claude-opus-5-5",
    max_tokens=16000,
    container={
        "skills": [{"type": "anthropic", "skill_id": "pdf", "version": "latest"}]
    },
    messages=[
        {
            "role": "user",
            "content": "Generate a PDF invoice template",
        }
    ],
    tools=[{"type": "code_execution_20260521", "name": "code_execution"}],
)

次のステップ

Claudeが発見して正しく使用できる効果的なSkillsの書き方を学びます。

Agent Skillsを使用してAPI経由でClaudeの機能を拡張する方法を学びます。

特化したタスク向けに独自のSkillsをアップロードします。

Claude CodeにおけるSkillsについて学びます。

Skillsの例と実装パターンを探索します。

Was this page helpful?