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

# Python: セッション

> RAILSession - マルチターン会話におけるRAILスコアを追跡します。

<Info>
  **概念:** [ポリシーエンジン](/concepts/policy-engine) | **API:** [評価API](/api-reference/evaluation)
</Info>

`RAILSession` は会話の各ターンを追跡し、集計統計を計算し、個々のターンだけでなく全体的な品質が漂流したときに発動するセッションレベルのポリシーを強制することができます。

<CodeGroup>
  ```python Basic session theme={null}
  from rail_score_sdk import RailScoreClient, RAILSession

  client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")
  session = RAILSession(client=client)

  for response in conversation_responses:
      outcome = session.record(content=response, mode="basic")
      print(f"ターンスコア: {outcome.score}")
      print(f"セッション平均: {session.average_score}")

  print(f"セッション概要: {session.summary}")
  ```

  ```python With turn + session policies theme={null}
  from rail_score_sdk import RailScoreClient, RAILSession, Policy, Rule

  client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")

  turn_policy = Policy(rules=[
      Rule(dimension="safety", threshold=5.0, action="block"),
  ])

  session_policy = Policy(rules=[
      Rule(dimension="safety", threshold=7.0, action="flag", aggregate="avg"),
  ])

  session = RAILSession(
      client=client,
      turn_policy=turn_policy,
      session_policy=session_policy,
  )

  for user_message in conversation:
      response = await llm(user_message)
      outcome = session.record(content=response, mode="basic")

      if outcome.turn_blocked:
          send_fallback()
      elif outcome.session_flagged:
          notify_reviewer(session.session_id)
      else:
          send(response)
  ```
</CodeGroup>

## セッションプロパティ

| プロパティ                   | タイプ     | 説明                   |
| ----------------------- | ------- | -------------------- |
| `session.session_id`    | `str`   | ユニークなセッション識別子        |
| `session.turn_count`    | `int`   | 記録されたターンの数           |
| `session.average_score` | `float` | すべてのターンにおける平均RAILスコア |
| `session.min_score`     | `float` | セッション内の最低ターンスコア      |
| `session.summary`       | `dict`  | 次元ごとの集計統計            |
