Documentation
¶
Overview ¶
Package assert defines the Assertion contract and the deterministic assertions tamesu ships (contains, regex, json_path, status, tool_called, metric, turns). LLM judges and Genkit evaluators live in the llm module.
Index ¶
- Constants
- func Register(name string, factory func() Assertion)
- func Registered() []string
- func Similarity(a, b string) float64
- type Assertion
- func CallEndedBy(who []string) Assertion
- func Captured(name string, equals, matches *string) (Assertion, error)
- func Contains(s string) Assertion
- func DTMFReceived(digits string) Assertion
- func Evaluate(evaluator string, min float64) Assertion
- func Func(name string, fn func(ctx context.Context, r *RunResult) Result) Assertion
- func Golden(reference []string, mode string, min float64, source string) Assertion
- func JSONPath(path string, equals any) (Assertion, error)
- func Judge(rubric string, opts ...JudgeOption) Assertion
- func Lookup(name string) (Assertion, bool)
- func MustRegex(pattern string) Assertion
- func NotContains(s string) Assertion
- func NotRegex(pattern string) (Assertion, error)
- func OnTurn(n int, last bool, inner Assertion) Assertion
- func Regex(pattern string) (Assertion, error)
- func SLO(metric string, max float64) Assertion
- func Status(code int) Assertion
- func ToolCalled(name string, args map[string]any) Assertion
- func ToolNotCalled(name string, args map[string]any) Assertion
- func ToolSequence(names []string, exact bool) Assertion
- func TransferredTo(pattern string) (Assertion, error)
- func Turns(c Comparison) Assertion
- type Comparison
- type EvalRequest
- type EvalVerdict
- type Evaluator
- type JudgeOption
- type JudgeRequest
- type JudgeVerdict
- type Judger
- type MetricBuilder
- type Result
- type RunResult
- type Turn
Constants ¶
const ( EventDTMFReceived = "dtmf_received" // Detail: the digits the agent sent EventCallEnded = "call_ended" // Detail: agent, caller, timeout, error, no_answer or busy EventTransfer = "transfer" // Detail: the SIP REFER target )
Event kinds the voice targets emit on the session timeline. The sip assertions read them.
const ( GoldenExact = "exact" GoldenSimilar = "similar" GoldenJudge = "judge" )
Golden modes.
const DefaultGoldenMin = 0.8
DefaultGoldenMin is the word overlap a similar golden turn needs.
Variables ¶
This section is empty.
Functions ¶
func Similarity ¶
Similarity is the Jaccard overlap of the two texts' word sets, 0 to 1.
Types ¶
type Assertion ¶
Assertion is one check over a finished run.
func CallEndedBy ¶
CallEndedBy passes when the call ended for one of the listed reasons (agent, caller, timeout, error, no_answer, busy).
func Captured ¶
Captured passes when the run captured name and, when given, the value equals or matches the expectation.
func DTMFReceived ¶
DTMFReceived passes when the digits the agent sent, concatenated, equal digits.
func Evaluate ¶
Evaluate runs a registered Genkit evaluator on the run (input: the first user turn, output: the agent transcript) and passes when its score is at least min (or it reports PASS when it has no numeric score).
func Golden ¶
Golden compares the agent's turns, in order, with reference turns: exact (normalised text), similar (word overlap of at least min) or judge (the judge decides whether each turn means the same as its reference). Fewer agent turns than references fail; extra agent turns are ignored.
func JSONPath ¶
JSONPath passes when path exists in every agent response and, when equals is not nil, equals it (numbers and strings compared after JSON normalisation).
func Judge ¶
func Judge(rubric string, opts ...JudgeOption) Assertion
Judge grades the run against a rubric with the run's Judger (an LLM).
func NotContains ¶
NotContains passes when no agent turn contains s.
func OnTurn ¶
OnTurn evaluates inner on one agent turn only: the 1-based turn n, or the last turn when last is set.
func SLO ¶
SLO passes when the metric is at most max, or was not measured in this run (an audio metric on a text test), so one SLO applies to every test.
func ToolCalled ¶
ToolCalled passes when the agent called the tool, with args matching every key of args (a subset of the call's arguments) when args is not empty.
func ToolNotCalled ¶
ToolNotCalled passes when the agent never called the tool (with those args).
func ToolSequence ¶
ToolSequence passes when the tool calls happened in the given order: as a subsequence of the run's calls, or exactly that list with exact.
func TransferredTo ¶
TransferredTo passes when the agent transferred the call (a SIP REFER) to a target matching pattern.
func Turns ¶
func Turns(c Comparison) Assertion
Turns compares the number of agent turns: assert.Turns(assert.Comparison{Op: "lte", Value: 6}).
type Comparison ¶
Comparison is one of lt, lte, gt, gte, eq against a number.
func (Comparison) Symbol ¶
func (c Comparison) Symbol() string
Symbol is the comparison operator for people.
type EvalRequest ¶
type EvalRequest struct {
Evaluator string `json:"evaluator"`
Input any `json:"input"`
Output any `json:"output,omitempty"`
Context []any `json:"context,omitempty"`
Reference any `json:"reference,omitempty"`
}
EvalRequest runs a registered Genkit evaluator on one example.
type EvalVerdict ¶
type EvalVerdict struct {
Pass bool `json:"pass"`
Score float64 `json:"score"`
Reason string `json:"reason,omitempty"`
}
EvalVerdict is an evaluator's score.
type Evaluator ¶
type Evaluator interface {
Evaluate(ctx context.Context, req EvalRequest) (EvalVerdict, error)
}
Evaluator runs Genkit evaluators by name.
type JudgeOption ¶
type JudgeOption func(*JudgeRequest)
JudgeOption configures a judge assertion.
func WithMin ¶
func WithMin(min float64) JudgeOption
WithMin sets the minimum score to pass on the 1-5 scale (default 4).
func WithModel ¶
func WithModel(model string) JudgeOption
WithModel sets the judge model (a Genkit reference).
func WithScale ¶
func WithScale(scale string) JudgeOption
WithScale sets the judge scale: "binary" or "1-5".
type JudgeRequest ¶
type JudgeRequest struct {
Rubric string `json:"rubric"`
// Scale is "binary" (pass or fail) or "1-5" (a score compared with Min).
Scale string `json:"scale,omitempty"`
Min float64 `json:"min,omitempty"`
// Model overrides the configured judge model (a Genkit reference).
Model string `json:"model,omitempty"`
Transcript []Turn `json:"transcript,omitempty"`
ToolCalls []target.ToolCall `json:"tool_calls,omitempty"`
Metrics map[string]float64 `json:"metrics,omitempty"`
}
JudgeRequest is what an LLM judge receives: the rubric and the whole run.
type JudgeVerdict ¶
type JudgeVerdict struct {
Pass bool `json:"pass"`
Score float64 `json:"score"`
Reason string `json:"reason"`
Evidence []string `json:"evidence,omitempty"`
// TraceID and PromptVersion make judge drift traceable.
TraceID string `json:"trace_id,omitempty"`
PromptVersion string `json:"prompt_version,omitempty"`
}
JudgeVerdict is the judge's structured answer.
type Judger ¶
type Judger interface {
Judge(ctx context.Context, req JudgeRequest) (JudgeVerdict, error)
}
Judger grades a run against a rubric. The llm module implements it; the runner sets it on every RunResult.
type MetricBuilder ¶
type MetricBuilder struct {
// contains filtered or unexported fields
}
MetricBuilder builds a metric assertion: assert.Metric("time_to_first_audio_ms").Lt(1500).
func Metric ¶
func Metric(name string) MetricBuilder
Metric starts a metric assertion on the named built-in metric.
func (MetricBuilder) Compare ¶
func (m MetricBuilder) Compare(c Comparison) Assertion
Compare finishes the metric assertion with an explicit comparison.
func (MetricBuilder) Eq ¶
func (m MetricBuilder) Eq(v float64) Assertion
func (MetricBuilder) Gt ¶
func (m MetricBuilder) Gt(v float64) Assertion
func (MetricBuilder) Gte ¶
func (m MetricBuilder) Gte(v float64) Assertion
func (MetricBuilder) Lt ¶
func (m MetricBuilder) Lt(v float64) Assertion
Lt, Lte, Gt, Gte and Eq finish the metric assertion.
func (MetricBuilder) Lte ¶
func (m MetricBuilder) Lte(v float64) Assertion
type Result ¶
type Result struct {
Name string `json:"name"`
Pass bool `json:"pass"`
// Score is the judge's score when the assertion has one (0 to 1 or 1 to
// 5); zero otherwise.
Score float64 `json:"score,omitempty"`
// Reason explains the outcome in one or two sentences.
Reason string `json:"reason"`
// Evidence quotes the turns or values the outcome rests on.
Evidence []string `json:"evidence,omitempty"`
// TraceID is the Genkit trace of a judge or evaluator call.
TraceID string `json:"trace_id,omitempty"`
}
Result is the outcome of one assertion.
type RunResult ¶
type RunResult struct {
TestName string
Target string
Transcript []Turn
ToolCalls []target.ToolCall
Metrics map[string]float64
Artifacts target.Artifacts
// Status lists the HTTP status of every agent turn (rest).
Status []int
// Responses holds the raw payload of every agent turn (the JSON body for
// rest), in order, for json_path.
Responses []any
// Captures are the values the run captured from the agent's turns.
Captures map[string]string
Events []target.Event
// Judger and Evaluator are the AI hooks the runner sets; nil means no
// model is available and judge or evaluator assertions fail.
Judger Judger
Evaluator Evaluator
}
RunResult is everything one run produced, the input of every assertion.
func (*RunResult) AgentText ¶
AgentText joins the agent's turns, newline separated: what contains, regex and the judges read.
func (*RunResult) AgentTurns ¶
AgentTurns counts the agent's turns.
func (*RunResult) Turn ¶
Turn returns a view of the run restricted to one agent turn (1-based; 0 or a number past the last turn means the last turn): its transcript holds the user turn that caused it and the agent turn, and Status and Responses hold that turn's entries. The metrics, tool calls and hooks are shared.