> ## Documentation Index
> Fetch the complete documentation index at: https://translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# エージェントをクライアントに関連付ける

> 1つ以上のクライアントをエージェントに関連付けると、それらのクライアントに発行されるトークンにエージェントのアイデンティティが含まれるため、帰属の確認と追跡が可能になります。

export const ReleaseStageNotice = ({feature, stage, plans, contact, terms}) => {
  const stageTextMap = {
    "beta": "Beta",
    "ea": "早期アクセス"
  };
  const stageText = stageTextMap[stage] || "製品リリース段階";
  const prsLink = "/docs/troubleshoot/product-lifecycle/product-release-stages";
  const linkify = (text, url) => {
    return <a href={url} target="_blank" rel="noreferrer" class="link">{text}</a>;
  };
  const includeDetails = (plans, contact, terms) => {
    const hasDetails = terms || plans || contact;
    if (!hasDetails) return null;
    return <span data-as="p">
            {plans && <>この機能は{linkify(`${plans}プラン`, "https://auth0.com/pricing")}でご利用いただけます。 </>}
            {contact && "参加をご希望の場合は、" + contact + "までお問い合わせください。 "}
            {terms && <>この機能を使用することにより、Oktaの該当する無料トライアル規約および{linkify("Master Subscription Agreement", "https://www.okta.com/legal")}に同意したものとみなされます。</>}
        </span>;
  };
  return <Warning>
            <span data-as="p">
                <strong>{feature}機能は現在、{linkify(stageText, prsLink)}です。</strong>
            </span>

            {includeDetails(plans, contact, terms)}
        </Warning>;
};

<ReleaseStageNotice feature="プリンシパルとしてのエージェント" stage="ea" contact="Auth0 Support" terms="true" />

[Auth0 のファーストクラスアイデンティティとして登録](/docs/ja-jp/ai-agents-mcp/agents-as-principal/register-an-agent)すると、任意の OAuth クライアントにエージェントを関連付けることができます。1 つのエージェントを複数のクライアントに関連付けることも可能です。環境やリージョンごとにクライアントを分ける場合など、複数のクライアントにわたるトークンとログで単一の `agent_id` を持つ、論理的に同一のエージェントアイデンティティを使用したい場合に便利です。

`agent_id` はクライアントオブジェクトに保存され、関連付けは動的に管理されます。

エージェントをクライアントに関連付けると、クライアントクレデンシャルグラントでは、そのクライアントに発行されるトークンにエージェントのアイデンティティがサブジェクト (`sub`) として含まれます。トークン交換および標準のログインフローでは、アクター (`act`) として含まれます。詳細については、[トークン内のエージェントアイデンティティ](/docs/ja-jp/ai-agents-mcp/agents-as-principal/agent-identity-in-tokens)を参照してください。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  `external_agent_id` を設定しているかどうかにかかわらず、内部 `agent_id` は Management API を通じてエージェントを管理するための識別子として使用されます。
</Callout>

<div id="associate-a-client-at-creation">
  ## クライアント作成時に関連付ける
</div>

`POST /api/v2/clients` でクライアントを作成する際に、`agent_id` を設定します。

```bash theme={null}
curl --request POST \
  --url 'https://YOUR_AUTH0_DOMAIN/api/v2/clients' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_MGMT_API_TOKEN' \
  --data '{
    "name": "My AI Client",
    "agent_id": "YOUR_AGENT_ID"
  }'
```

成功すると、Auth0 は設定した `agent_id` を含むクライアントオブジェクトを返します。

<div id="retrieve-the-agent-associated-client">
  ## エージェントに関連付けられたクライアントを取得する
</div>

`agent_id` をクライアントに関連付けた後、`/api/v2/clients/{id}` に `GET` リクエストを送信してクライアントオブジェクトを取得します。

```bash theme={null}
curl --request GET \
  --url 'https://YOUR_AUTH0_DOMAIN/api/v2/clients/YOUR_CLIENT_ID' \
  --header 'Authorization: Bearer YOUR_MGMT_API_TOKEN'
```

成功すると、Auth0 は設定した `agent_id` を含むクライアントオブジェクトを返します。

<div id="associate-an-existing-client">
  ## 既存のクライアントを関連付ける
</div>

既存のクライアントは、Auth0 Dashboard または Management API を使用して関連付けることができます。

<Tabs>
  <Tab title="Auth0 Dashboard">
    1. **Dashboard > Agents** に移動し、エージェントを選択して、エージェントの **Applications** タブを選択します。
    2. **Add Application** を選択し、モーダルでエージェントに関連付けるアプリケーションを選択します。複数のアプリケーションを選択できます。
    3. **Add Applications** を選択します。

    追加に成功すると、アプリケーションがエージェントの **Applications** タブに表示されます。
  </Tab>

  <Tab title="Management API">
    `PATCH /api/v2/clients/{id}` を使用して、既存のクライアントをエージェントに関連付けます。

    ```bash theme={null}
    curl --request PATCH \
      --url 'https://YOUR_AUTH0_DOMAIN/api/v2/clients/YOUR_CLIENT_ID' \
      --header 'Content-Type: application/json' \
      --header 'Authorization: Bearer YOUR_MGMT_API_TOKEN' \
      --data '{
        "agent_id": "YOUR_AGENT_ID"
      }'
    ```

    成功すると、Auth0 は設定した `agent_id` を含む更新後のクライアントオブジェクトを返します。
  </Tab>
</Tabs>

<div id="remove-the-agent-association">
  ## エージェントとの関連付けを解除する
</div>

クライアントとエージェントの関連付けを解除するには、`PATCH /api/v2/clients/{id}` を使用して `agent_id` を `null` に設定します。

```bash theme={null}
curl --request PATCH \
  --url 'https://YOUR_AUTH0_DOMAIN/api/v2/clients/YOUR_CLIENT_ID' \
  --header 'Content-Type: application/json' \
  --header 'Authorization: Bearer YOUR_MGMT_API_TOKEN' \
  --data '{
    "agent_id": null
  }'
```

関連付けを解除すると、以降クライアントに発行されるトークンにはagentのアイデンティティが含まれなくなります。既存のトークンは、有効期限が切れるまで有効です。

<div id="next-steps">
  ## 次のステップ
</div>

* Auth0 が[トークンにエージェントのアイデンティティを埋め込む方法](/docs/ja-jp/ai-agents-mcp/agents-as-principal/agent-identity-in-tokens)について学ぶ
