> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-HK/llms.txt # 評分器 檔案式 Agent 會在其 `scorers/` 目錄中探索[評分器](https://mastra.zisheng.pro/zh-HK/docs/evals/overview)。本頁說明檔案式慣例;如需了解內置評分器、自訂評分器及取樣,請參閱評分器指南。 `scorers/` 下的每個檔案都會預設匯出一個評分器,而檔案名稱會成為其鍵。預設匯出的內容可以是 [`MastraScorer`](https://mastra.zisheng.pro/zh-HK/reference/evals/create-scorer),或 `{ scorer, sampling }` 項目。 ## 快速開始 將評分器檔案放在 Agent 的 `scorers/` 目錄下,即可加入評分器。以下範例使用[自訂評分器](https://mastra.zisheng.pro/zh-HK/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) ``` 此評分器會以 `relevance` 鍵註冊至 `weather` Agent,效果與將其加入 `config.scorers` 相同。 ## 取樣 如要控制評分器的執行頻率,請預設匯出 `{ scorer, sampling }` 項目,而非單獨的評分器: ```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 的優先次序 系統會將探索到的評分器,與 [`config.ts`](https://mastra.zisheng.pro/zh-HK/reference/file-based-agents/config) 中定義的評分器合併。如果鍵發生衝突,`config.scorers` 會優先,並顯示警告。如果 `config.scorers` 是函數,系統會忽略探索到的評分器並顯示警告,因為函數值評分器無法以靜態方式合併。 鍵發生衝突時,優先次序如下: 1. 函數值 `config.scorers` 2. 記錄值 `config.scorers` 3. 在 `scorers/` 下探索到的檔案 系統會保留鍵並無衝突的已探索評分器。 如需完整評分器介面,請參閱 [`createScorer()`](https://mastra.zisheng.pro/zh-HK/reference/evals/create-scorer)。