UNPKG

@mastra/core

Version:

Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.

54 lines (38 loc) 1.6 kB
# getScorer() The `getScorer()` method retrieves a specific scorer that was registered with the Mastra instance using its registration key. This method provides type-safe access to scorers and throws an error if the requested scorer isn't found. ## Usage example ```typescript import { mastra } from './mastra' // Get a specific scorer by key const relevancyScorer = mastra.getScorer('relevancyScorer') const weatherAgent = mastra.getAgent('weatherAgent') // Use the scorer to evaluate an AI output await weatherAgent.generate('What is the weather in Rome', { scorers: { answerRelevancy: { scorer: relevancyScorer, }, }, }) ``` ## Parameters **key** (`string`): The registration key of the scorer to retrieve. This should match a key used when registering scorers in the Mastra constructor. ## Returns **scorer** (`MastraScorer`): The MastraScorer instance associated with the provided key. ## Error handling This method throws a `MastraError` if: - The scorer with the specified key isn't found - No scorers are registered with the Mastra instance ```typescript try { const scorer = mastra.getScorer('nonExistentScorer') } catch (error) { if (error.id === 'MASTRA_GET_SCORER_NOT_FOUND') { console.log('Scorer not found, using default evaluation') } } ``` ## Related - [listScorers()](https://mastra.ai/reference/core/listScorers): Get all registered scorers - [getScorerById()](https://mastra.ai/reference/core/getScorerById): Get a scorer by its id property - [Custom Scorers](https://mastra.ai/docs/evals/custom-scorers): Learn how to create custom scorers