Documentation
¶
Overview ¶
Package scorer defines the interface and built-in implementations for evaluating AI outputs. Scorers range from deterministic string matchers to AI-based judges and persona-aware evaluators.
Index ¶
- type BehaviorTriggerScorer
- type CognitivePhaseScorer
- type CommunicationStyleScorer
- type ContainsScorer
- type CostScorer
- type CustomScorer
- type Descriptor
- type EmbeddingClient
- type ExactScorer
- type Factory
- type FactualScorer
- type Func
- type HallucinationScorer
- type Input
- type JSONSchemaScorer
- type JSONValidScorer
- type LLMClient
- type LLMJudgeScorer
- type LatencyScorer
- type LengthScorer
- type NotContainsScorer
- type Output
- type PerceptionFocusScorer
- type PersonaCoherenceScorer
- type RegexScorer
- type Registry
- func (r *Registry) Descriptors() []Descriptor
- func (r *Registry) Get(name string, config map[string]any) (Scorer, error)
- func (r *Registry) GetVersioned(name, revision string, config map[string]any) (Scorer, error)
- func (r *Registry) Has(name string) bool
- func (r *Registry) Register(name string, factory Factory)
- func (r *Registry) RegisterDescribed(d Descriptor, factory Factory)
- func (r *Registry) Revision(name string) (string, error)
- type Scorer
- type SemanticScorer
- type SkillUsageScorer
- type TraitConsistencyScorer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BehaviorTriggerScorer ¶
type BehaviorTriggerScorer struct {
// BehaviorName is the name of the behavior being tested.
BehaviorName string
// ExpectedActions are actions that should appear in the trace.
ExpectedActions []string
// TriggerKeywords are keywords that indicate the trigger was detected.
TriggerKeywords []string
}
BehaviorTriggerScorer analyzes the agent trace to verify that specific behaviors were triggered in response to conditions.
func NewBehaviorTriggerScorer ¶
func NewBehaviorTriggerScorer(name string, expectedActions, triggerKeywords []string) *BehaviorTriggerScorer
NewBehaviorTriggerScorer creates a behavior trigger scorer.
func (*BehaviorTriggerScorer) Name ¶
func (s *BehaviorTriggerScorer) Name() string
type CognitivePhaseScorer ¶
type CognitivePhaseScorer struct {
// ExpectedPhases is the ordered list of cognitive phases expected.
ExpectedPhases []string
}
CognitivePhaseScorer analyzes the agent trace for thinking strategy transitions — does the agent progress through expected cognitive phases (e.g. analysis → planning → execution → verification)?
func NewCognitivePhaseScorer ¶
func NewCognitivePhaseScorer(expectedPhases []string) *CognitivePhaseScorer
NewCognitivePhaseScorer creates a cognitive phase scorer.
func (*CognitivePhaseScorer) Name ¶
func (s *CognitivePhaseScorer) Name() string
type CommunicationStyleScorer ¶
type CommunicationStyleScorer struct {
Client LLMClient
Model string
ExpectedTone string
ExpectedFormat string
}
CommunicationStyleScorer uses an LLM to evaluate tone, formality, and verbosity of the agent output.
func NewCommunicationStyleScorer ¶
func NewCommunicationStyleScorer(client LLMClient, model, tone, format string) *CommunicationStyleScorer
NewCommunicationStyleScorer creates a communication style scorer.
func (*CommunicationStyleScorer) Name ¶
func (s *CommunicationStyleScorer) Name() string
type ContainsScorer ¶
ContainsScorer scores 1.0 if the actual output contains the expected substring.
func (*ContainsScorer) Name ¶
func (s *ContainsScorer) Name() string
type CostScorer ¶
type CostScorer struct {
MaxCost float64
}
CostScorer scores 1.0 if the cost is within the threshold. Cost is read from input.Context["cost"].
func (*CostScorer) Name ¶
func (s *CostScorer) Name() string
type CustomScorer ¶
type CustomScorer struct {
// contains filtered or unexported fields
}
CustomScorer wraps a user-provided function as a Scorer.
func FromFunc ¶
func FromFunc(name string, fn Func) *CustomScorer
FromFunc creates a named scorer from a function.
func (*CustomScorer) Name ¶
func (s *CustomScorer) Name() string
type Descriptor ¶
type Descriptor struct {
Name string
Revision string // immutable implementation revision; required for frozen evaluations
Description string
Dimension string // the human-like dimension it reports, empty for none
UsesLLM bool // true when scoring makes a model call, which costs money
// RequiresConfig is true when the scorer cannot be built without
// config, so a run-level pick with no config would be refused.
RequiresConfig bool
}
Descriptor says what a registered scorer is, for anyone listing them.
type EmbeddingClient ¶
EmbeddingClient generates vector embeddings for text.
type ExactScorer ¶
type ExactScorer struct {
CaseInsensitive bool
}
ExactScorer scores 1.0 if the actual output exactly matches the expected output.
func (*ExactScorer) Name ¶
func (s *ExactScorer) Name() string
type FactualScorer ¶
FactualScorer evaluates factual accuracy using an LLM judge.
func NewFactualScorer ¶
func NewFactualScorer(client LLMClient, model string) *FactualScorer
NewFactualScorer creates a factual accuracy scorer.
func (*FactualScorer) Name ¶
func (s *FactualScorer) Name() string
type HallucinationScorer ¶
HallucinationScorer detects hallucinated content using an LLM judge.
func NewHallucinationScorer ¶
func NewHallucinationScorer(client LLMClient, model string) *HallucinationScorer
NewHallucinationScorer creates a hallucination detection scorer.
func (*HallucinationScorer) Name ¶
func (s *HallucinationScorer) Name() string
type Input ¶
type Input struct {
Input string // User input / prompt
Expected string // Expected output (optional)
Actual string // Actual output
Trace *evalrun.RunTrace // Agent execution trace (optional, for persona scorers)
Context map[string]any // Additional context
}
Input provides all data needed for scoring.
type JSONSchemaScorer ¶
type JSONSchemaScorer struct {
Schema string
}
JSONSchemaScorer scores 1.0 if the actual output is valid JSON that matches a basic structural expectation. For full JSON Schema validation, provide a schema string.
func (*JSONSchemaScorer) Name ¶
func (s *JSONSchemaScorer) Name() string
type JSONValidScorer ¶
type JSONValidScorer struct{}
JSONValidScorer scores 1.0 if the actual output is valid JSON.
func (*JSONValidScorer) Name ¶
func (s *JSONValidScorer) Name() string
type LLMClient ¶
type LLMClient interface {
Complete(ctx context.Context, model, systemPrompt, userInput string, temperature float64) (string, error)
}
LLMClient is the interface for calling a language model for scoring.
type LLMJudgeScorer ¶
LLMJudgeScorer uses an LLM as a judge to evaluate outputs.
func NewLLMJudgeScorer ¶
func NewLLMJudgeScorer(client LLMClient, model, criteria string) *LLMJudgeScorer
NewLLMJudgeScorer creates a new LLM-as-judge scorer.
func (*LLMJudgeScorer) Name ¶
func (s *LLMJudgeScorer) Name() string
type LatencyScorer ¶
type LatencyScorer struct {
MaxMs int
}
LatencyScorer scores 1.0 if the latency is within the threshold. Latency is read from input.Context["latency_ms"].
func (*LatencyScorer) Name ¶
func (s *LatencyScorer) Name() string
type LengthScorer ¶
LengthScorer scores based on the token count of the output. Uses a simple word-split approximation for token counting.
func (*LengthScorer) Name ¶
func (s *LengthScorer) Name() string
type NotContainsScorer ¶
NotContainsScorer scores 1.0 if the actual output does NOT contain the substring.
func (*NotContainsScorer) Name ¶
func (s *NotContainsScorer) Name() string
type Output ¶
type Output struct {
Usage *evalrun.Usage // Optional judge accounting; nil means unknown, not zero.
Score float64 // 0.0 to 1.0
Passed bool // Score >= threshold
Reason string // Human-readable explanation
Dimension string // Which evaluation dimension (skill, trait, etc.)
Details map[string]any // Scorer-specific details
}
Output captures the result of a scoring evaluation.
type PerceptionFocusScorer ¶
type PerceptionFocusScorer struct {
// RequiredKeywords are terms the output must reference.
RequiredKeywords []string
// IgnoredKeywords are distractors the output should not focus on.
IgnoredKeywords []string
}
PerceptionFocusScorer evaluates whether the agent attended to the right keywords and patterns in its input, measuring perceptual focus.
func NewPerceptionFocusScorer ¶
func NewPerceptionFocusScorer(required, ignored []string) *PerceptionFocusScorer
NewPerceptionFocusScorer creates a perception focus scorer.
func (*PerceptionFocusScorer) Name ¶
func (s *PerceptionFocusScorer) Name() string
type PersonaCoherenceScorer ¶
PersonaCoherenceScorer performs holistic LLM-based evaluation of whether the agent maintains a consistent identity across all dimensions.
func NewPersonaCoherenceScorer ¶
func NewPersonaCoherenceScorer(client LLMClient, model, personaDesc string) *PersonaCoherenceScorer
NewPersonaCoherenceScorer creates a persona coherence scorer.
func (*PersonaCoherenceScorer) Name ¶
func (s *PersonaCoherenceScorer) Name() string
type RegexScorer ¶
type RegexScorer struct {
Pattern string
// contains filtered or unexported fields
}
RegexScorer scores 1.0 if the actual output matches the given regex pattern.
func NewRegexScorer ¶
func NewRegexScorer(pattern string) (*RegexScorer, error)
NewRegexScorer creates a RegexScorer with a pre-compiled pattern.
func (*RegexScorer) Name ¶
func (s *RegexScorer) Name() string
type Registry ¶
type Registry struct {
// contains filtered or unexported fields
}
Registry holds named scorer factories and creates scorer instances from config.
func NewRegistry ¶
func NewRegistry() *Registry
NewRegistry creates a scorer registry with built-in scorers pre-registered.
func (*Registry) Descriptors ¶
func (r *Registry) Descriptors() []Descriptor
Descriptors lists every registered scorer, sorted by name.
func (*Registry) GetVersioned ¶
GetVersioned resolves exactly the implementation a plan captured.
func (*Registry) RegisterDescribed ¶
func (r *Registry) RegisterDescribed(d Descriptor, factory Factory)
RegisterDescribed adds a scorer factory with a descriptor.
type SemanticScorer ¶
type SemanticScorer struct {
Client EmbeddingClient
Threshold float64
}
SemanticScorer evaluates semantic similarity between expected and actual outputs using embedding cosine similarity.
func NewSemanticScorer ¶
func NewSemanticScorer(client EmbeddingClient, threshold float64) *SemanticScorer
NewSemanticScorer creates a semantic similarity scorer. Threshold is the minimum cosine similarity to pass (default 0.8).
func (*SemanticScorer) Name ¶
func (s *SemanticScorer) Name() string
type SkillUsageScorer ¶
SkillUsageScorer analyzes agent trace tool calls to verify expected tool usage and detect forbidden tool usage.
func NewSkillUsageScorer ¶
func NewSkillUsageScorer(expected, forbidden []string) *SkillUsageScorer
NewSkillUsageScorer creates a skill usage scorer.
func (*SkillUsageScorer) Name ¶
func (s *SkillUsageScorer) Name() string
type TraitConsistencyScorer ¶
type TraitConsistencyScorer struct {
Client LLMClient
Model string
TraitName string
TraitDesc string
}
TraitConsistencyScorer uses an LLM judge to assess whether the agent's output is consistent with a specified personality trait.
func NewTraitConsistencyScorer ¶
func NewTraitConsistencyScorer(client LLMClient, model, traitName, traitDesc string) *TraitConsistencyScorer
NewTraitConsistencyScorer creates a trait consistency scorer.
func (*TraitConsistencyScorer) Name ¶
func (s *TraitConsistencyScorer) Name() string