> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ja/llms.txt # CI で Scorer を実行する CI パイプラインで Scorer を実行すると、時間の経過に伴う Agent の品質を測定するための定量的な指標を得られます。`runEvals` 関数は、Agent または Workflow を通じて複数のテストケースを処理し、集計スコアを返します。 ## 基本設定 [Vitest](https://vitest.dev/)、[Jest](https://jestjs.io/)、[Mocha](https://mochajs.org/) など、ESM モジュールをサポートする任意のテストフレームワークを使用できます。 ## テストケースの作成 `runEvals` を使用して、複数のテストケースに対して Agent を評価します。この関数はデータ項目の配列を受け取ります。各項目には `input` と、Scorer の検証に使用する任意の `groundTruth` が含まれます。 ```typescript import { describe, it, expect } from 'vitest' import { createScorer, runEvals } from '@mastra/core/evals' import { weatherAgent } from './weather-agent' import { locationScorer } from '../scorers/location-scorer' describe('Weather Agent Tests', () => { it('should correctly extract locations from queries', async () => { const result = await runEvals({ data: [ { input: 'weather in Berlin', groundTruth: { expectedLocation: 'Berlin', expectedCountry: 'DE' }, }, { input: 'weather in Berlin, Maryland', groundTruth: { expectedLocation: 'Berlin', expectedCountry: 'US' }, }, { input: 'weather in Berlin, Russia', groundTruth: { expectedLocation: 'Berlin', expectedCountry: 'RU' }, }, ], target: weatherAgent, scorers: [locationScorer], }) // Assert aggregate score meets threshold expect(result.scores['location-accuracy']).toBe(1) expect(result.summary.totalItems).toBe(3) }) }) ``` ## 結果を理解する `runEvals` 関数は、次の内容を持つオブジェクトを返します。 - `scores`: すべてのテストケースにおける各 Scorer の平均スコア - `summary.totalItems`: 処理されたテストケースの総数 ```typescript { scores: { 'location-accuracy': 1.0, // Average score across all items 'another-scorer': 0.85 }, summary: { totalItems: 3 } } ``` ## 複数のテストシナリオ 評価シナリオごとに個別のテストケースを作成します。 ```typescript describe('Weather Agent Tests', () => { const locationScorer = createScorer({/* ... */}) it('should handle location disambiguation', async () => { const result = await runEvals({ data: [ { input: 'weather in Berlin', groundTruth: {/* ... */}, }, { input: 'weather in Berlin, Maryland', groundTruth: {/* ... */}, }, ], target: weatherAgent, scorers: [locationScorer], }) expect(result.scores['location-accuracy']).toBe(1) }) it('should handle typos and misspellings', async () => { const result = await runEvals({ data: [ { input: 'weather in Berln', groundTruth: { expectedLocation: 'Berlin', expectedCountry: 'DE' }, }, { input: 'weather in Parris', groundTruth: { expectedLocation: 'Paris', expectedCountry: 'FR' }, }, ], target: weatherAgent, scorers: [locationScorer], }) expect(result.scores['location-accuracy']).toBe(1) }) }) ``` ## 次のステップ - [カスタム Scorer の作成](https://mastra.zisheng.pro/ja/docs/evals/custom-scorers)について学ぶ - [組み込み Scorer](https://mastra.zisheng.pro/ja/docs/evals/built-in-scorers)を確認する - [Memory が有効な Agent](https://mastra.zisheng.pro/ja/docs/evals/evals-with-memory)に対して Scorer を実行する - [runEvals API リファレンス](https://mastra.zisheng.pro/ja/reference/evals/run-evals)を読む