flowjudge

package module
v0.0.0-...-5422d13 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 8 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package flowjudge validates multi-agent voice flows by simulating a live room and judging turns with an LLM — not hardcoded word lists.

Typical use (ADSL desks):

h := flowjudge.New(llm,
    flowjudge.WithAgentRunner(adsl.FlowJudgeRunner(rt)),
    flowjudge.WithJudge(flowjudge.JudgeConfig{Rubric: flowjudge.VoiceRoomRubric}),
)
rep, err := h.Simulate(ctx, flowjudge.Room{
    Human: flowjudge.ScriptedHuman{"Hey Julia, let's speak English.", "Bring everyone."},
    Pick:  flowjudge.FixedPicker("agent/Julia", "agent/sarah"),
})

Harness.Run still supports scripted steps. Quality defaults to the AI judge when WithJudge is set; optional mechanical [Check]s are only for infra (empty reply, latency), not product language rules.

Index

Constants

View Source
const VoiceRoomRubric = `` /* 953-byte string literal not displayed */

VoiceRoomRubric is the default LLM-as-judge brief for multi-agent voice desks.

Variables

This section is empty.

Functions

func Spoken

func Spoken(text string) string

Spoken strips an optional leading voice tag for content checks / judging.

Types

type AIHuman

type AIHuman struct {
	Provider niro.Provider
	Model    string
	Persona  string
	Options  niro.Options
	MaxLines int
}

AIHuman uses an LLM to improvise the next user line in the room.

func (AIHuman) Next

func (h AIHuman) Next(ctx context.Context, st RoomState) (string, bool, error)

Next implements Human.

type AgentRunner

type AgentRunner interface {
	RunTurn(ctx context.Context, agentID string, input map[string]any, history []niro.Message) (AgentTurn, error)
}

AgentRunner runs one agent turn (e.g. ADSL Runtime.RunAgent + Collect).

type AgentRunnerFunc

type AgentRunnerFunc func(ctx context.Context, agentID string, input map[string]any, history []niro.Message) (AgentTurn, error)

AgentRunnerFunc adapts a function to AgentRunner.

func (AgentRunnerFunc) RunTurn

func (f AgentRunnerFunc) RunTurn(ctx context.Context, agentID string, input map[string]any, history []niro.Message) (AgentTurn, error)

RunTurn implements AgentRunner.

type AgentTurn

type AgentTurn struct {
	Text    string
	Latency time.Duration
}

AgentTurn is the result of an AgentRunner call.

type Check

type Check func(StepResult) []Failure

Check judges one step result. Return zero or more failures.

func DeskDefaults

func DeskDefaults() []Check

DeskDefaults is an alias of InfraDefaults kept for older call sites.

func InfraDefaults

func InfraDefaults() []Check

InfraDefaults is the only automatic mechanical gate: non-empty reply. Product quality belongs to the AI judge (WithJudge / Harness.Simulate).

func LatencyUnder

func LatencyUnder(d time.Duration) Check

LatencyUnder fails when step latency exceeds d.

func MaxWords

func MaxWords(n int) Check

MaxWords fails when spoken word count exceeds n (optional infra gate).

func NotEmpty

func NotEmpty() Check

NotEmpty fails when spoken text is empty.

type Failure

type Failure struct {
	Check  string
	Detail string
}

Failure is one check miss on a step.

type Flow

type Flow struct {
	Name  string
	Steps []Step
}

Flow is a named multi-step validation script.

type Harness

type Harness struct {
	// contains filtered or unexported fields
}

Harness runs flows against a provider and/or agent runner.

func New

func New(provider niro.Provider, opts ...Option) *Harness

New builds a harness.

func (*Harness) JudgeCall

func (h *Harness) JudgeCall(ctx context.Context, transcript []string) (Verdict, error)

JudgeCall scores the whole simulated conversation.

func (*Harness) JudgeTurn

func (h *Harness) JudgeTurn(ctx context.Context, mode string, speaker string, utterance string, transcript []string) (Verdict, error)

JudgeTurn asks the judge model to score one agent utterance in room context.

func (*Harness) Run

func (h *Harness) Run(ctx context.Context, flow Flow) (Report, error)

Run executes all steps sequentially, sharing a text history transcript.

func (*Harness) Simulate

func (h *Harness) Simulate(ctx context.Context, room Room) (RoomReport, error)

Simulate runs a room conversation like a live voice call and AI-judges it.

type Human

type Human interface {
	Next(ctx context.Context, st RoomState) (text string, done bool, err error)
}

Human produces the next human utterance (scripted or AI).

type JudgeConfig

type JudgeConfig struct {
	Provider niro.Provider // defaults to harness provider
	Model    string
	Rubric   string // defaults to VoiceRoomRubric
	Options  niro.Options
}

JudgeConfig configures the AI self-validator.

type Option

type Option func(*Harness)

Option configures a Harness.

func WithAgentRunner

func WithAgentRunner(r AgentRunner) Option

