Microsoft Foundry SDK を使用して会話をシミュレートする (プレビュー)

Important

この記事で "(プレビュー)" と付記されている項目は、現在、パブリック プレビュー段階です。 このプレビューはサービス レベル アグリーメントなしで提供されており、運用環境ではお勧めしません。 特定の機能がサポートされていないか、機能が制限されている可能性があります。 詳細については、「 Microsoft Azure プレビューの追加使用条件」を参照してください。

シナリオの説明からシミュレートされた会話を生成し、会話レベルで評価します。 このシナリオを使用して、デプロイ前に制御された状況でエージェントの動作をテストします。 サービスは、シナリオの説明に基づいて現実的な会話を生成し、それらを評価します。

前提条件

  • クラウド評価の前提条件とクライアントのセットアップを完了します。
  • ユーザーをシミュレートするモデル デプロイ。
  • 評価するエージェント ターゲット。
  • シミュレートする相互作用を記述するシナリオ データ。

この例では、「SDK クライアントのセットアップ」で構成された SDK クライアントを使用します

会話シミュレーションを理解する

この方法は、次の場合に役立ちます。

  • デプロイ前テスト: 実際のユーザー トラフィックなしで、さまざまなシナリオでエージェントの動作を検証します。
  • エッジ ケース カバレッジ: 自然にはほとんど発生しないが、適切に処理することが重要なシナリオをテストします。
  • 回帰テスト: 既知のシナリオでエージェントの更新によってパフォーマンスが低下しないようにします。
  • スケール テスト: ストレス テスト エージェントの機能に対して多くの会話をすばやく生成します。

会話シミュレーションは、次の手順に従います。

  1. シナリオの説明のデータセットを指定します。各行には、シミュレートされたユーザーが実行しようとする状況が記述されています。
  2. このサービスでは、シミュレーター モデルを使用してユーザーの役割を果たし、シナリオに基づいてエージェントと対話します。
  3. 各シナリオでは、1 つ以上の完全な会話が生成されます。
  4. 会話レベルのエバリュエーターは、生成された会話を評価します。
  5. プロジェクトには、会話と評価結果の両方が格納されます。

シナリオ データを準備する

ヒント

シナリオを手動で作成する代わりに、 シミュレーション シード (複数ターン) タスクの種類を使用して生成します。 生成されたデータセットには、必要な test_case_description フィールドが含まれており、 idcategory、および desired_num_turnsを含めることもできます。 生成されたデータセットの ID をシミュレーション実行の scenarios_id として使用し、アップロード手順をスキップします。 シミュレーション シード データセットの生成を参照してください。

シミュレートされたユーザーのシナリオを各行に記述する JSONL ファイルを作成します。 各行には test_case_descriptionが含まれている必要があります。 idcategory、およびdesired_num_turnsフィールドは省略可能です。 ユーザーの目標、コンテキスト、制約に関する詳細を含めます。 完全な例については、SDK の conversation 評価サンプルを参照してください。

{"id": "contoso_refund_timeline", "test_case_description": "Customer returned an item to Contoso Electronics 5 days ago and hasn't received their refund yet. They want to know how long Contoso refunds take.", "desired_num_turns": 10}
{"id": "contoso_store_hours_lookup", "test_case_description": "Customer wants to know what time the Contoso Electronics store closes today. Simple single-fact question with possibly one clarifying turn about which location.", "desired_num_turns": 3}

シミュレーションを構成するには、次のパラメーターを使用します。

パラメーター 必須 説明
num_conversations いいえ シナリオごとに生成する会話の数。 既定値は 5、サーバー側の上限は 5 です。
max_turns いいえ 会話あたりのターン (交換) の最大数。 既定値は 10、サーバー側の上限は 50 です。
model はい ユーザーのシミュレートに使用するモデルデプロイ。 たとえば、「 gpt-4.1 」のように入力します。 モデル ルーターはシミュレーター モデルとしてサポートされていません。評価対象としてのみ使用できます。
sampling_params いいえ シミュレーター モデルのサンプリング パラメーター ( temperaturetop_pmax_completion_tokensなど)。
data_mapping いいえ シナリオ JSONL のフィールドをシミュレーション パラメーターにマップします。 一般的なマッピング: test_case_descriptioniddesired_num_turns

