Loading...
    • ビルド
    • 管理
    • モデルと料金
    • クライアントSDK
    • APIリファレンス
    Search...
    ⌘K
    はじめに
    Claudeの概要クイックスタート
    Claudeで構築する
    機能概要Messages APIの使用停止理由の処理
    モデルの機能
    拡張思考適応的思考エフォート高速モード(ベータ:リサーチプレビュー)構造化出力引用ストリーミングメッセージバッチ処理検索結果ストリーミング拒否多言語サポート埋め込み
    ツール
    概要ツール使用の仕組みウェブ検索ツールウェブフェッチツールコード実行ツールメモリツールBashツールコンピューター使用ツールテキストエディタツール
    ツールインフラ
    ツール検索プログラムによるツール呼び出し細粒度ツールストリーミング
    コンテキスト管理
    コンテキストウィンドウコンパクションコンテキスト編集プロンプトキャッシュトークンカウント
    ファイルの操作
    Files APIPDFサポート画像とビジョン
    スキル
    概要クイックスタートベストプラクティスエンタープライズ向けスキルAPIのスキル
    MCP
    リモートMCPサーバーMCPコネクター
    プロンプトエンジニアリング
    概要プロンプトのベストプラクティスConsoleプロンプトツール
    テストと評価
    成功の定義と評価の構築ConsoleでのEvaluation Toolの使用レイテンシの削減
    ガードレールの強化
    幻覚の低減出力の一貫性向上ジェイルブレイクの軽減プロンプトリークの低減
    リソース
    用語集
    リリースノート
    Claude Platform
    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
    はじめに

    Claude Managed Agentsを始める

    最初の自律エージェントを作成します。

    Was this page helpful?

    • CLIのインストール
    • SDKのインストール

    このガイドでは、エージェントの作成、環境のセットアップ、セッションの開始、エージェントレスポンスのストリーミングについて説明します。

    コアコンセプト

    ConceptDescription
    AgentThe model, system prompt, tools, MCP servers, and skills
    EnvironmentA configured container template (packages, network access)
    SessionA running agent instance within an environment, performing a specific task and generating outputs
    EventsMessages exchanged between your application and the agent (user turns, tool results, status updates)

    前提条件

    • Anthropic Consoleアカウント
    • APIキー

    CLIのインストール

    インストールを確認します:

    ant --version

    SDKのインストール

    APIキーを環境変数として設定します:

    export ANTHROPIC_API_KEY="your-api-key-here"

    最初のセッションを作成する

    すべてのManaged Agents APIリクエストにはmanaged-agents-2026-04-01ベータヘッダーが必要です。SDKはベータヘッダーを自動的に設定します。

    何が起きているか

    ユーザーイベントを送信すると、Claude Managed Agentsは:

    1. コンテナをプロビジョニングします: 環境設定によってビルド方法が決まります。
    2. エージェントループを実行します: Claudeはメッセージに基づいて使用するツールを決定します
    3. ツールを実行します: ファイル書き込み、bashコマンド、その他のツール呼び出しがコンテナ内で実行されます
    4. イベントをストリーミングします: エージェントが作業している間、リアルタイムの更新を受け取ります
    5. アイドル状態になります: エージェントはこれ以上行うことがなくなるとsession.status_idleイベントを発行します

    次のステップ

    エージェントを定義する

    再利用可能なバージョン管理されたエージェント設定を作成します

    1. 1

      エージェントを作成する

      モデル、システムプロンプト、利用可能なツールを定義するエージェントを作成します。

      set -euo pipefail
      
      agent=$(
        curl -sS --fail-with-body https://api.anthropic.com/v1/agents \
          -H "x-api-key: $ANTHROPIC_API_KEY" \
          -H "anthropic-version: 2023-06-01" \
          -H "anthropic-beta: managed-agents-2026-04-01" \
          -H "content-type: application/json" \
          -d @- <<'EOF'
      {
        "name": "Coding Assistant",
        "model": "claude-sonnet-4-6",
        "system": "You are a helpful coding assistant. Write clean, well-documented code.",
        "tools": [
          {"type": "agent_toolset_20260401"}
        ]
      }
      EOF
      )
      
      AGENT_ID=$(jq -er '.id' <<<"$agent")
      AGENT_VERSION=$(jq -er '.version' <<<"$agent")
      
      echo "Agent ID: $AGENT_ID, version: $AGENT_VERSION"

      agent_toolset_20260401ツールタイプは、事前構築されたエージェントツールのフルセット(bash、ファイル操作、ウェブ検索など)を有効にします。完全なリストとツールごとの設定オプションについてはツールを参照してください。

      返されたagent.idを保存してください。作成するすべてのセッションで参照します。

    2. 2

      環境を作成する

      環境は、エージェントが実行されるコンテナを定義します。

      environment=$(
        curl -sS --fail-with-body https://api.anthropic.com/v1/environments \
          -H "x-api-key: $ANTHROPIC_API_KEY" \
          -H "anthropic-version: 2023-06-01" \
          -H "anthropic-beta: managed-agents-2026-04-01" \
          -H "content-type: application/json" \
          -d @- <<'EOF'
      {
        "name": "quickstart-env",
        "config": {
          "type": "cloud",
          "networking": {"type": "unrestricted"}
        }
      }
      EOF
      )
      
      ENVIRONMENT_ID=$(jq -er '.id' <<<"$environment")
      
      echo "Environment ID: $ENVIRONMENT_ID"

      返されたenvironment.idを保存してください。作成するすべてのセッションで参照します。

    3. 3

      セッションを開始する

      エージェントと環境を参照するセッションを作成します。

      session=$(
        curl -sS --fail-with-body https://api.anthropic.com/v1/sessions \
          -H "x-api-key: $ANTHROPIC_API_KEY" \
          -H "anthropic-version: 2023-06-01" \
          -H "anthropic-beta: managed-agents-2026-04-01" \
          -H "content-type: application/json" \
          -d @- <<EOF
      {
        "agent": "$AGENT_ID",
        "environment_id": "$ENVIRONMENT_ID",
        "title": "Quickstart session"
      }
      EOF
      )
      
      SESSION_ID=$(jq -er '.id' <<<"$session")
      
      echo "Session ID: $SESSION_ID"
    4. 4

      メッセージを送信してレスポンスをストリーミングする

      ストリームを開き、ユーザーイベントを送信し、到着したイベントを処理します:

      # Send the user message first; the API buffers events until the stream attaches
      curl -sS --fail-with-body \
        "https://api.anthropic.com/v1/sessions/$SESSION_ID/events" \
        -H "x-api-key: $ANTHROPIC_API_KEY" \
        -H "anthropic-version: 2023-06-01" \
        -H "anthropic-beta: managed-agents-2026-04-01" \
        -H "content-type: application/json" \
        -d @- >/dev/null <<'EOF'
      {
        "events": [
          {
            "type": "user.message",
            "content": [
              {
                "type": "text",
                "text": "Create a Python script that generates the first 20 Fibonacci numbers and saves them to fibonacci.txt"
              }
            ]
          }
        ]
      }
      EOF
      
      # Open the SSE stream and process events as they arrive
      while IFS= read -r line; do
        [[ $line == data:* ]] || continue
        json=${line#data: }
        case $(jq -r '.type' <<<"$json") in
          agent.message)
            jq -j '.content[] | select(.type == "text") | .text' <<<"$json"
            ;;
          agent.tool_use)
            printf '\n[Using tool: %s]\n' "$(jq -r '.name' <<<"$json")"
            ;;
          session.status_idle)
            printf '\n\nAgent finished.\n'
            break
            ;;
        esac
      done < <(
        curl -sS -N --fail-with-body \
          "https://api.anthropic.com/v1/sessions/$SESSION_ID/stream" \
          -H "x-api-key: $ANTHROPIC_API_KEY" \
          -H "anthropic-version: 2023-06-01" \
          -H "anthropic-beta: managed-agents-2026-04-01" \
          -H "Accept: text/event-stream"
      )

      エージェントはPythonスクリプトを作成し、コンテナ内で実行し、出力ファイルが作成されたことを確認します。出力はこのようになります:

      I'll create a Python script that generates the first 20 Fibonacci numbers and saves them to a file.
      [Using tool: write]
      [Using tool: bash]
      The script ran successfully. Let me verify the output file.
      [Using tool: bash]
      fibonacci.txt contains the first 20 Fibonacci numbers (0 through 4181).
      
      Agent finished.
    環境を設定する

    ネットワークとコンテナの設定をカスタマイズします

    エージェントツール

    エージェントの特定のツールを有効にします

    イベントとストリーミング

    イベントを処理し、実行中にエージェントを操作します