evals

package
v0.9.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package evals provides an evaluation framework for testing agent quality.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AccuracyEval

type AccuracyEval struct {
	EvalName string
	Judge    model.Provider
	Rubric   string
}

AccuracyEval uses an LLM judge to score the accuracy of agent output against expected output.

func (*AccuracyEval) Name

func (e *AccuracyEval) Name() string

func (*AccuracyEval) Run

func (e *AccuracyEval) Run(ctx context.Context, actual, expected string) EvalResult

type CaseSpec added in v0.7.0

type CaseSpec struct {
	// Eval selects the evaluator: "exact_match", "contains", or "accuracy".
	Eval string `yaml:"eval"`
	// Name is an optional label; it defaults to the Eval type when empty.
	Name     string `yaml:"name"`
	Input    string `yaml:"input"`
	Expected string `yaml:"expected"`
}

CaseSpec is the YAML representation of a single eval case.

type ContainsEval

type ContainsEval struct {
	EvalName string
}

ContainsEval checks if the input contains the expected substring.

func (*ContainsEval) Name

func (e *ContainsEval) Name() string

func (*ContainsEval) Run

func (e *ContainsEval) Run(_ context.Context, input, expected string) EvalResult

type Eval

type Eval interface {
	// Name returns a human-readable name for this eval.
	Name() string
	// Run executes the evaluation and returns a result.
	Run(ctx context.Context, input string, expected string) EvalResult
}

Eval defines a single evaluation case.

type EvalCase

type EvalCase struct {
	Eval     Eval
	Input    string
	Expected string
}

EvalCase pairs an Eval with test data.

type EvalResult

type EvalResult struct {
	Name       string        `json:"name"`
	Score      float64       `json:"score"`
	Passed     bool          `json:"passed"`
	Details    string        `json:"details"`
	Latency    time.Duration `json:"latency"`
	TokensUsed int           `json:"tokens_used,omitempty"`
	Error      string        `json:"error,omitempty"`
}

EvalResult captures the outcome of a single evaluation.

type ExactMatchEval

type ExactMatchEval struct {
	EvalName string
}

ExactMatchEval checks if the agent output exactly matches the expected output.

func (*ExactMatchEval) Name

func (e *ExactMatchEval) Name() string

func (*ExactMatchEval) Run

func (e *ExactMatchEval) Run(_ context.Context, input, expected string) EvalResult

type PerformanceBaseline

type PerformanceBaseline struct {
	MaxLatency      time.Duration
	MaxTotalTokens  int
	MaxPromptTokens int
}

PerformanceBaseline defines expected performance thresholds.

type PerformanceEval

type PerformanceEval struct {
	EvalName string
	RunFunc  func(ctx context.Context) (latency time.Duration, promptTokens int, completionTokens int, err error)
	Baseline *PerformanceBaseline
}

PerformanceEval measures execution latency and token usage, comparing against optional baselines.

func (*PerformanceEval) Name

func (e *PerformanceEval) Name() string

func (*PerformanceEval) Run

func (e *PerformanceEval) Run(ctx context.Context, _, _ string) EvalResult

type ReliabilityEval

type ReliabilityEval struct {
	EvalName      string
	ActualCalls   []ToolCallExpectation
	ExpectedCalls []ToolCallExpectation
}

ReliabilityEval verifies the agent made correct tool calls in the correct order.

func (*ReliabilityEval) Name

func (e *ReliabilityEval) Name() string

func (*ReliabilityEval) Run

type Suite

type Suite struct {
	Name  string
	Evals []EvalCase
}

Suite is a collection of evaluations that run together.

func LoadSuite added in v0.7.0

func LoadSuite(data []byte) (*Suite, error)

LoadSuite parses YAML suite data into a runnable Suite. It returns an error for malformed YAML, a missing suite name, an empty case list, or a case that names an unknown or unsupported evaluator.

func (*Suite) Run

func (s *Suite) Run(ctx context.Context) SuiteResult

Run executes all evaluations in the suite and aggregates results.

type SuiteResult

type SuiteResult struct {
	SuiteName    string        `json:"suite_name"`
	Results      []EvalResult  `json:"results"`
	TotalEvals   int           `json:"total_evals"`
	Passed       int           `json:"passed"`
	Failed       int           `json:"failed"`
	Errors       int           `json:"errors"`
	AvgScore     float64       `json:"avg_score"`
	TotalLatency time.Duration `json:"total_latency"`
}

SuiteResult aggregates results from running a suite.

func (*SuiteResult) Summary

func (sr *SuiteResult) Summary() string

Summary returns a human-readable summary of the suite results.

type SuiteSpec added in v0.7.0

type SuiteSpec struct {
	Name  string     `yaml:"name"`
	Cases []CaseSpec `yaml:"cases"`
}

SuiteSpec is the YAML representation of an eval suite. It maps a declarative file to a runnable Suite so evals can be defined without writing Go.

Example:

name: greeting-suite
cases:
  - eval: exact_match
    name: exact-greeting
    input: "hello"
    expected: "hello"
  - eval: contains
    input: "the quick brown fox"
    expected: "quick"

type ToolCallExpectation

type ToolCallExpectation struct {
	Name string
	Args map[string]any
}

ToolCallExpectation defines an expected tool call.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL