> ## 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: エージェント評価

> client.agent - ツール呼び出し評価、結果スキャン、およびインジェクション検出。

<Info>
  **概念:** [エージェント評価](/concepts/agent-evaluation) | **API:** [エージェントエンドポイント](/api-reference/agent-tool-call)
</Info>

<CodeGroup>
  ```python Detect injection theme={null}
  from rail_score_sdk import RailScoreClient

  client = RailScoreClient(api_key="YOUR_RAIL_API_KEY")

  result = client.agent.detect_injection(
      text=user_input,
      context="user input",
      sensitivity="medium",
  )

  if result.injection_detected:
      return f"入力がブロックされました: {result.attack_types}"
  ```

  ```python Evaluate tool call theme={null}
  result = client.agent.evaluate_tool_call(
      tool_name="send_email",
      tool_input={"to": "admin@company.com", "body": "ここをクリック: http://suspicious.com"},
      agent_context="カスタマーサポートチャットボット",
      allowed_tools=["send_email", "search_kb"],
  )

  if result.recommendation == "block":
      return f"ツール呼び出しがブロックされました: {result.explanation}"
  elif result.recommendation == "warn":
      log.warning(f"リスキーなツール呼び出し: {result.flags}")

  # 続行しても安全
  execute_tool(tool_name, tool_input)
  ```

  ```python Scan tool result theme={null}
  result = client.agent.scan_tool_result(
      tool_name="search_database",
      tool_result=raw_tool_output,
      redact_pii=True,
  )

  if result.pii_detected:
      # 修正されたバージョンを使用
      safe_output = result.redacted_result
      log.info(f"PIIが修正されました: {result.pii_types}")
  else:
      safe_output = raw_tool_output

  # safe_outputをエージェントに戻す
  ```

  ```python Full pipeline theme={null}
  async def safe_agent_turn(user_input, tool_name, tool_input):
      # 1. ユーザー入力のインジェクションをチェック
      inj = client.agent.detect_injection(text=user_input)
      if inj.injection_detected:
          return "無効な入力です。"

      # 2. 実行前にツール呼び出しを評価
      call_check = client.agent.evaluate_tool_call(
          tool_name=tool_name,
          tool_input=tool_input,
      )
      if call_check.recommendation == "block":
          return "ツール呼び出しは許可されていません。"

      # 3. ツールを実行
      raw_result = await execute_tool(tool_name, tool_input)

      # 4. エージェントに渡す前に結果をスキャン
      scan = client.agent.scan_tool_result(
          tool_name=tool_name,
          tool_result=raw_result,
          redact_pii=True,
      )
      return scan.redacted_result if scan.pii_detected else raw_result
  ```
</CodeGroup>