エバリュエーターの定義

会話レベルの評価用に設計されたエバリュエーターを選択します。 シミュレートされた会話は、エバリュエーターに自動的にマップされます。

import os
from openai.types.eval_create_params import DataSourceConfigCustom
from azure.identity import DefaultAzureCredential
from azure.ai.projects import AIProjectClient
from azure.ai.projects.models import TestingCriterionAzureAIEvaluator, PromptAgentDefinition

endpoint = os.environ["AZURE_AI_PROJECT_ENDPOINT"]
model_deployment_name = os.environ["AZURE_AI_MODEL_DEPLOYMENT_NAME"]
agent_name = os.environ.get("FOUNDRY_AGENT_NAME", "")

with (
    DefaultAzureCredential() as credential,
    AIProjectClient(endpoint=endpoint, credential=credential) as project_client,
    project_client.get_openai_client() as openai_client,
):
    # Simulation uses the same "custom" eval group type as dataset evaluation (S1),
    # since the generated conversations follow the same messages schema.
    data_source_config = DataSourceConfigCustom(
        type="custom",
        item_schema={
            "type": "object",
            "properties": {
                "messages": {"type": "array"},
            },
            "required": ["messages"],
        },
        include_sample_schema=False,
    )

    testing_criteria = [
        TestingCriterionAzureAIEvaluator(
            type="azure_ai_evaluator",
            name="customer_satisfaction",
            evaluator_name="builtin.customer_satisfaction",
            initialization_parameters={"model": model_deployment_name},
            data_mapping={"messages": "{{item.messages}}"},
        ),
        TestingCriterionAzureAIEvaluator(
            type="azure_ai_evaluator",
            name="task_completion",
            evaluator_name="builtin.task_completion",
            initialization_parameters={"model": model_deployment_name},
            data_mapping={"messages": "{{item.messages}}"},
        ),
    ]

評価を作成して実行する

sample_data_simulation_scenarios.jsonl をダウンロードします。

# Create (or update) an agent to simulate against
agent = project_client.agents.create_version(
    agent_name=agent_name,
    definition=PromptAgentDefinition(
        model=model_deployment_name,
        instructions="You are a helpful customer service agent. Be empathetic and solution-oriented.",
    ),
)

# Upload scenario data
scenarios_id = project_client.datasets.upload_file(
    name="simulation-scenarios",
    version="1",
    file_path="./sample_data_simulation_scenarios.jsonl",
).id

# Create the evaluation
eval_object = openai_client.evals.create(
    name="Multi-turn Conversation Simulation",
    data_source_config=data_source_config,
    testing_criteria=testing_criteria,
)

# Create a simulation run
eval_run = openai_client.evals.runs.create(
    eval_id=eval_object.id,
    name="conversation-simulation-run",
    data_source={
        "type": "azure_ai_target_completions",
        "source": {
            "type": "file_id",
            "id": scenarios_id,
        },
        "target": {
            "type": "azure_ai_agent",
            "name": agent.name,
            "version": agent.version,
        },
        "item_generation_params": {
            "type": "conversation_gen_preview",
            "model": model_deployment_name,
            "num_conversations": 2,
            "max_turns": 5,
            "sampling_params": {
                "temperature": 0.7,
                "top_p": 1.0,
                "max_completion_tokens": 800,
            },
            "data_mapping": {
                "test_case_description": "test_case_description",
                "id": "id",
                "desired_num_turns": "desired_num_turns",
            },
        },
    },
    extra_body={"evaluation_level": "conversation"},
)

次のステップ