> ## 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.

# Actions のエージェントコンテキスト

> `event.agent` オブジェクトを使用して、Auth0 Actions でエージェントのアイデンティティとメタデータにアクセスします。

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" />

リクエストにエージェントにリンクされたクライアントが含まれる場合、Actions ランタイムは `event.agent` オブジェクトを公開します。エージェントが関与していない場合、このオブジェクトは存在しないため、既存の Actions コードには影響しません。

<div id="triggers">
  ## トリガー
</div>

`event.agent` は、次のトリガーで使用できます。

| トリガー                   | `event.agent` が使用できる場合                              |
| ---------------------- | --------------------------------------------------- |
| `credentials-exchange` | クライアントに `agent_id` が設定されているクライアントクレデンシャルグラント。       |
| `post-login`           | クライアントに `agent_id` が設定されている認可コード、トークン交換、またはデバイスフロー。 |

<div id="eventagent-object">
  ## `event.agent` オブジェクト
</div>

`event.agent` オブジェクトのスキーマは次のとおりです。

```json theme={null}
{
  "agent_id": "agt_72jbvv7LfRKYp59gtRLtkn",
  "agent_metadata": {
    "env": "prod"
  }
}
```

`event.client` は変更されず、リクエストを認証したリンク済みの OAuth クライアントを引き続き示します。

<div id="example-custom-claims-on-agent-tokens">
  ## 例: エージェントトークンのカスタムクレーム
</div>

`credentials-exchange` Action で `event.agent` を使用して、アクセストークンにエージェントのコンテキストを追加します。

```javascript theme={null}
exports.onExecuteCredentialsExchange = async (event, api) => {
  if (event.agent) {
    api.accessToken.setCustomClaim('agent_env', event.agent.agent_metadata?.env);
    api.accessToken.setCustomClaim('agent_id', event.agent.agent_id);
  }
};
```

Actions の作成について詳しくは、[Write Your First Action](/docs/ja-jp/customize/actions/write-your-first-action)をご覧ください。
