Documentation
¶
Overview ¶
Package eval is a behavioral eval harness for jargo bots. It drives a real bot over RTVI, plays scripted conversation turns, and asserts on the semantic events the bot emits. That is a level above unit tests, which check one processor at a time.
A scenario is a YAML file of turns and the events each turn should produce. The same scenario runs from a Go test (the bot hosted in-process, see Run) or from the command line against a running bot. In text mode each user turn is delivered as RTVI send-text, so the audio processors sit idle; in audio mode (Options.UserTTS) it is synthesized and streamed as microphone audio, so the bot's own VAD, turn detection and STT run for real. Transcribing the bot's audio back, to assert on what was actually heard, builds on the same core later.
Expectation fields ¶
event: <name> required: the event to match
within_ms: <int> latency budget, measured from the turn's user input
text_contains: <str> substring check on the event's text, case-sensitive
eval: <str> criterion an LLM judge checks the bot's reply against
(llm_response and tts_response, which carry its text,
and the expression its TTS performed),
or, on function_call, the call itself by name and args
text_excludes: <str> the reverse of text_contains: the text must not hold it
text_matches: <regex> | [<regex>, ...]
regular expressions (RE2, as Go's regexp reads them)
the text must each match, such as a format the reply
must open with; the failure names the first pattern
that did not match
marker: <str> for llm_marker: what the marker meant, one of
complete, short, long, or incomplete for either of
the last two
marker_first: <bool> for llm_marker: the marker came before any text
markers: <int> for llm_marker: how many markers the response holds
text_after: <bool> for llm_marker: text follows the first marker
name: <str> for function_call: the tool the call must be to
args: <mapping> for function_call: an argument subset the call must carry
calls: <list> for function_call: several calls, in any order
absent: true assert the event does NOT arrive
Turn fields ¶
user: <str> what the user says, sent as text or synthesized dtmf: <str> keypad keys the user presses; quote it, # is a comment expect: <list> the events to match, in order send_after: <mapping> when to send this turn's input (see below)
user and dtmf are mutually exclusive, and both are optional: a turn with neither only waits and asserts, which is what a bot-first scenario needs to check an opening greeting. expect is optional too, for a turn that only sends.
Scenario fields ¶
name: <str> required: the scenario's name turns: <list> the turns, played in order context: <list> messages the bot's context starts from
Any value can come from a separate file with !include, resolved against the scenario file's directory, so scenarios can share a block they all need:
turns: !include shared_turns.yaml
Asserting on the bot's reply ¶
Two events carry the bot's own words, and they sit at different points in the pipeline:
llm_response the text the model produced (bot-llm-text) tts_response the text the TTS reports speaking (bot-tts-text)
In an expressive conversation (alpha), expression is the expression the bot's TTS performed, from bot-output, in the tags the LLM writes: <<excited>> where the delivery of its spoken text changes (<<neutral>> back to the baseline), [[laughter]] for a sound, [[pause 600]] for a pause. A tag the TTS can't perform is never reported. A content check on it accumulates the expression performed in the turn.
Asserting on the markers the model emits ¶
A model reading the turn-completion protocol begins each response with a marker saying whether the user's turn was finished. The markers are a diagnostic and never reach a client, so a scenario asserting on one asks the bot to report them:
turns:
- user: "Let me think about it, hmmm"
expect:
- event: llm_marker
marker: incomplete # the bot held the turn open
- user: "I think I'd go to Japan."
expect:
- event: llm_marker
marker: complete # ... and answered this one
The event carries the response as the model produced it, before anything was held back, so a scenario can check the model against the protocol it was given: marker_first that nothing came before the marker, markers how many the response holds, and text_after whether anything follows the first one, which a complete turn should have and an incomplete one should not.
llm_response is available in both modes. tts_response is audio mode only: a text-mode turn asks for no spoken response, so no TTS runs and no segment is produced. Assert on it when what matters is that the reply reached synthesis rather than that the model wrote it, which is the difference between a turn that answered and a turn that was heard.
A turn often answers in more than one response: an interim filler ("Let me check on that.") and then the answer. So a content check on either of them aggregates. It accumulates the text of successive segments and re-checks on each, until the check passes, the judge rejects, or within_ms expires. A missing substring is not a failure on its own, because more text may follow, which is why an assertion on text the bot never produces waits out its whole budget. Set within_ms on one to keep that short.
A judge grades the conversation rather than one reply on its own: it is given each user turn and each segment of the bot's reply, so a terse answer is read against the question it answers. It may also answer "continue", meaning the reply so far is only filler and the criterion should be judged again once more arrives.
A function_call expectation holds the set of calls the turn should make. They are matched by name in any order and the expectation passes only when every one is found. Write a single call with the name/args shorthand:
expect:
- event: function_call
name: get_weather
args: {city: Paris}
and several under calls:, where an entry is a bare tool name or a mapping:
expect:
- event: function_call
calls:
- get_weather
- {name: get_restaurants, args: {city: Paris}}
args is a subset check: every argument listed must be present with that value, and any further argument the model passed is ignored. A bare function_call, with neither name nor calls, matches whatever the bot calls. Asserting on a call's name or its arguments requires the bot to report them, which the harness arranges for itself (see Handler).
absent: true inverts an expectation. It passes only when no event of that type arrives before the within_ms budget expires, and fails as soon as one does, which is how "must not answer twice" is written:
expect:
- event: llm_response
eval: "answers the question"
- event: llm_response
absent: true
within_ms: 5000
It matches on event type alone, so no content or call check may accompany it, and it waits out its whole budget: set within_ms explicitly to keep the quiet window short.
The same two-expectation shape is how "this tool was called, and not again" is written. The first expectation claims the call, and the absent one behind it holds a quiet window open that a repeat trips:
expect:
- event: function_call
name: dispatch_alert
- event: function_call
absent: true
within_ms: 3000
That is the assertion to reach for against a provider that re-requests a call it already made, where running the tool twice is the expensive fault. Because absent matches on event type, the window forbids any further call, not only another dispatch_alert, so put it on a turn whose tool calls are all listed above it.
Scheduling a turn ¶
A turn's input goes out as soon as the previous turn finishes, unless the turn carries send_after. That waits for an event to have been seen, then waits delay_ms longer, which is how an interruption is written:
turns:
- user: "tell me about Paris"
expect:
- event: llm_started
- user: "actually, tell me about Tokyo"
send_after: {event: llm_started, delay_ms: 500}
expect:
- event: bot_interrupted
An event seen earlier in the run anchors the delay at that earlier sighting, so the turn may fire at once. The wait for the event is bounded at 30s, and a turn whose schedule never fires reports the schedule rather than any of its expectations.
event is optional. On its own, delay_ms is a pure time delay measured from the previous turn's send, for pacing turns where there is no event to anchor on.
Diagnosing a run ¶
A Result carries more than its failures: how long the run took, every event the bot emitted whether or not the scenario asserted on it, and a timestamped trace of what the harness itself decided. Together they are what makes a scenario that failed once and passed the next time readable. Options.OnProgress reports the same as it happens, for a caller watching a long run.
Index ¶
- Constants
- func Handler(buildBot Bot) http.Handler
- func Run(t *testing.T, path string, buildBot Bot)
- func RunWith(t *testing.T, path string, buildBot Bot, opts Options)
- func RunWithJudge(t *testing.T, path string, buildBot Bot, judge Judge)
- type Bot
- type EvalJudge
- func (j *EvalJudge) AddAssistantMessage(text string)
- func (j *EvalJudge) AddToolCall(text string)
- func (j *EvalJudge) AddUserMessage(text string)
- func (j *EvalJudge) Classifier() classifier.Classifier
- func (j *EvalJudge) Close(ctx context.Context) error
- func (j *EvalJudge) Evaluate(ctx context.Context, criterion string) JudgeVerdict
- func (j *EvalJudge) EvaluateCall(ctx context.Context, name string, args map[string]any, criterion string) JudgeVerdict
- type EvalJudgeConfig
- type Event
- type Expectation
- type ExpectationResult
- type Failure
- type FunctionCall
- type Judge
- type JudgeVerdict
- type Manifest
- type Options
- type Patterns
- type Progress
- type Result
- type Scenario
- type ScenarioFile
- type SendAfter
- type SuiteEntry
- type SuiteResult
- type Turn
- type TurnResult
Constants ¶
const ( // VerdictYes means the reply satisfies the criterion. VerdictYes = "yes" // VerdictNo means the reply gives a substantive answer that fails it. VerdictNo = "no" // VerdictContinue means the bot is still working toward its answer, and the // criterion should be judged again once more text arrives. VerdictContinue = "continue" )
The verdicts a judge can return.
const ( // TurnPassed means every expectation of the turn was met. TurnPassed = "passed" // TurnFailed means at least one was not. TurnFailed = "failed" )
The statuses a turn resolves to.
const ( // EventUserStartedSpeaking fires when the bot's VAD detects the user's speech // beginning (audio mode only). EventUserStartedSpeaking = "user_started_speaking" // EventUserStoppedSpeaking fires when the user's turn ends (audio mode only). EventUserStoppedSpeaking = "user_stopped_speaking" // EventUserTranscription carries the bot's STT transcription of the user's // speech (audio mode only). EventUserTranscription = "user_transcription" // EventLLMStarted fires when the bot begins generating a response. EventLLMStarted = "llm_started" // EventLLMResponse carries the bot's LLM text, joined across the response. EventLLMResponse = "llm_response" // EventTTSResponse carries the text the bot's TTS reports speaking, one // segment as each arrives (audio mode only: a text-mode turn asks for no // spoken response, so no TTS runs and no segment is ever produced). EventTTSResponse = "tts_response" // EventFunctionCall fires when the bot invokes a tool. EventFunctionCall = "function_call" // EventBotInterrupted fires when the bot's in-flight output is cut off, by a // barge-in or by a turn sent with send_after. It is the event a barge-in // scenario asserts on. EventBotInterrupted = "bot_interrupted" // EventVADUserStartedSpeaking is the raw VAD signal, ungated by turn // detection (audio mode only). Useful as a timing anchor when a turn strategy // gates or defers the turn-level user_stopped_speaking. EventVADUserStartedSpeaking = "vad_user_started_speaking" // EventVADUserStoppedSpeaking is the raw VAD signal for the end of speech // (audio mode only). EventVADUserStoppedSpeaking = "vad_user_stopped_speaking" // EventLLMMarker carries the sideband marker the bot's model emitted in a // response, such as a turn-completion marker. It arrives when the response // ends, and carries the response's raw text with it. Markers never reach a // client by default; a scenario asserting on one asks the bot to report them. EventLLMMarker = "llm_marker" // EventExpression is the expression the bot's TTS performed in an // expressive conversation (alpha), from bot-output, in the tags the LLM // writes: <<excited>> where the delivery of its spoken text changes // (<<neutral>> back to the baseline), [[laughter]] for a sound, // [[pause 600]] for a pause. A tag the TTS can't perform is never reported. EventExpression = "expression" )
Event names a scenario can assert on. These are the friendly names scenarios use; the harness maps the bot's RTVI server messages onto them.
const ( // MarkerComplete means the user's turn was finished and the bot answers. MarkerComplete = "complete" // MarkerShort means the user was cut off and the bot waits. MarkerShort = "short" // MarkerLong means the user asked for time and the bot waits longer. MarkerLong = "long" // MarkerIncomplete matches either of the two above, for a scenario that // cares that the bot held the turn open rather than which reason it read. MarkerIncomplete = "incomplete" )
The meanings a marker expectation can name, which are the emitter's own vocabulary rather than the marker text, since that is configurable.
const ( // StatusTurn heads a turn, carrying its input as the event. StatusTurn = "turn" // StatusMatched means the expectation was met. StatusMatched = "matched" // StatusFailed means the event arrived but did not satisfy the expectation. StatusFailed = "failed" // StatusTimeout means nothing of the expectation's kind arrived at all // before its budget expired. StatusTimeout = "timeout" )
The Progress statuses.
Variables ¶
This section is empty.
Functions ¶
func Handler ¶
Handler serves buildBot over RTVI on a plain WebSocket: it accepts one client per connection, wires the transport into the bot's pipeline, and runs it until the client disconnects. Mount it in a bot's own HTTP server to expose an eval endpoint that `jargo eval run`, or any RTVI WebSocket client, can drive. The in-process Host uses it too.
The endpoint speaks RTVI through the eval serializer, which additionally understands the harness's own control messages. Serving the bot's production RTVI endpoint to the harness instead works, but a scenario asserting on tool arguments will not see them: raising the report level is deliberately something only this serializer allows.
func Run ¶
Run plays the scenario at path against buildBot, hosted in-process over a loopback WebSocket, and reports every unmet expectation through t. Text mode: each user turn is injected as RTVI send-text, so audio processors sit idle. For an LLM judge or audio mode, use RunWith.
Types ¶
type Bot ¶
Bot builds the bot's pipeline task around the harness-provided transport endpoints. The pipeline must include an rtvi.Processor so the harness can drive it (send-text) and observe its events. The builder is transport- agnostic: the harness supplies a WebSocket transport's input and output.
type EvalJudge ¶ added in v0.3.0
type EvalJudge struct {
// contains filtered or unexported fields
}
EvalJudge judges a conversation with a classifier, and asks an LLM for the reasons.
Every question goes to the classifier, which answers with an option and a probability for each of the options it was offered. A reply is judged yes, no or continue, with the conversation before it and the reply itself sent apart, so the classifier knows which part to judge. A tool call is judged yes or no by its name and arguments. Each verdict carries the classifier's confidence, and its reason starts out as the probabilities it gave (P(yes)=0.97). Each question's verdict is cached by its criterion and state.
A classifier gives no reasons, so the judge asks an LLM of its own, the explainer, for them: for every no, and for every yes less sure than ExplainBelow, but never for a continue. The explainer makes its own judgement over the same conversation and never changes a verdict: when it agrees, its reason is used; when it disagrees, the reason says so.
A question that fails is asked once more; a second failure gives a no with the reason "judge call failed".
func NewEvalJudge ¶ added in v0.3.0
func NewEvalJudge(cfg EvalJudgeConfig) (*EvalJudge, error)
NewEvalJudge builds a judge.
func NewLLMJudge
deprecated
func NewLLMJudge(inf llm.Inferencer) *EvalJudge
NewLLMJudge builds a judge that classifies with inf and explains with it too, e.g. eval.NewLLMJudge(chat.NewLLM(chat.LLMConfig{APIKey: key})).
Deprecated: build a classifier/llm classifier over the service and pass it to NewEvalJudge, with the service as the Explainer for the reasons.
func (*EvalJudge) AddAssistantMessage ¶ added in v0.3.0
AddAssistantMessage adds a segment of the bot's current reply to the conversation the judge sees. Consecutive segments are one reply.
func (*EvalJudge) AddToolCall ¶ added in v0.3.0
AddToolCall records a tool call the bot made, on one line, e.g. book({"time": "6pm"}). A reply and a call are judged on the spoken conversation only, so it is kept but not shown to them.
func (*EvalJudge) AddUserMessage ¶ added in v0.3.0
AddUserMessage records a user turn, so a later reply is judged in context (a terse "that's four" answering "what is two plus two?", say).
func (*EvalJudge) Classifier ¶ added in v0.3.0
func (j *EvalJudge) Classifier() classifier.Classifier
Classifier is the classifier that decides the verdicts.
func (*EvalJudge) Close ¶ added in v0.3.0
Close releases what the judge holds open; the session calls it when the run ends.
func (*EvalJudge) Evaluate ¶ added in v0.3.0
func (j *EvalJudge) Evaluate(ctx context.Context, criterion string) JudgeVerdict
Evaluate judges whether the bot's latest reply satisfies criterion, in the conversation so far. It gives a yes, a no, or, when continue is allowed, a continue when the bot is still working toward its answer, cached by criterion and conversation. A final verdict that needs a reason is explained, and a failed question is a no with the failure as its reason.
func (*EvalJudge) EvaluateCall ¶ added in v0.3.0
func (j *EvalJudge) EvaluateCall( ctx context.Context, name string, args map[string]any, criterion string, ) JudgeVerdict
EvaluateCall judges whether a tool call the bot made satisfies criterion, in the conversation so far. It gives a yes or a no, cached by call, criterion and conversation, and explained when it needs a reason.
type EvalJudgeConfig ¶ added in v0.3.0
type EvalJudgeConfig struct {
// Classifier decides the verdicts. The judge sets it up before its first
// question and cleans it up when it is closed. Required.
Classifier classifier.Classifier
// Explainer is the LLM asked for the reason behind a no or an unsure
// verdict; nil reports the probabilities alone.
Explainer llm.Inferencer
// ExplainBelow is the confidence under which a yes is explained too; nil
// uses 0.75. Zero limits the explainer to the no verdicts, and a value above
// 1 sends it every verdict.
ExplainBelow *float64
// AllowContinue is whether a reply may be judged continue: the bot is still
// working toward its answer, so the harness waits for more of it. Nil allows
// it. A suite whose judged replies are all final answers turns it off, and a
// reply is then yes or no.
AllowContinue *bool
// MaxTokens caps the explainer's answer; zero uses 200, enough for a verdict
// and a short reason.
MaxTokens int
}
EvalJudgeConfig configures an EvalJudge.
type Event ¶
type Event struct {
// Kind is one of the Event* name constants.
Kind string
// Text is the reply text on an llm_response, the spoken text on a
// tts_response, or the transcript on a user_transcription. Empty for events
// that carry no text.
Text string
// Function is the tool name on a function_call.
Function string
// Args are the arguments the model produced for a function_call.
Args map[string]any
// Kind, on an llm_marker, is what the marker meant: "complete", "short" or
// "long". Text carries the marker as the model wrote it.
MarkerKind string
// Raw, on an llm_marker, is the response as the model produced it, markers
// included, which is what a check on how well it follows the protocol reads.
Raw string
// Markers, on an llm_marker, is every marker the bot recognizes, so the raw
// text can be read without knowing how the bot was configured.
Markers []string
}
Event is a friendly, translated view of an RTVI server message: the level a scenario asserts on. A run reports every one it saw, so a scenario that failed can be read against what the bot actually did.
type Expectation ¶
type Expectation struct {
// Event is the friendly event name to match (see the Event constants).
Event string `yaml:"event"`
// TextContains, when set, requires the event's text to contain this
// substring, case-sensitively and whatever the spacing. Applies to
// llm_response and tts_response.
TextContains string `yaml:"text_contains,omitempty"`
// TextExcludes is the mirror of TextContains: the event's text must not hold
// this substring. It is for what should never reach the user, a marker the
// model let slip into its reply above all.
//
// On its own it checks the one event it matches. Alongside TextContains or
// Eval, which accumulate a reply across its segments, it is checked on each
// segment, so the failure lands as soon as the text appears rather than at
// the end of the budget.
TextExcludes string `yaml:"text_excludes,omitempty"`
// TextMatches are regular expressions the event's text must each match,
// checked on the same text as TextExcludes, such as a format the reply must
// open with. YAML takes one pattern or a list of them. The patterns are RE2,
// as Go's regexp reads them, so a lookaround or a backreference is rejected
// when the scenario is loaded.
TextMatches Patterns `yaml:"text_matches,omitempty"`
// Eval, when set, is a natural-language criterion an LLM judge checks the
// bot's reply against. Applies to llm_response and tts_response, the two
// events carrying text the bot itself produced.
//
// On a function_call the criterion is about the call instead: each call the
// expectation matches is put to the judge by name and arguments, with the
// conversation so far as context, which is how a scenario checks what Args
// cannot match verbatim. A call is not a partial reply, so the verdict is
// yes or no and the first rejected call fails the expectation.
Eval string `yaml:"eval,omitempty"`
// Name is the single-call shorthand for Calls: the tool name a function_call
// event must match.
Name string `yaml:"name,omitempty"`
// Args is the single-call shorthand for Calls: the argument subset the
// matched call must carry.
Args map[string]any `yaml:"args,omitempty"`
// Calls is the set of tool calls the turn should make, for a function_call
// event. They are matched by name in any order and the expectation passes
// only when all of them are found. Built from `calls:`, or from the
// `name:`/`args:` shorthand, by normalizeCalls.
Calls []FunctionCall `yaml:"calls,omitempty"`
// Marker, on an llm_marker, is what the marker must mean: "complete",
// "short", "long", or "incomplete" for either of the last two. A bare
// llm_marker asserts only that the bot read a marker from its response.
Marker string `yaml:"marker,omitempty"`
// MarkerFirst, on an llm_marker, requires that the first marker in the
// response came before any text, which is what the protocol asks of the
// model.
MarkerFirst *bool `yaml:"marker_first,omitempty"`
// Markers, on an llm_marker, is how many markers the response's text holds.
// The protocol asks for exactly one.
Markers *int `yaml:"markers,omitempty"`
// TextAfter, on an llm_marker, is whether any text follows the first marker.
// A complete turn should have some, an incomplete one none.
TextAfter *bool `yaml:"text_after,omitempty"`
// Absent inverts the expectation: it passes only when no event of this type
// arrives before the WithinMS budget expires, and fails as soon as one does.
// It matches on event type only, so no content check may accompany it.
Absent bool `yaml:"absent,omitempty"`
// WithinMS is the latency budget for the event, measured from the user input;
// zero uses the harness default.
WithinMS int `yaml:"within_ms,omitempty"`
// contains filtered or unexported fields
}
Expectation is one assertion about an event the bot emits.
func (*Expectation) UnmarshalYAML ¶
func (e *Expectation) UnmarshalYAML(node *yaml.Node) error
UnmarshalYAML decodes an expectation, recording whether `calls:` was written out. The distinction matters: a missing `calls:` falls back to the `name:`/`args:` shorthand, whereas an empty one is a mistake.
type ExpectationResult ¶ added in v0.3.0
type ExpectationResult struct {
// Expectation is the 1-based index of the expectation within the turn.
Expectation int
// Event is the event name the expectation waited for.
Event string
// Passed reports whether it was satisfied.
Passed bool
// Matched is what it matched, in short, when it passed: a function call's
// name and arguments, the text of a reply or a transcript. It is empty for
// an event carrying no text, and on a failure, whose reason is in Failures.
Matched string
}
ExpectationResult is what one expectation of a turn resolved to.
type Failure ¶
type Failure struct {
// Turn is the 1-based turn number.
Turn int
// Expectation is the 1-based expectation index within the turn.
Expectation int
// Event is the event name that was expected.
Event string
// Reason explains what went wrong.
Reason string
}
Failure is one unmet expectation in a scenario run.
type FunctionCall ¶
type FunctionCall struct {
// Name is the tool name to match. An empty name matches any call, which is
// what a bare function_call expectation asserts.
Name string `yaml:"name,omitempty"`
// Args, when set, is a subset check on the call's arguments: every listed
// key must be present with the listed value, and any further argument the
// model passed is ignored.
Args map[string]any `yaml:"args,omitempty"`
}
FunctionCall is one expected tool call within a function_call expectation.
func (*FunctionCall) UnmarshalYAML ¶
func (c *FunctionCall) UnmarshalYAML(node *yaml.Node) error
UnmarshalYAML accepts either a bare tool name or a {name, args} mapping, so a calls: list can mix the two.
type Judge ¶
type Judge interface {
// AddUserMessage records a user turn in the conversation.
AddUserMessage(text string)
// AddAssistantMessage appends a segment of the bot's current reply.
AddAssistantMessage(text string)
// Evaluate judges the conversation so far against criterion. A judge that
// cannot answer reports VerdictNo with the reason, rather than failing: an
// unavailable judge is a failed assertion, not a broken run.
Evaluate(ctx context.Context, criterion string) JudgeVerdict
// EvaluateCall judges a tool call the bot made against criterion, by the
// call's name and arguments, with the conversation so far as context. It is
// how a scenario checks what an argument subset cannot match verbatim.
//
// A call is not a partial reply, so there is nothing to wait for and the
// verdict is yes or no; a judge answering VerdictContinue is read as a no.
EvaluateCall(ctx context.Context, name string, args map[string]any, criterion string) JudgeVerdict
}
Judge decides whether the bot's most recent reply satisfies a natural-language criterion, which is what a scenario's `judge:` assertion asks. It is fed the conversation as the scenario plays: the harness records each user turn and each segment of the bot's reply, and Evaluate judges the most recent reply in that context. That is what lets a terse or ambiguous reply be resolved, one that would not make sense on its own.
A judge is per-scenario, because the conversation it holds is. The harness treats it as optional, so a scenario with no `judge:` assertion needs none. A judge that also has a Close(context.Context) error method is closed when the run ends, however it ends.
type JudgeVerdict ¶
type JudgeVerdict struct {
// Verdict is VerdictYes, VerdictNo or VerdictContinue.
Verdict string
// Reason is a one-sentence justification.
Reason string
// RawResponse is the judge's raw answer, for diagnostics.
RawResponse string
// Confidence is how sure the judge is of the verdict, from 0 to 1; nil when
// it did not say.
Confidence *float64
}
JudgeVerdict is the outcome of a single judge call.
func (JudgeVerdict) Passed ¶
func (v JudgeVerdict) Passed() bool
Passed reports whether the verdict is a definite yes.
type Manifest ¶
type Manifest struct {
// Concurrency is how many scenarios run at once; zero uses a default.
Concurrency int `yaml:"concurrency"`
// Suite is the list of bots and their scenarios.
Suite []SuiteEntry `yaml:"suite"`
// contains filtered or unexported fields
}
Manifest lists the bots to test and the scenarios to run against each. Scenario paths are resolved relative to the manifest file, so a manifest is portable.
func LoadManifest ¶
LoadManifest reads and validates a suite manifest.
type Options ¶
type Options struct {
// Judge grades `judge:` assertions; nil is fine when no scenario uses one.
// It holds the conversation it grades against, so give each scenario its own
// rather than reusing one across scenarios.
Judge Judge
// UserTTS selects audio mode. When set, each user turn is synthesized with
// this TTS service and streamed to the bot as microphone audio (so the bot's
// real VAD, turn detection and STT run), instead of the text-mode send-text.
// Any jargo TTS service works, e.g. cartesia.NewTTS(...).
UserTTS *tts.Base
// OnProgress, when set, is called as each turn and expectation resolves, for
// a caller reporting a long run as it happens rather than at the end. It runs
// on the harness's own goroutine, so keep it quick.
OnProgress func(Progress)
}
Options configures a scenario run.
type Patterns ¶ added in v0.3.0
type Patterns []string
Patterns are regular expressions an event's text must each match. YAML takes one pattern or a list of them.
type Progress ¶
type Progress struct {
// Turn is the 1-based turn number.
Turn int
// Expectation is the 1-based expectation index, or 0 for a turn-level
// record: the turn's header, or a schedule that never fired.
Expectation int
// Event is the expectation's event name, or the turn's input for a header.
Event string
// Status is "turn", "matched", "failed" or "timeout".
Status string
// Detail is the failure reason, or what was matched.
Detail string
}
Progress reports how one turn or expectation resolved, as it happens.
type Result ¶
type Result struct {
// Scenario is the scenario's name.
Scenario string
// Failures lists every unmet expectation; empty means the scenario passed.
Failures []Failure
// Turns is what each turn resolved to, in order, and what each of its
// expectations matched. A scenario stopped early lists the turns it reached.
Turns []TurnResult
// Duration is how long the run took.
Duration time.Duration
// Events is every event the bot emitted, in order, whether or not a scenario
// asserted on it. It is what a failure is read against: what the bot actually
// did, rather than only what it was expected to do.
Events []Event
// DebugLog is a timestamped trace of the harness's own decisions: events as
// they arrived, what each expectation waited for, what the judge said. It is
// what makes a run that failed once and passed the next time diagnosable.
DebugLog []string
}
Result is the outcome of running one scenario.
func Host ¶
Host stands up buildBot on an in-process loopback WebSocket and plays scenario against it, returning the result. Run wraps this for the go-test path; callers that want the Result directly (custom reporting, benchmarks) can use it.
func RunURL ¶
RunURL plays scenario against a bot already listening at botURL (a ws:// or wss:// RTVI endpoint). It backs the command-line runner.
type Scenario ¶
type Scenario struct {
// Name identifies the scenario in reports; required.
Name string `yaml:"name"`
// Turns are played in order.
Turns []Turn `yaml:"turns"`
// Context is the conversation the bot's context should start from. When set,
// the harness sends it once the bot is ready, replacing whatever context the
// bot built for itself. Leave it out to test the bot's own opening state.
Context []frames.Message `yaml:"context,omitempty"`
// contains filtered or unexported fields
}
Scenario is a scripted conversation and the events it should produce.
type ScenarioFile ¶ added in v0.3.0
type ScenarioFile struct {
// Name is the file's own `name:`, which every scenario in it is named under.
Name string
// Path is the file it was read from.
Path string
// Scenarios are the scenarios it holds, in the order the file writes them.
Scenarios []*Scenario
}
ScenarioFile is a scenario file: what it is called, where it was read from, and the scenarios it holds.
Most files hold one. A file holds several when they test one behavior through many short conversations, which is cheaper to read and cheaper to run than the same thing spread over a directory of near-identical files.
func LoadFile ¶ added in v0.3.0
func LoadFile(path string) (*ScenarioFile, error)
LoadFile reads and validates a scenario file, returning every scenario it holds.
A file's scenarios sit under `scenarios:`, each with a `name:` of its own, and are named `<file name>/<scenario name>`. Any key a scenario can carry may also sit at the top of the file, where it is the default for every scenario in it; a scenario setting the same key replaces the whole value, so nothing is merged and a `context:` is written out in full rather than added to.
A file whose scenario keys sit at the top level with no `scenarios:` is the older shape, and loads as the one scenario it describes.
type SendAfter ¶
type SendAfter struct {
// Event is the event to schedule from, or empty for a pure delay.
Event string `yaml:"event,omitempty"`
// DelayMS is how long to wait after the event was seen, or, with no event,
// after the previous turn's send.
DelayMS int `yaml:"delay_ms,omitempty"`
}
SendAfter schedules when a turn's input is sent. The harness waits for Event to have been seen, either earlier in the run or arriving now, then waits DelayMS longer before sending. That is how a barge-in is written: `send_after: {event: llm_started, delay_ms: 500}` interrupts 500ms after the bot started responding.
Event is optional. On its own, DelayMS is a pure time delay measured from the previous turn's send, with no event to anchor on.
type SuiteEntry ¶
type SuiteEntry struct {
// Name labels the entry in the results. Empty uses the bot's URL, which is
// what tells apart two entries differing only in the scenarios they play.
Name string `yaml:"name"`
// BotURL is the bot's RTVI WebSocket endpoint (ws:// or wss://).
BotURL string `yaml:"bot_url"`
// Concurrency caps how many of this entry's scenarios may be in flight at
// once, under the manifest's own; zero sets no cap of its own. It is for a
// bot whose provider rate-limits concurrent connections.
Concurrency int `yaml:"concurrency"`
// Scenarios are scenario file paths, resolved relative to the manifest.
Scenarios []string `yaml:"scenarios"`
}
SuiteEntry is one bot and the scenarios to play against it.
type SuiteResult ¶
type SuiteResult struct {
// Entry is the label of the manifest entry the scenario ran under, which is
// the entry's name or, having none, its bot's URL.
Entry string
// BotURL is the bot the scenario ran against.
BotURL string
// Scenario is the scenario file path.
Scenario string
// Result is the scenario result; zero-valued when Err is set.
Result Result
// Err is non-nil when the scenario could not be loaded or run.
Err error
}
SuiteResult is the outcome of running one scenario against one bot.
func RunSuite ¶
func RunSuite(ctx context.Context, m *Manifest, newJudge func() Judge) []SuiteResult
RunSuite runs every scenario in the manifest against its bot and returns one result per scenario, in manifest order.
The manifest's Concurrency is how many scenarios run at once. The suite keeps that many going, taking the next scenario from the first entry in manifest order that still has one, so an entry's scenarios finish together and no slot waits while any entry still has scenarios. An entry whose provider rate-limits sets its own Concurrency, and never has more than that many scenarios in flight; a worker that finds it full takes the next entry's scenario.
newJudge builds the judge for one scenario, and is called once per scenario rather than once for the suite: a judge holds the conversation it grades against, so scenarios running at the same time cannot share one. It may return nil, and may itself be nil, when no scenario uses `judge:`.
func (SuiteResult) Passed ¶
func (r SuiteResult) Passed() bool
Passed reports whether the scenario ran and every expectation was met.
type Turn ¶
type Turn struct {
// User is the text the user "says" this turn (sent as RTVI send-text).
User string `yaml:"user,omitempty"`
// DTMF is a keypad sequence the user presses, one frame per key. Mutually
// exclusive with User. Quote it in YAML: an unquoted # starts a comment.
DTMF string `yaml:"dtmf,omitempty"`
// Expect lists the events to match, in order, after the turn's input.
// Optional: a turn may just send input, with the assertion on a later turn.
Expect []Expectation `yaml:"expect,omitempty"`
// SendAfter, when set, schedules when the turn's input is sent rather than
// sending it as soon as the previous turn finishes.
SendAfter *SendAfter `yaml:"send_after,omitempty"`
// contains filtered or unexported fields
}
Turn is one step of a scenario: input for the bot, expectations about what it does, or both.
A turn drives the bot one of two ways: the harness sends a user utterance, or it sends a sequence of keypad presses. The two are mutually exclusive, and both are optional. A turn with neither only waits and asserts, which is what a bot-first scenario needs: nothing to say, only an opening greeting to check.
func (*Turn) UnmarshalYAML ¶
UnmarshalYAML decodes a turn, reading its keypad sequence from the text as written.
dtmf is not decoded like the other fields because YAML reinterprets an unquoted number before any of this sees it: `dtmf: 012` would arrive as 10 and `dtmf: 0x10` as 16, silently rewriting the keys the scenario typed. Taking the raw scalar keeps every digit, so `dtmf: 123` still works unquoted while a leading zero or a hex-looking token reaches the keypad check with its characters intact, and is rejected there rather than misread here.
type TurnResult ¶ added in v0.3.0
type TurnResult struct {
// Turn is the 1-based turn number.
Turn int
// Status is TurnPassed or TurnFailed.
Status string
// Expectations is what each of the turn's expectations resolved to, in
// order, up to the one that timed out.
Expectations []ExpectationResult
// Duration is how long the turn took.
Duration time.Duration
}
TurnResult is what one turn of a scenario resolved to.
It is what a run is read back from once it is over: the failures alone say what went wrong, and these say what happened, a passing run included. A turn stops at an expectation nothing arrived for, so it lists its expectations up to that one and no further.