Mastra 推出 Classifiers:用评估模型做快速可预测决策
Introducing Classifiers with Jev | Mastra Blog
Mastra 上线 Classifiers,可在评估模型上定义 choice、score、boolean 三类问题并设置评估标准,用答案驱动快速、可预测的决策。每个 criteria key 都会返回概率,最高者成为 choice,答案同时说明决策依据;一个 classifier 可混合多个问题、共用同一输入,并按问题名索引答案。Classifiers 与 agents、tools、workflows 一样注册在主 Mastra 实例上,可接入 workflow 分支逻辑选择合适 agent。
正文
当前显示原文,中文全文译文尚未就绪。
You can now use evaluation models in Mastra with a classifier. Define questions as choice, score, or boolean, then set the criteria to evaluate, and use the answer to make fast, predictable decisions.
With an evaluation model, you provide instructions describing what to decide and criteria outlining what can be answered. A choice returns one of the criteria keys, a score returns a position from an ordered list, and a boolean returns the probability the answer is true.
We shipped this after the dramatic rise of Jev a couple weeks ago, and ran a workshop showing how it works: Building a Classifier in Mastra with Jev.
Before classifiers, picking from a fixed set of options meant prompting an LLM, describing the options, defining the output shape, then parsing and validating whatever came back. With a classifier, the options are the criteria, and the answer shows why the decision was made, with a probability for each option, so your code can decide what happens next.
A classifier can hold several questions of mixed types, all evaluated against the same input, with each answer keyed by the question name you gave it. instructions and criteria aren't limited to strings either — both accept any JSON-compatible value, so a criteria description can be an object or an array.
Install the latest Mastra core package and an evaluation model provider:
Define a classifier with an id, a model, and one or more questions. This example uses a route question with the "choice" type to pick one key from the defined criteria.
Classifiers are registered on the main Mastra instance, the same as agents, tools and workflows:
A classifier will return an answers object similar to this:
Each criteria key gets a probability, and the highest one becomes the choice. A workflow can use the choice to drive the branch logic and pick an appropriate agent to answer the user's query:
For more information and full configuration options, see:
Classifier reference; Workflow.classifier reference; ClassifierProcessor reference; createClassifierScorer reference