WithAgentRunner enables Step.Agent / Harness.Simulate execution.

func WithJudge

func WithJudge(cfg JudgeConfig) Option

WithJudge enables LLM-as-judge self-validation (preferred quality path).

func WithModel

func WithModel(model string) Option

WithModel sets the default model id for raw provider turns / judge fallback.

func WithOptions

func WithOptions(opts niro.Options) Option

WithOptions sets default generation options for raw provider turns.

type Report

type Report struct {
	Name  string
	Steps []StepReport
}

Report is the full flow outcome.

func (Report) FailureCount

func (r Report) FailureCount() int

FailureCount totals check failures.

func (Report) Passed

func (r Report) Passed() bool

Passed is true when every step passed.

func (Report) String

func (r Report) String() string

String summarizes the report for logs/CI.

type Room

type Room struct {
	Name      string
	HumanName string // default "Alex"
	Human     Human
	// Pick chooses which agent speaks next. Required.
	Pick SpeakerPicker
	// Present is passed into each agent Input["present"] (optional roster).
	Present []string
	// MaxHumanTurns stops after this many human utterances (0 = until Human done).
	MaxHumanTurns int
	// PeerBeats inserts this many peer-continue turns after each human+reply pair.
	PeerBeats int
	// JudgeEachTurn runs the AI judge after every agent utterance (default: when WithJudge).
	JudgeEachTurn *bool
	// JudgeCall runs a final whole-transcript AI judge (default: when WithJudge).
	JudgeCall  *bool
	MaxLatency time.Duration // optional infra gate only
}

Room simulates being in a live multi-agent voice call.

type RoomReport

type RoomReport struct {
	Name       string
	Transcript []string
	Turns      []StepReport
	Call       *Verdict
}

RoomReport holds per-turn and optional whole-call AI verdicts.

func (RoomReport) Passed

func (r RoomReport) Passed() bool

Passed is true when every turn passed and the optional call judge passed.

func (RoomReport) String

func (r RoomReport) String() string

String summarizes the room simulation.

type RoomState

type RoomState struct {
	Transcript  []string
	LastSpeaker string
	HumanTurns  int
	AgentTurns  int
	ExpectPeer  bool
	HumanName   string
}

RoomState is the live simulation snapshot.

type ScriptedHuman

type ScriptedHuman []string

ScriptedHuman plays fixed lines in order (like a rehearsal script).

func (ScriptedHuman) Next

func (h ScriptedHuman) Next(ctx context.Context, st RoomState) (string, bool, error)

Next implements Human.

type SpeakerPicker

type SpeakerPicker interface {
	Pick(ctx context.Context, st RoomState) (agentID string, peerContinue bool, err error)
}

SpeakerPicker chooses the next agent id and whether this is a peer-continue beat.

func FixedPicker

func FixedPicker(agentIDs ...string) SpeakerPicker

FixedPicker cycles agent ids; peer beats use ExpectPeer from room state.

type SpeakerPickerFunc

type SpeakerPickerFunc func(ctx context.Context, st RoomState) (agentID string, peerContinue bool, err error)

SpeakerPickerFunc adapts a function to SpeakerPicker.

func (SpeakerPickerFunc) Pick

Pick implements SpeakerPicker.

type Step

type Step struct {
	Name string

	// Agent path (ADSL / custom runner).
	Agent string
	Input map[string]any

	// Raw LLM path.
	System string
	User   string

	// Mode for the AI judge: "human" (default) or "peer".
	Mode string

	// Label appended into shared history as "Label: text" after the step.
	// Defaults to Agent name, else Name.
	As string

	// Append this line to history before the turn (e.g. human utterance).
	HistoryAppend string

	Checks     []Check
	SkipJudge  bool // skip AI judge even when WithJudge is set
	MaxLatency time.Duration
	Options    niro.Options // optional per-step override
}

Step is one turn in a flow.

Prefer Agent+Input with WithAgentRunner for ARDL desks. Otherwise set System/User for a raw provider turn (prompt-level harness).

Quality is judged by the LLM when WithJudge is set — do not encode product language rules as Checks. Checks are for infra only (empty, latency).

type StepReport

type StepReport struct {
	Name     string
	Agent    string
	Text     string
	Latency  time.Duration
	Failures []Failure
	Judge    *Verdict
}

StepReport is the outcome of one step.

func (StepReport) Passed

func (s StepReport) Passed() bool

Passed reports whether the step had no failures.

type StepResult

type StepResult struct {
	Name         string
	Agent        string
	Text         string
	PreviousText string
	Latency      time.Duration
	History      []string
}

StepResult is what mechanical checks see.

type Verdict

type Verdict struct {
	Pass    bool     `json:"pass"`
	Score   int      `json:"score"`
	Issues  []string `json:"issues"`
	Summary string   `json:"summary"`
	Raw     string   `json:"-"`
	Latency time.Duration
}

Verdict is the LLM judge outcome for one turn or a whole call.

Jump to

Keyboard shortcuts

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