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 CompileSchema(schema map[string]any) (*jsonschema.Schema, error)
- func Cosine(a, b []float32) float64
- func Delegations(r *RunResult) []target.ToolCall
- 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 CommandState(c CommandCheck) (Assertion, error)
- func Contains(s string) Assertion
- func DTMFReceived(digits string) Assertion
- func DelegatedTo(agent, contains string, re *regexp.Regexp) 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 Grounded(c GroundedCheck) (Assertion, error)
- func HTTPState(c HTTPCheck) (Assertion, error)
- func Handoff(c HandoffCheck) (Assertion, error)
- 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 SimilarTo(text string, min float64, model string) Assertion
- func Status(code int) Assertion
- func ToolCalled(name string, args map[string]any) Assertion
- func ToolCalledWithSchema(name string, args map[string]any, schema map[string]any) (Assertion, error)
- 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 Claim
- type CommandCheck
- type Comparison
- type EmbedRequest
- type EmbedResponse
- type Embedder
- type EvalRequest
- type EvalVerdict
- type Evaluator
- type GroundContext
- type GroundRequest
- type GroundVerdict
- type GroundedCheck
- type Grounder
- type HTTPCheck
- type HandoffCheck
- type HandoffDetail
- 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.
const DefaultSimilarity = 0.8
DefaultSimilarity is the cosine similarity similar_to needs when the assertion gives no min.
const DefaultStateTimeout = 30 * time.Second
DefaultStateTimeout bounds one state check when none is configured.
const EventHandoff = "handoff"
EventHandoff is recorded when the agent handed the conversation to a person: Detail is a HandoffDetail as JSON.
Variables ¶
This section is empty.
Functions ¶
func CompileSchema ¶ added in v1.4.0
func CompileSchema(schema map[string]any) (*jsonschema.Schema, error)
CompileSchema compiles a JSON Schema given as a document (the YAML mapping of a suite), so a mistake in the schema is a config error and not a test failure.
func Cosine ¶ added in v1.4.0
Cosine is the cosine similarity of two vectors: 1 for the same direction, 0 for unrelated ones. Vectors of different lengths or without magnitude score 0.
func Delegations ¶ added in v1.15.0
Delegations lists the messages the agent sent to remote agents.
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 CommandState ¶ added in v1.7.0
func CommandState(c CommandCheck) (Assertion, error)
CommandState builds the assertion for a CommandCheck.
func DTMFReceived ¶
DTMFReceived passes when the digits the agent sent, concatenated, equal digits.
func DelegatedTo ¶ added in v1.15.0
DelegatedTo passes when the agent sent a message to the remote agent (one of the suite's remote_agents) and, when given, the message contains the text or matches the expression.
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 Grounded ¶ added in v1.8.0
func Grounded(c GroundedCheck) (Assertion, error)
Grounded builds the assertion for a GroundedCheck.
func Handoff ¶ added in v1.7.0
func Handoff(c HandoffCheck) (Assertion, error)
Handoff builds the assertion for a HandoffCheck. It reads the handoff events the run recorded (a target's handoff signal) and the transfer events of phone calls (a SIP REFER counts as a handoff to its target).
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 SimilarTo ¶ added in v1.4.0
SimilarTo passes when some agent turn means the same as text: the cosine similarity of their embeddings is at least min (DefaultSimilarity when 0). model picks the embedding model; "" uses the configured one.
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 ToolCalledWithSchema ¶ added in v1.4.0
func ToolCalledWithSchema(name string, args map[string]any, schema map[string]any) (Assertion, error)
ToolCalledWithSchema passes when the agent called the tool (with args matching, like ToolCalled) and the arguments of every call to it validate against the JSON Schema: a call with arguments the schema rejects fails the assertion, whatever the other calls looked like. A nil schema is ToolCalled.
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 Claim ¶ added in v1.8.0
type Claim struct {
Text string `json:"claim"`
Supported bool `json:"supported"`
// Evidence quotes the context that supports the claim, or says what is
// missing.
Evidence string `json:"evidence,omitempty"`
}
Claim is one factual statement the agent made.
type CommandCheck ¶ added in v1.7.0
type CommandCheck struct {
Run string // sh -c
// Exit is the expected exit code; nil means 0.
Exit *int
// Contains and Regex check the combined output.
Contains *string
Regex *string
Timeout time.Duration
// Dir is the working directory ("" for the current one).
Dir string
// Env is added to the command's environment (KEY=value).
Env []string
}
CommandCheck is a state assertion that runs a shell command after the conversation and checks its exit code and output.
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 EmbedRequest ¶ added in v1.4.0
type EmbedRequest struct {
// Model overrides the configured embedding model (a Genkit reference).
Model string `json:"model,omitempty"`
Texts []string `json:"texts"`
}
EmbedRequest asks for the embedding of each text, with one model.
type EmbedResponse ¶ added in v1.4.0
type EmbedResponse struct {
Vectors [][]float32 `json:"vectors"`
Model string `json:"model,omitempty"`
}
EmbedResponse is one vector per text, in order, and the model that made them.
type Embedder ¶ added in v1.4.0
type Embedder interface {
Embed(ctx context.Context, req EmbedRequest) (EmbedResponse, error)
}
Embedder turns texts into vectors for the semantic assertions. The llm module implements it; the runner sets it on every RunResult.
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 GroundContext ¶ added in v1.8.0
type GroundContext struct {
// JSONPath selects passages from every raw response (rest / websocket /
// realtime events): strings, or lists and objects rendered as JSON.
JSONPath string
// Tool names a tool whose results are the context (model / realtime /
// pipecat targets, where tamesu sees the results).
Tool string
// Text are passages given in the suite.
Text []string
}
GroundContext says where the retrieval context of a run is.
type GroundRequest ¶ added in v1.8.0
type GroundRequest struct {
// Context are the passages the agent could legitimately draw on.
Context []string `json:"context"`
// Model overrides the configured judge model (a Genkit reference).
Model string `json:"model,omitempty"`
// Language is the conversation's language (BCP 47), when the persona has one.
Language string `json:"language,omitempty"`
Transcript []Turn `json:"transcript"`
}
GroundRequest asks whether the agent's claims are supported by the context it was given (retrieved passages, tool results).
type GroundVerdict ¶ added in v1.8.0
type GroundVerdict struct {
Claims []Claim `json:"claims"`
Reason string `json:"reason"`
// TraceID and PromptVersion identify the model call.
TraceID string `json:"trace_id,omitempty"`
PromptVersion string `json:"prompt_version,omitempty"`
}
GroundVerdict is the grounding check's structured answer.
func (GroundVerdict) Supported ¶ added in v1.8.0
func (v GroundVerdict) Supported() (supported, total int)
Supported counts the supported claims and the total.
type GroundedCheck ¶ added in v1.8.0
type GroundedCheck struct {
Context GroundContext
// Min is the fraction of claims that must be supported; 0 means all.
Min float64
Model string
}
GroundedCheck is the grounding assertion: every factual claim the agent makes must be supported by the context, or at least Min of them.
type Grounder ¶ added in v1.8.0
type Grounder interface {
Ground(ctx context.Context, req GroundRequest) (GroundVerdict, error)
}
Grounder checks the agent's claims against context.
type HTTPCheck ¶ added in v1.7.0
type HTTPCheck struct {
URL string
Method string // GET when empty
Headers map[string]string
Body any // a string is sent as is; anything else as JSON
// Status is the expected status code; nil means any code under 400.
Status *int
// JSONPath, when set, must exist in the JSON body and, with Equals not
// nil, equal it.
JSONPath string
Equals any
// Contains and Regex check the body text.
Contains *string
Regex *string
Timeout time.Duration
// Client overrides the HTTP client (tests).
Client *http.Client
}
HTTPCheck is a state assertion against your backend: after the conversation, a request is made and its status and body are checked. It closes the loop between what the agent said and what it did.
type HandoffCheck ¶ added in v1.7.0
type HandoffCheck struct {
// Expected is whether a handoff should have happened (nil means yes).
Expected *bool
// WithinTurns, when positive, is the latest agent turn the handoff may
// happen on.
WithinTurns int
// To is a regular expression the destination must match.
To *string
// SummaryContains are texts the summary must contain.
SummaryContains []string
// Summary is a judge rubric for the summary (needs a judge).
Summary string
}
HandoffCheck is a handoff and escalation assertion: whether the agent handed the conversation to a person, when, to whom and with what summary.
type HandoffDetail ¶ added in v1.7.0
type HandoffDetail struct {
// Turn is the agent turn (1-based) that handed off.
Turn int `json:"turn"`
// To is the destination (a department, a queue, a SIP target) when the
// signal names one.
To string `json:"to,omitempty"`
// Summary is what the agent passed on to the person, when the signal
// names one.
Summary string `json:"summary,omitempty"`
// Via says what signalled it: "tool transfer_to_human", "json_path
// $.handoff", "regex", "transfer".
Via string `json:"via,omitempty"`
}
HandoffDetail is what a handoff event carries.
func Handoffs ¶ added in v1.7.0
func Handoffs(r *RunResult) []HandoffDetail
Handoffs lists the run's handoffs: handoff events, then phone transfers.
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"`
// Language is the conversation's language (BCP 47), when the persona has one.
Language string `json:"language,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
// Language is the persona's language, so judges know the conversation
// is not in English on purpose.
Language string
// Judger, Evaluator and Embedder are the AI hooks the runner sets; nil
// means no model is available and judge, evaluator or similar_to
// assertions fail.
Judger Judger
Grounder Grounder
Evaluator Evaluator
Embedder Embedder
}
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.