> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # Scorer 檔案式 Agent 會從 `scorers/` 目錄探索 [scorer](https://mastra.zisheng.pro/zh-TW/docs/evals/overview)。本頁說明檔案式慣例;若要了解內建 scorer、自訂 scorer 與 sampling,請參閱 scorer 指南。 `scorers/` 下的每個檔案都會 default export 一個 scorer,而檔名會成為其 key。default export 可以是 [`MastraScorer`](https://mastra.zisheng.pro/zh-TW/reference/evals/create-scorer),也可以是 `{ scorer, sampling }` entry。 ## 快速開始 在 Agent 的 `scorers/` 目錄下放置檔案以新增 scorer。以下範例使用[自訂 scorer](https://mastra.zisheng.pro/zh-TW/docs/evals/custom-scorers): ```typescript import { createScorer } from '@mastra/core/evals' export default createScorer({ id: 'relevance', description: 'Scores how relevant the response is', }).generateScore(() => 1) ``` 此 scorer 會以 `relevance` key 註冊至 `weather` Agent,效果與將它加入 `config.scorers` 相同。 ## Sampling 若要控制 scorer 的執行頻率,請 default export `{ scorer, sampling }` entry,而不是單獨的 scorer: ```typescript import { createScorer } from '@mastra/core/evals' const relevance = createScorer({ id: 'relevance', description: 'Scores how relevant the response is', }).generateScore(() => 1) export default { scorer: relevance, sampling: { type: 'ratio', rate: 0.5 }, } ``` ## 與 config 的優先順序 探索到的 scorer 會與 [`config.ts`](https://mastra.zisheng.pro/zh-TW/reference/file-based-agents/config) 中定義的 scorer 合併。若 key 發生衝突,`config.scorers` 會優先,並記錄警告。如果 `config.scorers` 是函式,系統會忽略探索到的 scorer 並顯示警告,因為函式值 scorer 無法以靜態方式合併。 key 發生衝突時,優先順序如下: 1. 函式值 `config.scorers` 2. Record 值 `config.scorers` 3. 在 `scorers/` 下探索到的檔案 未衝突的已探索 scorer 會予以保留。 完整 scorer interface 請參閱 [`createScorer()`](https://mastra.zisheng.pro/zh-TW/reference/evals/create-scorer)。