> ## Documentation Index
> Fetch the complete documentation index at: https://adcp-docs-ja.pier1.co.jp/llms.txt
> Use this file to discover all available pages before exploring further.

# si_terminate_session

SI セッションを終了します。ホストまたはブランドエージェントのいずれからでも終了を開始でき、理由によってセッションの締め方が示されます。

## リクエスト

| Field                 | Type   | Required | Description    |
| --------------------- | ------ | -------- | -------------- |
| `session_id`          | string | Yes      | 終了するセッション ID   |
| `reason`              | string | Yes      | セッション終了の理由     |
| `termination_context` | object | No       | 終了に関する追加コンテキスト |

### 終了理由

| Reason                | Meaning           | Typical Initiator               |
| --------------------- | ----------------- | ------------------------------- |
| `handoff_transaction` | ユーザーが購入を完了したい     | ブランドエージェント（pending\_handoff 経由） |
| `handoff_complete`    | 会話が自然に終了          | ブランドエージェント                      |
| `user_exit`           | ユーザーが明示的に会話を終了    | Host                            |
| `session_timeout`     | 非アクティブのタイムアウト到達   | Host                            |
| `host_terminated`     | ポリシー/エラー理由でホストが終了 | Host                            |

### Termination Context オブジェクト

追加詳細は理由によって異なります:

**`handoff_transaction` の場合:**

```json theme={null}
{
  "intent": { /* purchase intent from handoff */ },
  "context_for_checkout": { /* ACP context */ }
}
```

**`user_exit` の場合:**

```json theme={null}
{
  "user_signal": "changed_topic",
  "partial_context": { /* what was discussed */ }
}
```

**`session_timeout` の場合:**

```json theme={null}
{
  "last_activity": "2026-01-18T10:30:00Z",
  "timeout_seconds": 300
}
```

## レスポンス

| Field         | Type    | Description           |
| ------------- | ------- | --------------------- |
| `session_id`  | string  | どのセッションが終了したかの確認      |
| `terminated`  | boolean | 成功時は常に `true`         |
| `acp_handoff` | object  | 取引ハンドオフ時に含まれる         |
| `follow_up`   | object  | 将来のエンゲージメント向けの任意アクション |

### ACP Handoff オブジェクト

取引終了の場合、ACP チェックアウトに必要なデータを含みます:

| Field          | Type   | Description                     |
| -------------- | ------ | ------------------------------- |
| `checkout_url` | string | ブランドの ACP チェックアウトエンドポイント        |
| `payload`      | object | ACP に渡すデータ                      |
| `expires_at`   | string | チェックアウトコンテキストの ISO 8601 形式の有効期限 |

### Follow-Up オブジェクト

将来のエンゲージメントに向けた提案:

| Field              | Type   | Description      |
| ------------------ | ------ | ---------------- |
| `suggested_action` | string | ホストが次に行うべきこと     |
| `data`             | object | そのアクションに関する関連データ |
| `message`          | string | 表示用の任意メッセージ      |

## 例

### トランザクションハンドオフ

`type: "transaction"` の `pending_handoff` を受け取った後:

**Request:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "reason": "handoff_transaction",
  "termination_context": {
    "intent": {
      "action": "purchase",
      "product": {
        "type": "flight",
        "flight_number": "DL628"
      }
    }
  }
}
```

**Response:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "terminated": true,
  "acp_handoff": {
    "checkout_url": "https://delta.com/acp/checkout",
    "payload": {
      "session_id": "sess_abc123",
      "flight": "DL628",
      "passenger": {
        "email": "jane@example.com",
        "name": "Jane Smith"
      },
      "applied_offers": ["delta_chatgpt_3313"],
      "price": {
        "amount": 199,
        "currency": "USD"
      }
    },
    "expires_at": "2026-01-18T11:00:00Z"
  }
}
```

### Conversation Complete (No Purchase)

トランザクションなしで会話が自然に終わる場合:

**Request:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "reason": "handoff_complete"
}
```

**Response:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "terminated": true,
  "follow_up": {
    "suggested_action": "save_for_later",
    "data": {
      "flights_discussed": ["DL628", "DL632"],
      "destination": "BOS",
      "travel_date": "2026-01-27"
    },
    "message": "Let me know if you'd like to revisit Boston flights later!"
  }
}
```

### ユーザー退出

ユーザーが話題を変える、または明示的に離脱する場合:

**Request:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "reason": "user_exit",
  "termination_context": {
    "user_signal": "changed_topic",
    "partial_context": {
      "flights_viewed": ["DL628"],
      "last_topic": "seat selection"
    }
  }
}
```

**Response:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "terminated": true,
  "follow_up": {
    "suggested_action": "remind_later",
    "data": {
      "incomplete_booking": {
        "flight": "DL628",
        "step": "seat_selection"
      }
    }
  }
}
```

### セッションタイムアウト

非アクティブによるタイムアウトの場合:

**Request:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "reason": "session_timeout",
  "termination_context": {
    "last_activity": "2026-01-18T10:25:00Z",
    "timeout_seconds": 300
  }
}
```

**Response:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "terminated": true
}
```

### ホストによる終了

ホストがポリシーやエラー理由でセッションを終了する場合:

**Request:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "reason": "host_terminated",
  "termination_context": {
    "cause": "user_left_app"
  }
}
```

**Response:**

```json theme={null}
{
  "session_id": "sess_abc123",
  "terminated": true
}
```

## ACP 連携フロー

理由が `handoff_transaction` の場合:

```mermaid theme={null}
sequenceDiagram
    participant H as Host
    participant B as Brand Agent
    participant A as ACP

    H->>B: si_terminate_session(handoff_transaction)
    B->>H: { acp_handoff: { checkout_url, payload } }
    H->>A: Initiate checkout with payload
    A->>H: Checkout flow
```

1. ホストは終了レスポンスで `acp_handoff` を受け取ります
2. ホストは提供された `checkout_url` と `payload` を使って ACP チェックアウトを開始します
3. ACP がトランザクションを処理し、ユーザーとホストの信頼関係を維持します
4. ブランドは加盟店にはならず、支払いは ACP が処理します

## キーポイント

1. **常にセッションを終了する** - 会話が終わったように見えても terminate を呼び、リソースクリーンアップとフォローアップ提案を得ます。

2. **ACP ハンドオフデータには有効期限がある** - `expires_at` フィールドがチェックアウトコンテキストの有効期間を示します。

3. **フォローアップで再エンゲージメントを促す** - 取引がない終了でも将来のエンゲージメント提案を含められます。

4. **ホストが信頼を維持する** - 取引は ACP を経由し、ユーザーとホストの関係性を保つ。
